From: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:30:05 +0000 (+0400) Subject: Define and expose the API from the same place (#3106) X-Git-Tag: 0.27.1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87713d2172053c4ad05efacf3ab7e0a5c15616fc;p=thirdparty%2Fhttpx.git Define and expose the API from the same place (#3106) * Tidy up imports * Update tests/test_exported_members.py --------- Co-authored-by: Tom Christie --- diff --git a/httpx/__init__.py b/httpx/__init__.py index f61112f8..e9addde0 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -1,48 +1,15 @@ from .__version__ import __description__, __title__, __version__ -from ._api import delete, get, head, options, patch, post, put, request, stream -from ._auth import Auth, BasicAuth, DigestAuth, NetRCAuth -from ._client import USE_CLIENT_DEFAULT, AsyncClient, Client -from ._config import Limits, Proxy, Timeout, create_ssl_context -from ._content import ByteStream -from ._exceptions import ( - CloseError, - ConnectError, - ConnectTimeout, - CookieConflict, - DecodingError, - HTTPError, - HTTPStatusError, - InvalidURL, - LocalProtocolError, - NetworkError, - PoolTimeout, - ProtocolError, - ProxyError, - ReadError, - ReadTimeout, - RemoteProtocolError, - RequestError, - RequestNotRead, - ResponseNotRead, - StreamClosed, - StreamConsumed, - StreamError, - TimeoutException, - TooManyRedirects, - TransportError, - UnsupportedProtocol, - WriteError, - WriteTimeout, -) -from ._models import Cookies, Headers, Request, Response -from ._status_codes import codes -from ._transports.asgi import ASGITransport -from ._transports.base import AsyncBaseTransport, BaseTransport -from ._transports.default import AsyncHTTPTransport, HTTPTransport -from ._transports.mock import MockTransport -from ._transports.wsgi import WSGITransport -from ._types import AsyncByteStream, SyncByteStream -from ._urls import URL, QueryParams +from ._api import * +from ._auth import * +from ._client import * +from ._config import * +from ._content import * +from ._exceptions import * +from ._models import * +from ._status_codes import * +from ._transports import * +from ._types import * +from ._urls import * try: from ._main import main diff --git a/httpx/_api.py b/httpx/_api.py index b5821cc4..3dd943b3 100644 --- a/httpx/_api.py +++ b/httpx/_api.py @@ -22,6 +22,18 @@ from ._types import ( VerifyTypes, ) +__all__ = [ + "delete", + "get", + "head", + "options", + "patch", + "post", + "put", + "request", + "stream", +] + def request( method: str, diff --git a/httpx/_auth.py b/httpx/_auth.py index 903e3996..b03971ab 100644 --- a/httpx/_auth.py +++ b/httpx/_auth.py @@ -16,6 +16,9 @@ if typing.TYPE_CHECKING: # pragma: no cover from hashlib import _Hash +__all__ = ["Auth", "BasicAuth", "DigestAuth", "NetRCAuth"] + + class Auth: """ Base class for all authentication schemes. diff --git a/httpx/_client.py b/httpx/_client.py index e2c6702e..cf3b3062 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -58,6 +58,8 @@ from ._utils import ( same_origin, ) +__all__ = ["USE_CLIENT_DEFAULT", "AsyncClient", "Client"] + # The type annotation for @classmethod and context managers here follows PEP 484 # https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods T = typing.TypeVar("T", bound="Client") diff --git a/httpx/_config.py b/httpx/_config.py index 7636a5dc..6662ea80 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -14,6 +14,8 @@ from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes from ._urls import URL from ._utils import get_ca_bundle_from_env +__all__ = ["Limits", "Proxy", "Timeout", "create_ssl_context"] + DEFAULT_CIPHERS = ":".join( [ "ECDHE+AESGCM", diff --git a/httpx/_content.py b/httpx/_content.py index 10b574bb..786699f3 100644 --- a/httpx/_content.py +++ b/httpx/_content.py @@ -25,6 +25,8 @@ from ._types import ( ) from ._utils import peek_filelike_length, primitive_value_to_str +__all__ = ["ByteStream"] + class ByteStream(AsyncByteStream, SyncByteStream): def __init__(self, stream: bytes) -> None: diff --git a/httpx/_exceptions.py b/httpx/_exceptions.py index 11424621..18dfa2f2 100644 --- a/httpx/_exceptions.py +++ b/httpx/_exceptions.py @@ -38,6 +38,37 @@ import typing if typing.TYPE_CHECKING: from ._models import Request, Response # pragma: no cover +__all__ = [ + "CloseError", + "ConnectError", + "ConnectTimeout", + "CookieConflict", + "DecodingError", + "HTTPError", + "HTTPStatusError", + "InvalidURL", + "LocalProtocolError", + "NetworkError", + "PoolTimeout", + "ProtocolError", + "ProxyError", + "ReadError", + "ReadTimeout", + "RemoteProtocolError", + "RequestError", + "RequestNotRead", + "ResponseNotRead", + "StreamClosed", + "StreamConsumed", + "StreamError", + "TimeoutException", + "TooManyRedirects", + "TransportError", + "UnsupportedProtocol", + "WriteError", + "WriteTimeout", +] + class HTTPError(Exception): """ diff --git a/httpx/_models.py b/httpx/_models.py index cd76705f..92b393a2 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -53,6 +53,8 @@ from ._utils import ( parse_header_links, ) +__all__ = ["Cookies", "Headers", "Request", "Response"] + class Headers(typing.MutableMapping[str, str]): """ diff --git a/httpx/_status_codes.py b/httpx/_status_codes.py index 4cde4e68..133a6231 100644 --- a/httpx/_status_codes.py +++ b/httpx/_status_codes.py @@ -2,6 +2,8 @@ from __future__ import annotations from enum import IntEnum +__all__ = ["codes"] + class codes(IntEnum): """HTTP status codes and reason phrases diff --git a/httpx/_transports/__init__.py b/httpx/_transports/__init__.py index e69de29b..7a321053 100644 --- a/httpx/_transports/__init__.py +++ b/httpx/_transports/__init__.py @@ -0,0 +1,15 @@ +from .asgi import * +from .base import * +from .default import * +from .mock import * +from .wsgi import * + +__all__ = [ + "ASGITransport", + "AsyncBaseTransport", + "BaseTransport", + "AsyncHTTPTransport", + "HTTPTransport", + "MockTransport", + "WSGITransport", +] diff --git a/httpx/_transports/asgi.py b/httpx/_transports/asgi.py index 9543a128..794cb17b 100644 --- a/httpx/_transports/asgi.py +++ b/httpx/_transports/asgi.py @@ -25,6 +25,8 @@ _ASGIApp = typing.Callable[ [typing.Dict[str, typing.Any], _Receive, _Send], typing.Coroutine[None, None, None] ] +__all__ = ["ASGITransport"] + def create_event() -> Event: if sniffio.current_async_library() == "trio": diff --git a/httpx/_transports/base.py b/httpx/_transports/base.py index 8b6dc3c2..66fd99d7 100644 --- a/httpx/_transports/base.py +++ b/httpx/_transports/base.py @@ -8,6 +8,8 @@ from .._models import Request, Response T = typing.TypeVar("T", bound="BaseTransport") A = typing.TypeVar("A", bound="AsyncBaseTransport") +__all__ = ["AsyncBaseTransport", "BaseTransport"] + class BaseTransport: def __enter__(self: T) -> T: diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index 14476a3c..e82104e9 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -62,6 +62,8 @@ SOCKET_OPTION = typing.Union[ typing.Tuple[int, int, None, int], ] +__all__ = ["AsyncHTTPTransport", "HTTPTransport"] + @contextlib.contextmanager def map_httpcore_exceptions() -> typing.Iterator[None]: diff --git a/httpx/_transports/mock.py b/httpx/_transports/mock.py index 5abea837..8c418f59 100644 --- a/httpx/_transports/mock.py +++ b/httpx/_transports/mock.py @@ -9,6 +9,9 @@ SyncHandler = typing.Callable[[Request], Response] AsyncHandler = typing.Callable[[Request], typing.Coroutine[None, None, Response]] +__all__ = ["MockTransport"] + + class MockTransport(AsyncBaseTransport, BaseTransport): def __init__(self, handler: SyncHandler | AsyncHandler) -> None: self.handler = handler diff --git a/httpx/_transports/wsgi.py b/httpx/_transports/wsgi.py index cd03a941..8592ffe0 100644 --- a/httpx/_transports/wsgi.py +++ b/httpx/_transports/wsgi.py @@ -16,6 +16,9 @@ if typing.TYPE_CHECKING: _T = typing.TypeVar("_T") +__all__ = ["WSGITransport"] + + def _skip_leading_empty_chunks(body: typing.Iterable[_T]) -> typing.Iterable[_T]: body = iter(body) for chunk in body: diff --git a/httpx/_types.py b/httpx/_types.py index 649d101d..b7b0518c 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -108,6 +108,8 @@ RequestFiles = Union[Mapping[str, FileTypes], Sequence[Tuple[str, FileTypes]]] RequestExtensions = MutableMapping[str, Any] +__all__ = ["AsyncByteStream", "SyncByteStream"] + class SyncByteStream: def __iter__(self) -> Iterator[bytes]: diff --git a/httpx/_urls.py b/httpx/_urls.py index 43dedd56..f9f68a99 100644 --- a/httpx/_urls.py +++ b/httpx/_urls.py @@ -9,6 +9,8 @@ from ._types import QueryParamTypes, RawURL, URLTypes from ._urlparse import urlencode, urlparse from ._utils import primitive_value_to_str +__all__ = ["URL", "QueryParams"] + class URL: """ diff --git a/pyproject.toml b/pyproject.toml index 4f7a848f..3fe24a14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,6 +101,9 @@ ignore = ["B904", "B028"] [tool.ruff.isort] combine-as-imports = true +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["F403", "F405"] + [tool.mypy] ignore_missing_imports = true strict = true