Skip to content
Myr

Escalate 0.17 deprecation warnings to becoming fully deprecated. (#1597)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 39d8ee6 · Browse files · 7 files+14 added−80 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+14 added−80 removed

  • tests:+12 added−33 removed
  • other:+2 added−47 removed

7 files+14 added−80 removed

modified:httpx/__init__.py+1 added-2 removed
33 unmodified lines
34 WriteError,35 WriteTimeout,36)37from ._models import URL, Cookies, Headers, QueryParams, Request, Response38from ._status_codes import StatusCode, codes38from ._status_codes import codes39from ._transports.asgi import ASGITransport40from ._transports.base import (41 AsyncBaseTransport,42 AsyncByteStream,
56 unmodified lines
99 "RequestError",100 "RequestNotRead",101 "Response",102 "ResponseNotRead",103 "StatusCode",103 "stream",104 "StreamClosed",105 "StreamConsumed",106 "StreamError",
17 unmodified lines
modified:httpx/_client.py-17 removed
55 unmodified lines
56 URLPattern,57 get_environment_proxies,58 get_logger,59 same_origin,60 warn_deprecated,60)6162# The type annotation for @classmethod and context managers here follows PEP 48463# https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods
520 unmodified lines
584 proxies: ProxiesTypes = None,585 mounts: typing.Mapping[str, BaseTransport] = None,586 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,587 limits: Limits = DEFAULT_LIMITS,589 pool_limits: Limits = None,588 max_redirects: int = DEFAULT_MAX_REDIRECTS,589 event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None,590 base_url: URLTypes = "",591 transport: BaseTransport = None,
20 unmodified lines
612 "Using http2=True, but the 'h2' package is not installed. "613 "Make sure to install httpx using `pip install httpx[http2]`."614 ) from None615618 if pool_limits is not None:619 warn_deprecated(620 "Client(..., pool_limits=...) is deprecated and will raise "621 "errors in the future. Use Client(..., limits=...) instead."622 )623 limits = pool_limits624616 allow_env_proxies = trust_env and app is None and transport is None617 proxy_map = self._get_proxy_map(proxies, allow_env_proxies)618619 self._transport = self._init_transport(
650 unmodified lines
1270 proxies: ProxiesTypes = None,1271 mounts: typing.Mapping[str, AsyncBaseTransport] = None,1272 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,1273 limits: Limits = DEFAULT_LIMITS,1283 pool_limits: Limits = None,1274 max_redirects: int = DEFAULT_MAX_REDIRECTS,1275 event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None,1276 base_url: URLTypes = "",1277 transport: AsyncBaseTransport = None,
20 unmodified lines
1298 "Using http2=True, but the 'h2' package is not installed. "1299 "Make sure to install httpx using `pip install httpx[http2]`."1300 ) from None13011312 if pool_limits is not None:1313 warn_deprecated(1314 "AsyncClient(..., pool_limits=...) is deprecated and will raise "1315 "errors in the future. Use AsyncClient(..., limits=...) instead."1316 )1317 limits = pool_limits13181302 allow_env_proxies = trust_env and app is None and transport is None1303 proxy_map = self._get_proxy_map(proxies, allow_env_proxies)13041305 self._transport = self._init_transport(
614 unmodified lines
modified:httpx/_status_codes.py-21 removed
1import warnings1from enum import IntEnum234class codes(IntEnum):
135 unmodified lines
140141# Include lower-case styles for `requests` compatibility.142for code in codes:143 setattr(codes, code._name_.lower(), int(code))145146147class StatusCodeCompat:148 def __call__(self, *args, **kwargs): # type: ignore149 message = "`httpx.StatusCode` is deprecated. Use `httpx.codes` instead."150 warnings.warn(message, DeprecationWarning)151 return codes(*args, **kwargs)152153 def __getattr__(self, attr): # type: ignore154 message = "`httpx.StatusCode` is deprecated. Use `httpx.codes` instead."155 warnings.warn(message, DeprecationWarning)156 return getattr(codes, attr)157158 def __getitem__(self, item): # type: ignore159 message = "`httpx.StatusCode` is deprecated. Use `httpx.codes` instead."160 warnings.warn(message, DeprecationWarning)161 return codes[item]162163164StatusCode = StatusCodeCompat()
modified:httpx/_utils.py+1 added-7 removed
6 unmodified lines
7import re8import sys9import time10import typing11import warnings11from pathlib import Path12from urllib.request import getproxies1314import sniffio
455 unmodified lines
470 def __init__(self, pattern: str) -> None:471 from ._models import URL472473 if pattern and ":" not in pattern:475 warn_deprecated(474 raise ValueError(475 f"Proxy keys should use proper URL forms rather "476 f"than plain scheme strings. "477 f'Instead of "{pattern}", use "{pattern}://"'478 )480 pattern += "://"479480 url = URL(pattern)481 self.pattern = pattern482 self.scheme = "" if url.scheme == "all" else url.scheme
49 unmodified lines
532 return self.priority < other.priority533534 def __eq__(self, other: typing.Any) -> bool:535 return isinstance(other, URLPattern) and self.pattern == other.pattern538539540def warn_deprecated(message: str) -> None: # pragma: nocover541 warnings.warn(message, DeprecationWarning, stacklevel=2)
modified:tests/client/test_client.py-10 removed
220 unmodified lines
221 request = client.build_request("GET", "/testing")222 assert request.url == "https://www.example.com/base%2Fpath/testing"223224225def test_pool_limits_deprecated():226 limits = httpx.Limits()227228 with pytest.warns(DeprecationWarning):229 httpx.Client(pool_limits=limits)230231 with pytest.warns(DeprecationWarning):232 httpx.AsyncClient(pool_limits=limits)233234225def test_context_managed_transport():226 class Transport(httpx.BaseTransport):227 def __init__(self):228 self.events = []
165 unmodified lines
modified:tests/client/test_proxies.py+12 added-10 removed
254 unmodified lines
255 assert transport._pool.proxy_origin == url_to_origin(expected)256257258@pytest.mark.parametrize(259 ["proxies", "expected_scheme"],259 ["proxies", "is_valid"],260 [261 ({"http": "http://127.0.0.1"}, "http://"),262 ({"https": "http://127.0.0.1"}, "https://"),263 ({"all": "http://127.0.0.1"}, "all://"),261 ({"http": "http://127.0.0.1"}, False),262 ({"https": "http://127.0.0.1"}, False),263 ({"all": "http://127.0.0.1"}, False),264 ({"http://": "http://127.0.0.1"}, True),265 ({"https://": "http://127.0.0.1"}, True),266 ({"all://": "http://127.0.0.1"}, True),267 ],268)266def test_for_deprecated_proxy_params(proxies, expected_scheme):267 with pytest.deprecated_call() as block:269def test_for_deprecated_proxy_params(proxies, is_valid):270 if not is_valid:271 with pytest.raises(ValueError):272 httpx.Client(proxies=proxies)273 else:274 httpx.Client(proxies=proxies)269270 warning_message = str(block.pop(DeprecationWarning))271272 assert expected_scheme in warning_message
modified:tests/test_status_codes.py-13 removed
1import pytest21import httpx234def test_status_code_as_int():
18 unmodified lines
232425def test_reason_phrase_for_unknown_status_code():26 assert httpx.codes.get_reason_phrase(499) == ""293031def test_deprecated_status_code_class():32 with pytest.warns(DeprecationWarning):33 assert httpx.StatusCode.NOT_FOUND == 4043435 with pytest.warns(DeprecationWarning):36 assert httpx.StatusCode(404) == 4043738 with pytest.warns(DeprecationWarning):39 assert httpx.StatusCode["NOT_FOUND"] == 404