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
Provenance
- Commit
6e55ca1- Tree
c6c5eb2- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
39d8ee6
7 files changed+14 added−80 removed
modified:httpx/__init__.py+1 added-2 removed
33 unmodified lines34 WriteError,35 WriteTimeout,36 )37 from ._models import URL, Cookies, Headers, QueryParams, Request, Response38-from ._status_codes import StatusCode, codes38+from ._status_codes import codes39 from ._transports.asgi import ASGITransport40 from ._transports.base import (41 AsyncBaseTransport,42 AsyncByteStream,56 unmodified lines99 "RequestError",100 "RequestNotRead",101 "Response",102 "ResponseNotRead",103- "StatusCode",103 "stream",104 "StreamClosed",105 "StreamConsumed",106 "StreamError",17 unmodified linesmodified:httpx/_client.py-17 removed
55 unmodified lines56 URLPattern,57 get_environment_proxies,58 get_logger,59 same_origin,60- warn_deprecated,60 )61 62 # The type annotation for @classmethod and context managers here follows PEP 48463 # https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods520 unmodified lines584 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 lines612 "Using http2=True, but the 'h2' package is not installed. "613 "Make sure to install httpx using `pip install httpx[http2]`."614 ) from None615 618- 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_limits624-616 allow_env_proxies = trust_env and app is None and transport is None617 proxy_map = self._get_proxy_map(proxies, allow_env_proxies)618 619 self._transport = self._init_transport(650 unmodified lines1270 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 lines1298 "Using http2=True, but the 'h2' package is not installed. "1299 "Make sure to install httpx using `pip install httpx[http2]`."1300 ) from None1301 1312- 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_limits1318-1302 allow_env_proxies = trust_env and app is None and transport is None1303 proxy_map = self._get_proxy_map(proxies, allow_env_proxies)1304 1305 self._transport = self._init_transport(614 unmodified linesmodified:httpx/_status_codes.py-21 removed
1-import warnings1 from enum import IntEnum2 3 4 class codes(IntEnum):135 unmodified lines140 141 # Include lower-case styles for `requests` compatibility.142 for code in codes:143 setattr(codes, code._name_.lower(), int(code))145-146-147-class 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)152-153- 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)157-158- def __getitem__(self, item): # type: ignore159- message = "`httpx.StatusCode` is deprecated. Use `httpx.codes` instead."160- warnings.warn(message, DeprecationWarning)161- return codes[item]162-163-164-StatusCode = StatusCodeCompat()modified:httpx/_utils.py+1 added-7 removed
6 unmodified lines7 import re8 import sys9 import time10 import typing11-import warnings11 from pathlib import Path12 from urllib.request import getproxies13 14 import sniffio455 unmodified lines470 def __init__(self, pattern: str) -> None:471 from ._models import URL472 473 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 += "://"479 480 url = URL(pattern)481 self.pattern = pattern482 self.scheme = "" if url.scheme == "all" else url.scheme49 unmodified lines532 return self.priority < other.priority533 534 def __eq__(self, other: typing.Any) -> bool:535 return isinstance(other, URLPattern) and self.pattern == other.pattern538-539-540-def warn_deprecated(message: str) -> None: # pragma: nocover541- warnings.warn(message, DeprecationWarning, stacklevel=2)modified:tests/client/test_client.py-10 removed
220 unmodified lines221 request = client.build_request("GET", "/testing")222 assert request.url == "https://www.example.com/base%2Fpath/testing"223 224 225-def test_pool_limits_deprecated():226- limits = httpx.Limits()227-228- with pytest.warns(DeprecationWarning):229- httpx.Client(pool_limits=limits)230-231- with pytest.warns(DeprecationWarning):232- httpx.AsyncClient(pool_limits=limits)233-234-225 def test_context_managed_transport():226 class Transport(httpx.BaseTransport):227 def __init__(self):228 self.events = []165 unmodified linesmodified:tests/client/test_proxies.py+12 added-10 removed
254 unmodified lines255 assert transport._pool.proxy_origin == url_to_origin(expected)256 257 258 @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 )266-def test_for_deprecated_proxy_params(proxies, expected_scheme):267- with pytest.deprecated_call() as block:269+def 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)269-270- warning_message = str(block.pop(DeprecationWarning))271-272- assert expected_scheme in warning_messagemodified:tests/test_status_codes.py-13 removed
1-import pytest2-1 import httpx2 3 4 def test_status_code_as_int():18 unmodified lines23 24 25 def test_reason_phrase_for_unknown_status_code():26 assert httpx.codes.get_reason_phrase(499) == ""29-30-31-def test_deprecated_status_code_class():32- with pytest.warns(DeprecationWarning):33- assert httpx.StatusCode.NOT_FOUND == 40434-35- with pytest.warns(DeprecationWarning):36- assert httpx.StatusCode(404) == 40437-38- with pytest.warns(DeprecationWarning):39- assert httpx.StatusCode["NOT_FOUND"] == 404