fix: make browser fetchers type hints always present

This commit is contained in:
Karim shoair
2026-02-15 01:03:15 +02:00
parent 77e825e7be
commit ba4d33337f
+17 -22
View File
@@ -19,7 +19,6 @@ from scrapling.core._types import (
TypeAlias, TypeAlias,
SetCookieParam, SetCookieParam,
SelectorWaitStates, SelectorWaitStates,
TYPE_CHECKING,
) )
from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator
@@ -27,9 +26,8 @@ from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator
ImpersonateType: TypeAlias = BrowserTypeLiteral | List[BrowserTypeLiteral] | None ImpersonateType: TypeAlias = BrowserTypeLiteral | List[BrowserTypeLiteral] | None
if TYPE_CHECKING: # pragma: no cover # Types for session initialization
# Types for session initialization class RequestsSession(TypedDict, total=False):
class RequestsSession(TypedDict, total=False):
impersonate: ImpersonateType impersonate: ImpersonateType
http3: Optional[bool] http3: Optional[bool]
stealthy_headers: Optional[bool] stealthy_headers: Optional[bool]
@@ -47,19 +45,22 @@ if TYPE_CHECKING: # pragma: no cover
cert: Optional[str | Tuple[str, str]] cert: Optional[str | Tuple[str, str]]
selector_config: Optional[Dict] selector_config: Optional[Dict]
# Types for GET request method parameters
class GetRequestParams(RequestsSession, total=False): # Types for GET request method parameters
class GetRequestParams(RequestsSession, total=False):
params: Optional[Dict | List | Tuple] params: Optional[Dict | List | Tuple]
cookies: Optional[CookieTypes] cookies: Optional[CookieTypes]
auth: Optional[Tuple[str, str]] auth: Optional[Tuple[str, str]]
# Types for POST/PUT/DELETE request method parameters
class DataRequestParams(GetRequestParams, total=False): # Types for POST/PUT/DELETE request method parameters
class DataRequestParams(GetRequestParams, total=False):
data: Optional[Dict[str, str] | List[Tuple] | str | BytesIO | bytes] data: Optional[Dict[str, str] | List[Tuple] | str | BytesIO | bytes]
json: Optional[Dict | List] json: Optional[Dict | List]
# Types for browser session
class PlaywrightSession(TypedDict, total=False): # Types for browser session
class PlaywrightSession(TypedDict, total=False):
max_pages: int max_pages: int
headless: bool headless: bool
disable_resources: bool disable_resources: bool
@@ -89,7 +90,8 @@ if TYPE_CHECKING: # pragma: no cover
retries: int retries: int
retry_delay: int | float retry_delay: int | float
class PlaywrightFetchParams(TypedDict, total=False):
class PlaywrightFetchParams(TypedDict, total=False):
load_dom: bool load_dom: bool
wait: int | float wait: int | float
network_idle: bool network_idle: bool
@@ -104,20 +106,13 @@ if TYPE_CHECKING: # pragma: no cover
blocked_domains: Optional[Set[str]] blocked_domains: Optional[Set[str]]
proxy: Optional[str | Dict[str, str]] proxy: Optional[str | Dict[str, str]]
class StealthSession(PlaywrightSession, total=False):
class StealthSession(PlaywrightSession, total=False):
allow_webgl: bool allow_webgl: bool
hide_canvas: bool hide_canvas: bool
block_webrtc: bool block_webrtc: bool
solve_cloudflare: bool solve_cloudflare: bool
class StealthFetchParams(PlaywrightFetchParams, total=False):
solve_cloudflare: bool
else: # pragma: no cover class StealthFetchParams(PlaywrightFetchParams, total=False):
RequestsSession = TypedDict solve_cloudflare: bool
GetRequestParams = TypedDict
DataRequestParams = TypedDict
PlaywrightSession = TypedDict
PlaywrightFetchParams = TypedDict
StealthSession = TypedDict
StealthFetchParams = TypedDict