From 8fa53743e05f0bd65ade1f20a13dbc1c978cd137 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 20 Apr 2024 18:22:56 +0100 Subject: [PATCH 1/6] Drop old Mypy ignores --- .mypy.ini | 15 --------------- aiohttp/abc.py | 2 +- aiohttp/connector.py | 2 +- aiohttp/resolver.py | 9 ++++----- examples/fake_server.py | 2 +- tests/test_resolver.py | 9 +-------- 6 files changed, 8 insertions(+), 31 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index 895ea60e335..667c513c686 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -26,20 +26,5 @@ warn_return_any = True #warn_unreachable = True warn_unused_ignores = True -[mypy-aiodns] -ignore_missing_imports = True - -[mypy-asynctest] -ignore_missing_imports = True - -[mypy-brotli] -ignore_missing_imports = True - -[mypy-brotlicffi] -ignore_missing_imports = True - [mypy-gunicorn.*] ignore_missing_imports = True - -[mypy-python_on_whales] -ignore_missing_imports = True diff --git a/aiohttp/abc.py b/aiohttp/abc.py index 0131197e992..b9a30b709d7 100644 --- a/aiohttp/abc.py +++ b/aiohttp/abc.py @@ -146,7 +146,7 @@ class AbstractResolver(ABC): @abstractmethod async def resolve( - self, host: str, port: int = 0, family: int = socket.AF_INET + self, host: str, port: int = 0, family: socket.AddressFamily = socket.AF_INET ) -> List[ResolveResult]: """Return IP address for given hostname""" diff --git a/aiohttp/connector.py b/aiohttp/connector.py index baf1f8cfcab..bfaa5adf331 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -745,7 +745,7 @@ def __init__( *, use_dns_cache: bool = True, ttl_dns_cache: Optional[int] = 10, - family: int = 0, + family: socket.AddressFamily = socket.AddressFamily.AF_UNSPEC, ssl: Union[bool, Fingerprint, SSLContext] = True, local_addr: Optional[Tuple[str, int]] = None, resolver: Optional[AbstractResolver] = None, diff --git a/aiohttp/resolver.py b/aiohttp/resolver.py index ee9b4d0b9a5..36a4b98bd64 100644 --- a/aiohttp/resolver.py +++ b/aiohttp/resolver.py @@ -12,7 +12,7 @@ # aiodns_default = hasattr(aiodns.DNSResolver, 'getaddrinfo') except ImportError: # pragma: no cover - aiodns = None + aiodns = None # type: ignore[assignment] aiodns_default = False @@ -32,7 +32,7 @@ def __init__(self) -> None: self._loop = asyncio.get_running_loop() async def resolve( - self, host: str, port: int = 0, family: int = socket.AF_INET + self, host: str, port: int = 0, family: socket.AddressFamily = socket.AF_INET ) -> List[ResolveResult]: infos = await self._loop.getaddrinfo( host, @@ -86,11 +86,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: if aiodns is None: raise RuntimeError("Resolver requires aiodns library") - self._loop = asyncio.get_running_loop() - self._resolver = aiodns.DNSResolver(*args, loop=self._loop, **kwargs) + self._resolver = aiodns.DNSResolver(*args, **kwargs) async def resolve( - self, host: str, port: int = 0, family: int = socket.AF_INET + self, host: str, port: int = 0, family: socket.AddressFamily = socket.AF_INET ) -> List[ResolveResult]: try: resp = await self._resolver.getaddrinfo( diff --git a/examples/fake_server.py b/examples/fake_server.py index 860cbc1e753..d6753b7b74f 100755 --- a/examples/fake_server.py +++ b/examples/fake_server.py @@ -22,7 +22,7 @@ async def resolve( self, host: str, port: int = 0, - family: Union[socket.AddressFamily, int] = socket.AF_INET, + family: socket.AddressFamily = socket.AF_INET, ) -> List[ResolveResult]: fake_port = self._fakes.get(host) if fake_port is not None: diff --git a/tests/test_resolver.py b/tests/test_resolver.py index 5e454dde334..ce9f345d737 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -20,7 +20,7 @@ getaddrinfo: Any = hasattr(aiodns.DNSResolver, "getaddrinfo") except ImportError: - aiodns = None + aiodns = None # type: ignore[assignment] getaddrinfo = False @@ -289,13 +289,6 @@ async def test_default_loop_for_threaded_resolver(loop: Any) -> None: assert resolver._loop is loop -@pytest.mark.skipif(aiodns is None, reason="aiodns required") -async def test_default_loop_for_async_resolver(loop: Any) -> None: - asyncio.set_event_loop(loop) - resolver = AsyncResolver() - assert resolver._loop is loop - - @pytest.mark.skipif(not getaddrinfo, reason="aiodns >=3.2.0 required") async def test_async_resolver_ipv6_positive_lookup(loop: Any) -> None: with patch("aiodns.DNSResolver") as mock: From 90fa0e30292f48f52fbfa2f7a3302622f258763e Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 20 Apr 2024 18:30:36 +0100 Subject: [PATCH 2/6] Add missing dependencies --- requirements/lint.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requirements/lint.in b/requirements/lint.in index f1f16a99aa9..3108c289045 100644 --- a/requirements/lint.in +++ b/requirements/lint.in @@ -1,6 +1,10 @@ +aiodns aioredis +Brotli +brotlicffi mypy; implementation_name == "cpython" pre-commit pytest +python-on-whales slotscheck uvloop; platform_system != "Windows" From ee70a02c0bb6702169e5f4bb517276ba2a16f8bb Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 20 Apr 2024 18:31:43 +0100 Subject: [PATCH 3/6] Unused import --- examples/fake_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/fake_server.py b/examples/fake_server.py index d6753b7b74f..d7be5954232 100755 --- a/examples/fake_server.py +++ b/examples/fake_server.py @@ -3,7 +3,7 @@ import pathlib import socket import ssl -from typing import Dict, List, Union +from typing import Dict, List from aiohttp import ClientSession, TCPConnector, test_utils, web from aiohttp.abc import AbstractResolver, ResolveResult From a3fa1576af63189bd58c9472a815b96f5c555379 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 20 Apr 2024 18:44:08 +0100 Subject: [PATCH 4/6] Revert brotli --- .mypy.ini | 6 ++++++ requirements/lint.in | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index 667c513c686..70261107033 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -26,5 +26,11 @@ warn_return_any = True #warn_unreachable = True warn_unused_ignores = True +[mypy-brotli] +ignore_missing_imports = True + +[mypy-brotlicffi] +ignore_missing_imports = True + [mypy-gunicorn.*] ignore_missing_imports = True diff --git a/requirements/lint.in b/requirements/lint.in index 3108c289045..98910e21f0e 100644 --- a/requirements/lint.in +++ b/requirements/lint.in @@ -1,7 +1,5 @@ aiodns aioredis -Brotli -brotlicffi mypy; implementation_name == "cpython" pre-commit pytest From 3999647c9958258a6c72eae0993c01f936398502 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Tue, 23 Apr 2024 15:30:57 +0100 Subject: [PATCH 5/6] ignore false positive --- tests/autobahn/test_autobahn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/autobahn/test_autobahn.py b/tests/autobahn/test_autobahn.py index 570660bc070..50b5bad2473 100644 --- a/tests/autobahn/test_autobahn.py +++ b/tests/autobahn/test_autobahn.py @@ -72,7 +72,8 @@ def test_client(report_dir: Path, request: Any) -> None: print("Stopping client and server") client.terminate() client.wait() - autobahn_container.stop() + # https://github.com/gabrieldemarmiesse/python-on-whales/pull/580 + autobahn_container.stop() # type: ignore[union-attr] failed_messages = get_failed_tests(f"{report_dir}/clients", "aiohttp") From f6b79e2cb830362bfa5435294ebaaa39ef5d1d95 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Tue, 23 Apr 2024 15:45:10 +0100 Subject: [PATCH 6/6] Pip compile --- requirements/lint.txt | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/requirements/lint.txt b/requirements/lint.txt index 408327b634c..ed31f58a244 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -4,14 +4,26 @@ # # pip-compile --allow-unsafe --output-file=requirements/lint.txt --strip-extras requirements/lint.in # +aiodns==3.2.0 + # via -r requirements/lint.in aioredis==2.0.1 # via -r requirements/lint.in +annotated-types==0.6.0 + # via pydantic async-timeout==4.0.3 # via aioredis +certifi==2024.2.2 + # via requests +cffi==1.16.0 + # via pycares cfgv==3.3.1 # via pre-commit +charset-normalizer==3.3.2 + # via requests click==8.1.6 - # via slotscheck + # via + # slotscheck + # typer distlib==0.3.7 # via virtualenv exceptiongroup==1.1.2 @@ -20,8 +32,14 @@ filelock==3.12.2 # via virtualenv identify==2.5.26 # via pre-commit +idna==3.7 + # via requests iniconfig==2.0.0 # via pytest +markdown-it-py==3.0.0 + # via rich +mdurl==0.1.2 + # via markdown-it-py mypy==1.9.0 ; implementation_name == "cpython" # via -r requirements/lint.in mypy-extensions==1.0.0 @@ -36,10 +54,28 @@ pluggy==1.4.0 # via pytest pre-commit==3.5.0 # via -r requirements/lint.in +pycares==4.4.0 + # via aiodns +pycparser==2.22 + # via cffi +pydantic==2.7.1 + # via python-on-whales +pydantic-core==2.18.2 + # via pydantic +pygments==2.17.2 + # via rich pytest==8.1.1 # via -r requirements/lint.in +python-on-whales==0.70.1 + # via -r requirements/lint.in pyyaml==6.0.1 # via pre-commit +requests==2.31.0 + # via python-on-whales +rich==13.7.1 + # via typer +shellingham==1.5.4 + # via typer slotscheck==0.19.0 # via -r requirements/lint.in tomli==2.0.1 @@ -47,11 +83,21 @@ tomli==2.0.1 # mypy # pytest # slotscheck +tqdm==4.66.2 + # via python-on-whales +typer==0.12.3 + # via python-on-whales typing-extensions==4.10.0 # via # -r requirements/typing-extensions.in # aioredis # mypy + # pydantic + # pydantic-core + # python-on-whales + # typer +urllib3==2.2.1 + # via requests uvloop==0.19.0 ; platform_system != "Windows" # via -r requirements/lint.in virtualenv==20.24.2