]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Move types definitions to a dedicated module (#902)
authorFlorimond Manca <florimond.manca@gmail.com>
Wed, 15 Apr 2020 11:12:09 +0000 (13:12 +0200)
committerGitHub <noreply@github.com>
Wed, 15 Apr 2020 11:12:09 +0000 (13:12 +0200)
httpx/_api.py
httpx/_auth.py
httpx/_client.py
httpx/_config.py
httpx/_content_streams.py
httpx/_dispatch/urllib3.py
httpx/_models.py
httpx/_types.py
httpx/_utils.py

index d42277c87e86186f7a1c9ca353262741540e79c1..a300f633e7ace1d0876a39735bf9af0c7ac64336 100644 (file)
@@ -1,17 +1,19 @@
 import typing
 
-from ._auth import AuthTypes
 from ._client import Client, StreamContextManager
-from ._config import DEFAULT_TIMEOUT_CONFIG, CertTypes, TimeoutTypes, VerifyTypes
-from ._models import (
+from ._config import DEFAULT_TIMEOUT_CONFIG
+from ._models import Request, Response
+from ._types import (
+    AuthTypes,
+    CertTypes,
     CookieTypes,
     HeaderTypes,
     QueryParamTypes,
-    Request,
     RequestData,
     RequestFiles,
-    Response,
+    TimeoutTypes,
     URLTypes,
+    VerifyTypes,
 )
 
 
index a8a9e624461072d120a992990d30d5e79b4cb215..e2278434ad98ba1a966592b9f6769accb20f0c81 100644 (file)
@@ -10,12 +10,6 @@ from ._exceptions import ProtocolError, RequestBodyUnavailable
 from ._models import Request, Response
 from ._utils import to_bytes, to_str, unquote
 
-AuthTypes = typing.Union[
-    typing.Tuple[typing.Union[str, bytes], typing.Union[str, bytes]],
-    typing.Callable[["Request"], "Request"],
-    "Auth",
-]
-
 
 class Auth:
     """
index 054b7af01f70259311fe58928408828424c5e6b7..df01c3da39bb6f5d4fd614eac3e8929f8a090abe 100644 (file)
@@ -5,42 +5,37 @@ from types import TracebackType
 import hstspreload
 import httpcore
 
-from ._auth import Auth, AuthTypes, BasicAuth, FunctionAuth
+from ._auth import Auth, BasicAuth, FunctionAuth
 from ._config import (
     DEFAULT_MAX_REDIRECTS,
     DEFAULT_POOL_LIMITS,
     DEFAULT_TIMEOUT_CONFIG,
     UNSET,
-    CertTypes,
     PoolLimits,
-    ProxiesTypes,
     Proxy,
     SSLConfig,
     Timeout,
-    TimeoutTypes,
     UnsetType,
-    VerifyTypes,
 )
 from ._content_streams import ContentStream
 from ._dispatch.asgi import ASGIDispatch
 from ._dispatch.wsgi import WSGIDispatch
 from ._exceptions import HTTPError, InvalidURL, RequestBodyUnavailable, TooManyRedirects
-from ._models import (
-    URL,
-    Cookies,
+from ._models import URL, Cookies, Headers, Origin, QueryParams, Request, Response
+from ._status_codes import codes
+from ._types import (
+    AuthTypes,
+    CertTypes,
     CookieTypes,
-    Headers,
     HeaderTypes,
-    Origin,
-    QueryParams,
+    ProxiesTypes,
     QueryParamTypes,
-    Request,
     RequestData,
     RequestFiles,
-    Response,
+    TimeoutTypes,
     URLTypes,
+    VerifyTypes,
 )
-from ._status_codes import codes
 from ._utils import (
     NetRCInfo,
     get_environment_proxies,
index a08238680b2b1945cd84fc0fb043b76190ffeb6c..52255c26a6a34d72f9339b428dab4035ffb34e74 100644 (file)
@@ -6,19 +6,10 @@ from pathlib import Path
 
 import certifi
 
-from ._models import URL, Headers, HeaderTypes, URLTypes
+from ._models import URL, Headers
+from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes
 from ._utils import get_ca_bundle_from_env, get_logger
 
-CertTypes = typing.Union[str, typing.Tuple[str, str], typing.Tuple[str, str, str]]
-VerifyTypes = typing.Union[str, bool, ssl.SSLContext]
-TimeoutTypes = typing.Union[
-    None, float, typing.Tuple[float, float, float, float], "Timeout"
-]
-ProxiesTypes = typing.Union[
-    URLTypes, "Proxy", typing.Dict[URLTypes, typing.Union[URLTypes, "Proxy"]]
-]
-
-
 DEFAULT_CIPHERS = ":".join(
     [
         "ECDHE+AESGCM",
index fa8616af20a97e4fc5b1bb7cb1f21ccd492745c2..72c5c52debbef059d335e84906a80e5382291ce2 100644 (file)
@@ -8,7 +8,7 @@ from urllib.parse import urlencode
 import httpcore
 
 from ._exceptions import StreamConsumed
-from ._types import StrOrBytes
+from ._types import RequestData, RequestFiles
 from ._utils import (
     format_form_param,
     guess_content_type,
@@ -16,29 +16,6 @@ from ._utils import (
     to_bytes,
 )
 
-RequestData = typing.Union[
-    dict, str, bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]
-]
-
-RequestFiles = typing.Dict[
-    str,
-    typing.Union[
-        # file (or str)
-        typing.Union[typing.IO[str], typing.IO[bytes], StrOrBytes],
-        # (filename, file (or str))
-        typing.Tuple[
-            typing.Optional[str],
-            typing.Union[typing.IO[str], typing.IO[bytes], StrOrBytes],
-        ],
-        # (filename, file (or str), content_type)
-        typing.Tuple[
-            typing.Optional[str],
-            typing.Union[typing.IO[str], typing.IO[bytes], StrOrBytes],
-            typing.Optional[str],
-        ],
-    ],
-]
-
 
 class ContentStream(httpcore.AsyncByteStream, httpcore.SyncByteStream):
     def get_headers(self) -> typing.Dict[str, str]:
index c3fcbe4df794100018d30cfac5bc092d9584c8b9..57c257dfa65c8aa1a08a2d23238203ed68acb2fb 100644 (file)
@@ -7,15 +7,9 @@ import httpcore
 import urllib3
 from urllib3.exceptions import MaxRetryError, SSLError
 
-from .._config import (
-    DEFAULT_POOL_LIMITS,
-    CertTypes,
-    PoolLimits,
-    Proxy,
-    SSLConfig,
-    VerifyTypes,
-)
+from .._config import DEFAULT_POOL_LIMITS, PoolLimits, Proxy, SSLConfig
 from .._content_streams import ByteStream, IteratorStream
+from .._types import CertTypes, VerifyTypes
 from .._utils import as_network_error
 
 
index 1cdf92803bfb67ecc34399678af8ab255bf6b5e6..aa441afe33fe3e138fa8fd03e8e827f2eaafe5be 100644 (file)
@@ -13,13 +13,7 @@ import chardet
 import rfc3986
 
 from .__version__ import __version__
-from ._content_streams import (
-    ByteStream,
-    ContentStream,
-    RequestData,
-    RequestFiles,
-    encode,
-)
+from ._content_streams import ByteStream, ContentStream, encode
 from ._decoders import (
     SUPPORTED_DECODERS,
     Decoder,
@@ -39,7 +33,15 @@ from ._exceptions import (
     StreamConsumed,
 )
 from ._status_codes import StatusCode
-from ._types import StrOrBytes
+from ._types import (
+    CookieTypes,
+    HeaderTypes,
+    PrimitiveData,
+    QueryParamTypes,
+    RequestData,
+    RequestFiles,
+    URLTypes,
+)
 from ._utils import (
     ElapsedTimer,
     flatten_queryparams,
@@ -55,25 +57,6 @@ from ._utils import (
 if typing.TYPE_CHECKING:  # pragma: no cover
     from ._dispatch.base import AsyncDispatcher  # noqa: F401
 
-PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]]
-
-URLTypes = typing.Union["URL", str]
-
-QueryParamTypes = typing.Union[
-    "QueryParams",
-    typing.Mapping[str, typing.Union[PrimitiveData, typing.Sequence[PrimitiveData]]],
-    typing.List[typing.Tuple[str, PrimitiveData]],
-    str,
-]
-
-HeaderTypes = typing.Union[
-    "Headers",
-    typing.Dict[StrOrBytes, StrOrBytes],
-    typing.Sequence[typing.Tuple[StrOrBytes, StrOrBytes]],
-]
-
-CookieTypes = typing.Union["Cookies", CookieJar, typing.Dict[str, str]]
-
 
 class URL:
     def __init__(
index cb13a60925d5847a82fa4c887782c0f979411261..f124bf702421bfc72fc506c468bb8f5b44e1cffd 100644 (file)
@@ -2,6 +2,67 @@
 Type definitions for type checking purposes.
 """
 
-from typing import Union
+import ssl
+from http.cookiejar import CookieJar
+from typing import (
+    IO,
+    TYPE_CHECKING,
+    AsyncIterator,
+    Callable,
+    Dict,
+    Iterator,
+    List,
+    Mapping,
+    Optional,
+    Sequence,
+    Tuple,
+    Union,
+)
+
+if TYPE_CHECKING:  # pragma: no cover
+    from ._auth import Auth  # noqa: F401
+    from ._config import Proxy, Timeout  # noqa: F401
+    from ._models import URL, Cookies, Headers, QueryParams, Request  # noqa: F401
 
 StrOrBytes = Union[str, bytes]
+
+PrimitiveData = Optional[Union[str, int, float, bool]]
+
+URLTypes = Union["URL", str]
+
+QueryParamTypes = Union[
+    "QueryParams",
+    Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
+    List[Tuple[str, PrimitiveData]],
+    str,
+]
+
+HeaderTypes = Union[
+    "Headers", Dict[StrOrBytes, StrOrBytes], Sequence[Tuple[StrOrBytes, StrOrBytes]],
+]
+
+CookieTypes = Union["Cookies", CookieJar, Dict[str, str]]
+
+CertTypes = Union[str, Tuple[str, str], Tuple[str, str, str]]
+VerifyTypes = Union[str, bool, ssl.SSLContext]
+TimeoutTypes = Union[None, float, Tuple[float, float, float, float], "Timeout"]
+ProxiesTypes = Union[URLTypes, "Proxy", Dict[URLTypes, Union[URLTypes, "Proxy"]]]
+
+AuthTypes = Union[
+    Tuple[Union[str, bytes], Union[str, bytes]],
+    Callable[["Request"], "Request"],
+    "Auth",
+]
+
+RequestData = Union[dict, str, bytes, Iterator[bytes], AsyncIterator[bytes]]
+
+FileContent = Union[IO[str], IO[bytes], str, bytes]
+FileTypes = Union[
+    # file (or text)
+    FileContent,
+    # (filename, file (or text))
+    Tuple[Optional[str], FileContent],
+    # (filename, file (or text), content_type)
+    Tuple[Optional[str], FileContent, Optional[str]],
+]
+RequestFiles = Dict[str, FileTypes]
index b2be9f552815903e93237fa940552e7bc3d0d9e1..5eefde76648daf872e98cc5519a5241c92ece476 100644 (file)
@@ -15,10 +15,9 @@ from types import TracebackType
 from urllib.request import getproxies
 
 from ._exceptions import NetworkError
-from ._types import StrOrBytes
+from ._types import PrimitiveData, StrOrBytes
 
 if typing.TYPE_CHECKING:  # pragma: no cover
-    from ._models import PrimitiveData
     from ._models import URL