Rename PoolLimits to Limits (#1113)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Rename PoolLimits to Limits * Lint
authored by Florimond Manca · committed by GitHub · parent 26cd4f5 · Browse files · 7 files·+80 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Tom Christie <tom@tomchristie.com>
Diff stats
7 files+80 added−38 removed
- tests:+21 added−6 removed
- other:+59 added−32 removed
Provenance
- Commit
f67e925- Tree
f6d8fe3- Author
Florimond Manca <florimond.manca@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
26cd4f5
7 files changed+80 added−38 removed
modified:docs/advanced.md+4 added-4 removed
399 unmodified lines400 ```401 402 ## Pool limit configuration403 404-You can control the connection pool size using the `pool_limits` keyword405-argument on the client. It takes instances of `httpx.PoolLimits` which define:404+You can control the connection pool size using the `limits` keyword405+argument on the client. It takes instances of `httpx.Limits` which define:406 407 - `max_keepalive`, number of allowable keep-alive connections, or `None` to always408 allow. (Defaults 10)409 - `max_connections`, maximum number of allowable connections, or` None` for no limits.410 (Default 100)411 412 413 ```python414-limits = httpx.PoolLimits(max_keepalive=5, max_connections=10)415-client = httpx.Client(pool_limits=limits)414+limits = httpx.Limits(max_keepalive=5, max_connections=10)415+client = httpx.Client(limits=limits)416 ```417 418 ## Multipart file encoding419 290 unmodified linesmodified:httpx/__init__.py+2 added-1 removed
1 from .__version__ import __description__, __title__, __version__2 from ._api import delete, get, head, options, patch, post, put, request, stream3 from ._auth import Auth, BasicAuth, DigestAuth4 from ._client import AsyncClient, Client5-from ._config import PoolLimits, Proxy, Timeout, create_ssl_context5+from ._config import Limits, PoolLimits, Proxy, Timeout, create_ssl_context6 from ._exceptions import (7 CloseError,8 ConnectError,9 ConnectTimeout,48 unmodified lines58 "Auth",59 "BasicAuth",60 "Client",61 "DigestAuth",62+ "Limits",63 "PoolLimits",64 "Proxy",65 "Timeout",66 "create_ssl_context",39 unmodified linesmodified:httpx/_client.py+39 added-24 removed
5 unmodified lines6 import httpcore7 8 from ._auth import Auth, BasicAuth, FunctionAuth9 from ._config import (10+ DEFAULT_LIMITS,11 DEFAULT_MAX_REDIRECTS,11- DEFAULT_POOL_LIMITS,12 DEFAULT_TIMEOUT_CONFIG,13 UNSET,14- PoolLimits,14+ Limits,15 Proxy,16 Timeout,17 UnsetType,18 create_ssl_context,30 unmodified lines49 get_environment_proxies,50 get_logger,51 same_origin,52 should_not_be_proxied,53+ warn_deprecated,54 )55 56 logger = get_logger(__name__)57 364 unmodified lines422 * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy423 URLs.424 * **timeout** - *(optional)* The timeout configuration to use when sending425 requests.425- * **pool_limits** - *(optional)* The connection pool configuration to use426- when determining the maximum number of concurrently open HTTP connections.426+ * **limits** - *(optional)* The limits configuration to use.427 * **max_redirects** - *(optional)* The maximum number of redirect responses428 that should be followed.429 * **base_url** - *(optional)* A URL to use as the base when building430 request URLs.16 unmodified lines447 cert: CertTypes = None,448 http2: bool = False,449 proxies: ProxiesTypes = None,450 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,451- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,451+ limits: Limits = DEFAULT_LIMITS,452+ pool_limits: Limits = None,453 max_redirects: int = DEFAULT_MAX_REDIRECTS,454 base_url: URLTypes = None,455 transport: httpcore.SyncHTTPTransport = None,456 app: typing.Callable = None,9 unmodified lines466 base_url=base_url,467 trust_env=trust_env,468 )469 470+ if pool_limits is not None:471+ warn_deprecated(472+ "Client(..., pool_limits=...) is deprecated and will raise "473+ "errors in the future. Use Client(..., limits=...) instead."474+ )475+ limits = pool_limits476+477 proxy_map = self._get_proxy_map(proxies, trust_env)478 479 self._transport = self._init_transport(480 verify=verify,481 cert=cert,482 http2=http2,475- pool_limits=pool_limits,483+ limits=limits,484 transport=transport,485 app=app,486 trust_env=trust_env,487 )6 unmodified lines494 proxy,495 verify=verify,496 cert=cert,497 http2=http2,490- pool_limits=pool_limits,498+ limits=limits,499 trust_env=trust_env,500 )501 for key, proxy in proxy_map.items()502 }3 unmodified lines506 self,507 verify: VerifyTypes = True,508 cert: CertTypes = None,509 http2: bool = False,502- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,510+ limits: Limits = DEFAULT_LIMITS,511 transport: httpcore.SyncHTTPTransport = None,512 app: typing.Callable = None,513 trust_env: bool = True,514 ) -> httpcore.SyncHTTPTransport:6 unmodified lines521 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)522 523 return httpcore.SyncConnectionPool(524 ssl_context=ssl_context,517- max_keepalive=pool_limits.max_keepalive,518- max_connections=pool_limits.max_connections,525+ max_keepalive=limits.max_keepalive,526+ max_connections=limits.max_connections,527 keepalive_expiry=KEEPALIVE_EXPIRY,528 http2=http2,529 )530 2 unmodified lines533 proxy: Proxy,534 verify: VerifyTypes = True,535 cert: CertTypes = None,536 http2: bool = False,529- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,537+ limits: Limits = DEFAULT_LIMITS,538 trust_env: bool = True,539 ) -> httpcore.SyncHTTPTransport:540 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)541 1 unmodified line543 proxy_url=proxy.url.raw,544 proxy_headers=proxy.headers.raw,545 proxy_mode=proxy.mode,546 ssl_context=ssl_context,539- max_keepalive=pool_limits.max_keepalive,540- max_connections=pool_limits.max_connections,547+ max_keepalive=limits.max_keepalive,548+ max_connections=limits.max_connections,549 keepalive_expiry=KEEPALIVE_EXPIRY,550 http2=http2,551 )552 400 unmodified lines953 * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy954 URLs.955 * **timeout** - *(optional)* The timeout configuration to use when sending956 requests.949- * **pool_limits** - *(optional)* The connection pool configuration to use950- when determining the maximum number of concurrently open HTTP connections.957+ * **limits** - *(optional)* The limits configuration to use.958 * **max_redirects** - *(optional)* The maximum number of redirect responses959 that should be followed.960 * **base_url** - *(optional)* A URL to use as the base when building961 request URLs.16 unmodified lines978 cert: CertTypes = None,979 http2: bool = False,980 proxies: ProxiesTypes = None,981 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,975- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,982+ limits: Limits = DEFAULT_LIMITS,983+ pool_limits: Limits = None,984 max_redirects: int = DEFAULT_MAX_REDIRECTS,985 base_url: URLTypes = None,986 transport: httpcore.AsyncHTTPTransport = None,987 app: typing.Callable = None,9 unmodified lines997 base_url=base_url,998 trust_env=trust_env,999 )1000 1001+ if pool_limits is not None:1002+ warn_deprecated(1003+ "AsyncClient(..., pool_limits=...) is deprecated and will raise "1004+ "errors in the future. Use AsyncClient(..., limits=...) instead."1005+ )1006+ limits = pool_limits1007+1008 proxy_map = self._get_proxy_map(proxies, trust_env)1009 1010 self._transport = self._init_transport(1011 verify=verify,1012 cert=cert,1013 http2=http2,999- pool_limits=pool_limits,1014+ limits=limits,1015 transport=transport,1016 app=app,1017 trust_env=trust_env,1018 )6 unmodified lines1025 proxy,1026 verify=verify,1027 cert=cert,1028 http2=http2,1014- pool_limits=pool_limits,1029+ limits=limits,1030 trust_env=trust_env,1031 )1032 for key, proxy in proxy_map.items()1033 }3 unmodified lines1037 self,1038 verify: VerifyTypes = True,1039 cert: CertTypes = None,1040 http2: bool = False,1026- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,1041+ limits: Limits = DEFAULT_LIMITS,1042 transport: httpcore.AsyncHTTPTransport = None,1043 app: typing.Callable = None,1044 trust_env: bool = True,1045 ) -> httpcore.AsyncHTTPTransport:6 unmodified lines1052 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)1053 1054 return httpcore.AsyncConnectionPool(1055 ssl_context=ssl_context,1041- max_keepalive=pool_limits.max_keepalive,1042- max_connections=pool_limits.max_connections,1056+ max_keepalive=limits.max_keepalive,1057+ max_connections=limits.max_connections,1058 keepalive_expiry=KEEPALIVE_EXPIRY,1059 http2=http2,1060 )1061 2 unmodified lines1064 proxy: Proxy,1065 verify: VerifyTypes = True,1066 cert: CertTypes = None,1067 http2: bool = False,1053- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,1068+ limits: Limits = DEFAULT_LIMITS,1069 trust_env: bool = True,1070 ) -> httpcore.AsyncHTTPTransport:1071 ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)1072 1 unmodified line1074 proxy_url=proxy.url.raw,1075 proxy_headers=proxy.headers.raw,1076 proxy_mode=proxy.mode,1077 ssl_context=ssl_context,1063- max_keepalive=pool_limits.max_keepalive,1064- max_connections=pool_limits.max_connections,1078+ max_keepalive=limits.max_keepalive,1079+ max_connections=limits.max_connections,1080 keepalive_expiry=KEEPALIVE_EXPIRY,1081 http2=http2,1082 )1083 427 unmodified linesmodified:httpx/_config.py+14 added-3 removed
315 unmodified lines316 f"read={self.read}, write={self.write}, pool={self.pool})"317 )318 319 320-class PoolLimits:320+class Limits:321 """322- Limits on the number of connections in a connection pool.322+ Configuration for limits to various client behaviors.323 324 **Parameters:**325 326 * **max_keepalive** - Allow the connection pool to maintain keep-alive connections22 unmodified lines349 f"max_connections={self.max_connections})"350 )351 352 353+class PoolLimits(Limits):354+ def __init__(355+ self, *, max_keepalive: int = None, max_connections: int = None,356+ ) -> None:357+ warn_deprecated(358+ "httpx.PoolLimits(...) is deprecated and will raise errors in the future. "359+ "Use httpx.Limits(...) instead."360+ )361+ super().__init__(max_keepalive=max_keepalive, max_connections=max_connections)362+363+364 class Proxy:365 def __init__(366 self, url: URLTypes, *, headers: HeaderTypes = None, mode: str = "DEFAULT",367 ):31 unmodified lines399 )400 401 402 DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=5.0)392-DEFAULT_POOL_LIMITS = PoolLimits(max_keepalive=10, max_connections=100)403+DEFAULT_LIMITS = Limits(max_keepalive=10, max_connections=100)404 DEFAULT_MAX_REDIRECTS = 20modified:tests/client/test_client.py+10 added
192 unmodified lines193 client = httpx.Client()194 request = client.build_request("GET", url)195 assert request.url.scheme == scheme196 assert request.url.is_ssl == is_ssl197+198+199+def test_pool_limits_deprecated():200+ limits = httpx.Limits()201+202+ with pytest.warns(DeprecationWarning):203+ httpx.Client(pool_limits=limits)204+205+ with pytest.warns(DeprecationWarning):206+ httpx.AsyncClient(pool_limits=limits)modified:tests/test_config.py+9 added-4 removed
99 unmodified lines100 assert response.status_code == 200101 102 103 def test_limits_repr():104- limits = httpx.PoolLimits(max_connections=100)105- assert repr(limits) == "PoolLimits(max_keepalive=None, max_connections=100)"104+ limits = httpx.Limits(max_connections=100)105+ assert repr(limits) == "Limits(max_keepalive=None, max_connections=100)"106 107 108 def test_limits_eq():109- limits = httpx.PoolLimits(max_connections=100)110- assert limits == httpx.PoolLimits(max_connections=100)109+ limits = httpx.Limits(max_connections=100)110+ assert limits == httpx.Limits(max_connections=100)111 112 113+def test_pool_limits_deprecated():114+ with pytest.warns(DeprecationWarning):115+ httpx.PoolLimits()116+117+118 def test_timeout_eq():119 timeout = httpx.Timeout(timeout=5.0)120 assert timeout == httpx.Timeout(timeout=5.0)121 116 unmodified linesmodified:tests/test_timeouts.py+2 added-2 removed
32 unmodified lines33 34 35 @pytest.mark.usefixtures("async_environment")36 async def test_pool_timeout(server):37- pool_limits = httpx.PoolLimits(max_connections=1)37+ limits = httpx.Limits(max_connections=1)38 timeout = httpx.Timeout(None, pool=1e-4)39 40- async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client:40+ async with httpx.AsyncClient(limits=limits, timeout=timeout) as client:41 async with client.stream("GET", server.url):42 with pytest.raises(httpx.PoolTimeout):43 await client.get("http://localhost:8000/")44 13 unmodified lines