Skip to content

Commit

Permalink
style: type hint about aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
shengchenyang committed Nov 19, 2024
1 parent 6440615 commit 62160a8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ayugespidertools/scraper/http/request/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import copy
from collections.abc import Awaitable, Callable, Iterable, Mapping
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, AnyStr, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, AnyStr, Optional, Tuple, TypedDict, Union

from scrapy import Request

Expand All @@ -16,6 +18,21 @@
from aiohttp.client_reqrep import ClientResponse, Fingerprint
from aiohttp.helpers import BasicAuth
from aiohttp.typedefs import LooseHeaders
from scrapy.http import Response
from typing_extensions import Concatenate, NotRequired

CallbackT = Callable[Concatenate[Response, ...], Any]


class VerboseCookie(TypedDict):
name: str
value: str
domain: NotRequired[str]
path: NotRequired[str]
secure: NotRequired[bool]


CookiesT = Union[dict[str, str], list[VerboseCookie]]


class AiohttpRequest(Request):
Expand All @@ -24,10 +41,10 @@ class AiohttpRequest(Request):
def __init__(
self,
url: str,
callback: Optional[Callable] = None,
callback: Optional[CallbackT] = None,
method: str = "GET",
headers: Union[Mapping[AnyStr, Any], Iterable[Tuple[AnyStr, Any]], None] = None,
cookies: Optional[Union[dict, list[dict]]] = None,
cookies: Optional[CookiesT] = None,
meta: Optional[dict[str, Any]] = None,
encoding: str = "utf-8",
priority: int = 0,
Expand Down

0 comments on commit 62160a8

Please sign in to comment.