From: Ramazan Elsunakev <35545693+relsunkaev@users.noreply.github.com> Date: Wed, 12 Oct 2022 08:45:06 +0000 (-0700) Subject: Add parameters to generics in `_client.py` (#2266) X-Git-Tag: 0.23.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71ee50b27770b461a5d2aaba9fca1fbc261bede1;p=thirdparty%2Fhttpx.git Add parameters to generics in `_client.py` (#2266) Co-authored-by: Tom Christie Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> --- diff --git a/httpx/_client.py b/httpx/_client.py index 6479ea71..f4c62ac4 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -153,6 +153,9 @@ class BoundAsyncStream(AsyncByteStream): await self._stream.aclose() +EventHook = typing.Callable[..., typing.Any] + + class BaseClient: def __init__( self, @@ -165,7 +168,7 @@ class BaseClient: follow_redirects: bool = False, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: typing.Optional[ - typing.Mapping[str, typing.List[typing.Callable]] + typing.Mapping[str, typing.List[EventHook]] ] = None, base_url: URLTypes = "", trust_env: bool = True, @@ -236,12 +239,12 @@ class BaseClient: self._timeout = Timeout(timeout) @property - def event_hooks(self) -> typing.Dict[str, typing.List[typing.Callable]]: + def event_hooks(self) -> typing.Dict[str, typing.List[EventHook]]: return self._event_hooks @event_hooks.setter def event_hooks( - self, event_hooks: typing.Dict[str, typing.List[typing.Callable]] + self, event_hooks: typing.Dict[str, typing.List[EventHook]] ) -> None: self._event_hooks = { "request": list(event_hooks.get("request", [])), @@ -639,11 +642,11 @@ class Client(BaseClient): limits: Limits = DEFAULT_LIMITS, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: typing.Optional[ - typing.Mapping[str, typing.List[typing.Callable]] + typing.Mapping[str, typing.List[EventHook]] ] = None, base_url: URLTypes = "", transport: typing.Optional[BaseTransport] = None, - app: typing.Optional[typing.Callable] = None, + app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", ): @@ -712,7 +715,7 @@ class Client(BaseClient): http2: bool = False, limits: Limits = DEFAULT_LIMITS, transport: typing.Optional[BaseTransport] = None, - app: typing.Optional[typing.Callable] = None, + app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, ) -> BaseTransport: if transport is not None: @@ -1360,11 +1363,11 @@ class AsyncClient(BaseClient): limits: Limits = DEFAULT_LIMITS, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: typing.Optional[ - typing.Mapping[str, typing.List[typing.Callable]] + typing.Mapping[str, typing.List[typing.Callable[..., typing.Any]]] ] = None, base_url: URLTypes = "", transport: typing.Optional[AsyncBaseTransport] = None, - app: typing.Optional[typing.Callable] = None, + app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, default_encoding: typing.Union[str, typing.Callable[[bytes], str]] = "utf-8", ): @@ -1433,7 +1436,7 @@ class AsyncClient(BaseClient): http2: bool = False, limits: Limits = DEFAULT_LIMITS, transport: typing.Optional[AsyncBaseTransport] = None, - app: typing.Optional[typing.Callable] = None, + app: typing.Optional[typing.Callable[..., typing.Any]] = None, trust_env: bool = True, ) -> AsyncBaseTransport: if transport is not None: