Karim shoair commited on
Commit ·
1543315
1
Parent(s): 20dd99a
fix: Fixes for the type checking in the main `init` file
Browse files- scrapling/__init__.py +28 -18
- scrapling/core/_types.py +0 -2
- scrapling/engines/_browsers/__init__.py +0 -2
scrapling/__init__.py
CHANGED
|
@@ -2,27 +2,37 @@ __author__ = "Karim Shoair (karim.shoair@pm.me)"
|
|
| 2 |
__version__ = "0.3.6"
|
| 3 |
__copyright__ = "Copyright (c) 2024 Karim Shoair"
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
module = __import__(module_path, fromlist=[class_name])
|
| 23 |
return getattr(module, class_name)
|
| 24 |
else:
|
| 25 |
-
raise AttributeError(f"module
|
| 26 |
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
| 2 |
__version__ = "0.3.6"
|
| 3 |
__copyright__ = "Copyright (c) 2024 Karim Shoair"
|
| 4 |
|
| 5 |
+
from typing import Any, TYPE_CHECKING
|
| 6 |
|
| 7 |
+
if TYPE_CHECKING:
|
| 8 |
+
from scrapling.parser import Selector, Selectors
|
| 9 |
+
from scrapling.core.custom_types import AttributesHandler, TextHandler
|
| 10 |
+
from scrapling.fetchers import Fetcher, AsyncFetcher, StealthyFetcher, DynamicFetcher
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Lazy import mapping
|
| 14 |
+
_LAZY_IMPORTS = {
|
| 15 |
+
"Fetcher": ("scrapling.fetchers", "Fetcher"),
|
| 16 |
+
"Selector": ("scrapling.parser", "Selector"),
|
| 17 |
+
"Selectors": ("scrapling.parser", "Selectors"),
|
| 18 |
+
"AttributesHandler": ("scrapling.core.custom_types", "AttributesHandler"),
|
| 19 |
+
"TextHandler": ("scrapling.core.custom_types", "TextHandler"),
|
| 20 |
+
"AsyncFetcher": ("scrapling.fetchers", "AsyncFetcher"),
|
| 21 |
+
"StealthyFetcher": ("scrapling.fetchers", "StealthyFetcher"),
|
| 22 |
+
"DynamicFetcher": ("scrapling.fetchers", "DynamicFetcher"),
|
| 23 |
+
}
|
| 24 |
+
__all__ = ["Selector", "Fetcher", "AsyncFetcher", "StealthyFetcher", "DynamicFetcher"]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def __getattr__(name: str) -> Any:
|
| 28 |
+
if name in _LAZY_IMPORTS:
|
| 29 |
+
module_path, class_name = _LAZY_IMPORTS[name]
|
| 30 |
module = __import__(module_path, fromlist=[class_name])
|
| 31 |
return getattr(module, class_name)
|
| 32 |
else:
|
| 33 |
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
| 34 |
|
| 35 |
|
| 36 |
+
def __dir__() -> list[str]:
|
| 37 |
+
"""Support for dir() and autocomplete."""
|
| 38 |
+
return sorted(__all__ + ["fetchers", "parser", "cli", "core", "__author__", "__version__", "__copyright__"])
|
scrapling/core/_types.py
CHANGED
|
@@ -39,6 +39,4 @@ except ImportError: # pragma: no cover
|
|
| 39 |
try:
|
| 40 |
from typing_extensions import Self # Backport
|
| 41 |
except ImportError:
|
| 42 |
-
from typing import TypeVar
|
| 43 |
-
|
| 44 |
Self = object
|
|
|
|
| 39 |
try:
|
| 40 |
from typing_extensions import Self # Backport
|
| 41 |
except ImportError:
|
|
|
|
|
|
|
| 42 |
Self = object
|
scrapling/engines/_browsers/__init__.py
CHANGED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
from ._controllers import DynamicSession, AsyncDynamicSession
|
| 2 |
-
from ._camoufox import StealthySession, AsyncStealthySession
|
|
|
|
|
|
|
|
|