diff --git a/httpx/__init__.py b/httpx/__init__.py index af38f8a912..19ab42b5c3 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -1,7 +1,7 @@ from .__version__ import __description__, __title__, __version__ from ._api import delete, get, head, options, patch, post, put, request, stream from ._auth import Auth, BasicAuth, DigestAuth -from ._client import AsyncClient, Client +from ._client import USE_CLIENT_DEFAULT, AsyncClient, Client from ._config import Limits, Proxy, Timeout, create_ssl_context from ._content import ByteStream from ._exceptions import ( @@ -112,6 +112,7 @@ "TransportError", "UnsupportedProtocol", "URL", + "USE_CLIENT_DEFAULT", "WriteError", "WriteTimeout", "WSGITransport", diff --git a/httpx/_client.py b/httpx/_client.py index 429382fa80..e33597f531 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -11,6 +11,8 @@ DEFAULT_MAX_REDIRECTS, DEFAULT_TIMEOUT_CONFIG, UNSET, + USE_CLIENT_DEFAULT, + ClientDefaultType, Limits, Proxy, Timeout, @@ -301,7 +303,7 @@ def stream( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> "StreamContextManager": @@ -446,9 +448,15 @@ def _build_auth(self, auth: AuthTypes) -> typing.Optional[Auth]: raise TypeError(f'Invalid "auth" argument: {auth!r}') def _build_request_auth( - self, request: Request, auth: typing.Union[AuthTypes, UnsetType] = UNSET + self, + request: Request, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, ) -> Auth: - auth = self._auth if isinstance(auth, UnsetType) else self._build_auth(auth) + auth = ( + self._auth + if isinstance(auth, ClientDefaultType) + else self._build_auth(auth) + ) if auth is not None: return auth @@ -758,7 +766,7 @@ def request( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -798,7 +806,7 @@ def send( request: Request, *, stream: bool = False, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -958,7 +966,7 @@ def get( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -985,7 +993,7 @@ def options( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1012,7 +1020,7 @@ def head( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1043,7 +1051,7 @@ def post( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1078,7 +1086,7 @@ def put( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1113,7 +1121,7 @@ def patch( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1144,7 +1152,7 @@ def delete( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1394,7 +1402,7 @@ async def request( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1435,7 +1443,7 @@ async def send( request: Request, *, stream: bool = False, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1602,7 +1610,7 @@ async def get( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1629,7 +1637,7 @@ async def options( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1656,7 +1664,7 @@ async def head( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1687,7 +1695,7 @@ async def post( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1722,7 +1730,7 @@ async def put( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1757,7 +1765,7 @@ async def patch( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1788,7 +1796,7 @@ async def delete( params: QueryParamTypes = None, headers: HeaderTypes = None, cookies: CookieTypes = None, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, ) -> Response: @@ -1877,7 +1885,7 @@ def __init__( client: BaseClient, request: Request, *, - auth: typing.Union[AuthTypes, UnsetType] = UNSET, + auth: typing.Union[AuthTypes, ClientDefaultType] = USE_CLIENT_DEFAULT, allow_redirects: bool = True, timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET, close_client: bool = False, diff --git a/httpx/_config.py b/httpx/_config.py index 837519afb5..858f4478e4 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -34,10 +34,15 @@ class UnsetType: + pass #  pragma: nocover + + +class ClientDefaultType: pass # pragma: nocover UNSET = UnsetType() +USE_CLIENT_DEFAULT = ClientDefaultType() def create_ssl_context(