From 1adc8139b9ea57a6d9611dc6507d7e3db4b9924a Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 6 Jul 2026 00:15:29 -0400 Subject: [PATCH] docs: fix README health-check snippet's invalid aiohttp kwarg; widen add()/replace() type hints to accept dict shapes the flagship health-check snippet called session.get(url, proxies=proxy) on a plain aiohttp session; aiohttp's ClientSession.get/_request has no `proxies=` kwarg (only singular `proxy:`), so the snippet TypeErrors immediately if followed verbatim. pm.get()'s dict output is documented (aiohttp()'s own docstring) as being for aioweb's ExtendedSession(proxies=...), so the snippet now names that session type instead of a bare aiohttp one. add()/replace() type hints omitted Dict[str, str] even though both already call to_proxy() at runtime and accept dict-shaped proxy specs, same as the burn()/restore()/is_burned()/remove() family. purely annotation, no behavior change. Signed-off-by: disqualifier --- README.md | 4 +++- src/aioproxies/manager.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b44528f..731f417 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,14 @@ regardless of source.) ```python from aioproxies import AioProxies, ProxiesExhaustedError +from aioweb import ExtendedSession pm = AioProxies(proxies=[...], cooldown=5) # 5s reuse spacing; cooldown defaults to 0 (off) try: proxy = pm.get() # next usable proxy, aiohttp dict - resp = await session.get(url, proxies=proxy) + async with ExtendedSession(proxies=proxy) as session: + resp = await session.get(url) if response_looks_blocked(resp): pm.burn(proxy, 600) # time out 10 min ... or pm.burn(proxy) for dead except ProxiesExhaustedError: diff --git a/src/aioproxies/manager.py b/src/aioproxies/manager.py index 99e350c..0774ff4 100644 --- a/src/aioproxies/manager.py +++ b/src/aioproxies/manager.py @@ -302,7 +302,7 @@ class AioProxies: for state in self._state.values(): state["uses"] = 0 - def replace(self, proxies: List[Union[str, Proxy]], *, keep_state: bool = False) -> None: + def replace(self, proxies: List[Union[str, Proxy, Dict[str, str]]], *, keep_state: bool = False) -> None: """swap the entire proxy list keep_state=False (default) wipes all per-proxy state (fresh batch). @@ -336,7 +336,7 @@ class AioProxies: self._state = new_state self._index = 0 - def add(self, proxies: Union[str, Proxy, List[Union[str, Proxy]]]) -> None: + def add(self, proxies: Union[str, Proxy, Dict[str, str], List[Union[str, Proxy, Dict[str, str]]]]) -> None: """append proxies to the pool, keeping existing state; skip duplicate keys""" if not self._is_list_source(): self._warn_non_list("add()")