]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add parameters to generics in `_client.py` (#2266)
authorRamazan Elsunakev <35545693+relsunkaev@users.noreply.github.com>
Wed, 12 Oct 2022 08:45:06 +0000 (01:45 -0700)
committerGitHub <noreply@github.com>
Wed, 12 Oct 2022 08:45:06 +0000 (09:45 +0100)
Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
httpx/_client.py

index 6479ea712f5315984d396d3c6e1cc1006c576e6a..f4c62ac4778732fa59dd74c33d8bfa2b1deb2325 100644 (file)
@@ -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: