diff --git a/aiohttp/client.py b/aiohttp/client.py index 026dbcdf591..6a9b084a7b3 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -900,9 +900,7 @@ async def _connect_and_send_request( if raise_for_status is None: raise_for_status = self._raise_for_status - if raise_for_status is None: - pass - elif callable(raise_for_status): + if callable(raise_for_status): await raise_for_status(resp) elif raise_for_status: resp.raise_for_status() diff --git a/aiohttp/web_log.py b/aiohttp/web_log.py index aafbf237ca6..27b1d87e214 100644 --- a/aiohttp/web_log.py +++ b/aiohttp/web_log.py @@ -4,15 +4,17 @@ import os import re import time as time_mod -from collections import namedtuple from collections.abc import Iterable -from typing import Callable, ClassVar +from typing import Callable, ClassVar, NamedTuple from .abc import AbstractAccessLogger from .web_request import BaseRequest from .web_response import StreamResponse -KeyMethod = namedtuple("KeyMethod", "key method") + +class KeyMethod(NamedTuple): + key: str | tuple[str, str] + method: Callable[[BaseRequest, StreamResponse, float], str] class AccessLogger(AbstractAccessLogger): @@ -191,7 +193,7 @@ def _format_D(request: BaseRequest, response: StreamResponse, time: float) -> st def _format_line( self, request: BaseRequest, response: StreamResponse, time: float - ) -> Iterable[tuple[str, Callable[[BaseRequest, StreamResponse, float], str]]]: + ) -> Iterable[tuple[str | tuple[str, str], str]]: return [(key, method(request, response, time)) for key, method in self._methods] @property @@ -205,17 +207,17 @@ def log(self, request: BaseRequest, response: StreamResponse, time: float) -> No fmt_info = self._format_line(request, response, time) values = list() - extra = dict() + extra: dict[str, str | dict[str, str]] = dict() for key, value in fmt_info: values.append(value) - if key.__class__ is str: + if isinstance(key, str): extra[key] = value else: - k1, k2 = key # type: ignore[misc] - dct = extra.get(k1, {}) # type: ignore[var-annotated,has-type] - dct[k2] = value # type: ignore[index,has-type] - extra[k1] = dct # type: ignore[has-type,assignment] + k1, k2 = key + dct: dict[str, str] = extra.get(k1, {}) # type: ignore[assignment] + dct[k2] = value + extra[k1] = dct self.logger.info(self._log_format % tuple(values), extra=extra) except Exception: diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index 0245d7b776c..2728eecf953 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -633,8 +633,7 @@ async def start(self) -> None: # Drop the processed task from asyncio.Task.all_tasks() early del task - # https://github.com/python/mypy/issues/14309 - if reset: # type: ignore[possibly-undefined] + if reset: self.log_debug("Ignored premature client disconnection 2") break diff --git a/aiohttp/web_routedef.py b/aiohttp/web_routedef.py index dc566b64f03..c396774fa54 100644 --- a/aiohttp/web_routedef.py +++ b/aiohttp/web_routedef.py @@ -152,10 +152,12 @@ def __repr__(self) -> str: def __getitem__(self, index: int) -> AbstractRouteDef: ... @overload - def __getitem__(self, index: "slice[int, int, int]") -> list[AbstractRouteDef]: ... + def __getitem__( + self, index: "slice[int | None, int | None, int | None]" + ) -> list[AbstractRouteDef]: ... def __getitem__( - self, index: Union[int, "slice[int, int, int]"] + self, index: Union[int, "slice[int | None, int | None, int | None]"] ) -> AbstractRouteDef | list[AbstractRouteDef]: return self._items[index] diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 19913f6806e..8afa2c213ec 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -158,7 +158,7 @@ def __init__( expect_handler = _default_expect_handler assert inspect.iscoroutinefunction(expect_handler) or ( - sys.version_info < (3, 14) and asyncio.iscoroutinefunction(expect_handler) + sys.version_info < (3, 14) and asyncio.iscoroutinefunction(expect_handler) # type: ignore[deprecated] ), f"Coroutine is expected, got {expect_handler!r}" method = method.upper() @@ -166,7 +166,7 @@ def __init__( raise ValueError(f"{method} is not allowed HTTP method") if inspect.iscoroutinefunction(handler) or ( - sys.version_info < (3, 14) and asyncio.iscoroutinefunction(handler) + sys.version_info < (3, 14) and asyncio.iscoroutinefunction(handler) # type: ignore[deprecated] ): pass elif isinstance(handler, type) and issubclass(handler, AbstractView): diff --git a/aiohttp/worker.py b/aiohttp/worker.py index 05d516061b1..88c67016c54 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -65,7 +65,7 @@ async def _run(self) -> None: if isinstance(self.wsgi, Application): app = self.wsgi elif inspect.iscoroutinefunction(self.wsgi) or ( - sys.version_info < (3, 14) and asyncio.iscoroutinefunction(self.wsgi) + sys.version_info < (3, 14) and asyncio.iscoroutinefunction(self.wsgi) # type: ignore[deprecated] ): wsgi = await self.wsgi() if isinstance(wsgi, web.AppRunner): diff --git a/requirements/constraints.txt b/requirements/constraints.txt index f8984715fd8..981765119ad 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -117,7 +117,7 @@ multidict==6.7.1 # -r requirements/multidict.in # -r requirements/runtime-deps.in # yarl -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via # -r requirements/lint.in # -r requirements/test-common.in diff --git a/requirements/dev.txt b/requirements/dev.txt index df5d8a2b9b8..251abc94af0 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -114,7 +114,7 @@ multidict==6.7.1 # via # -r requirements/runtime-deps.in # yarl -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via # -r requirements/lint.in # -r requirements/test-common.in diff --git a/requirements/lint.txt b/requirements/lint.txt index 0fee06995fc..11c725a38a1 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -51,7 +51,7 @@ markdown-it-py==4.0.0 # via rich mdurl==0.1.2 # via markdown-it-py -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via -r requirements/lint.in mypy-extensions==1.1.0 # via mypy diff --git a/requirements/test-common.txt b/requirements/test-common.txt index 1e63b83a974..6e29c3c9530 100644 --- a/requirements/test-common.txt +++ b/requirements/test-common.txt @@ -40,7 +40,7 @@ markdown-it-py==4.0.0 # via rich mdurl==0.1.2 # via markdown-it-py -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via -r requirements/test-common.in mypy-extensions==1.1.0 # via mypy diff --git a/requirements/test-ft.txt b/requirements/test-ft.txt index 23006dc6100..c9d2d1433a5 100644 --- a/requirements/test-ft.txt +++ b/requirements/test-ft.txt @@ -65,7 +65,7 @@ multidict==6.7.1 # via # -r requirements/runtime-deps.in # yarl -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via -r requirements/test-common.in mypy-extensions==1.1.0 # via mypy diff --git a/requirements/test.txt b/requirements/test.txt index 05301f8ee6d..2a6c25928df 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -65,7 +65,7 @@ multidict==6.7.1 # via # -r requirements/runtime-deps.in # yarl -mypy==1.19.1 ; implementation_name == "cpython" +mypy==1.20.2 ; implementation_name == "cpython" # via -r requirements/test-common.in mypy-extensions==1.1.0 # via mypy diff --git a/tests/test_web_request.py b/tests/test_web_request.py index a204cc1fd48..89cfa60fc3a 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -289,7 +289,7 @@ def test_request_cookie__set_item() -> None: assert req.cookies == {"name": "value"} with pytest.raises(TypeError): - req.cookies["my"] = "value" # type: ignore[index] + req.cookies["my"] = "value" def test_request_cookies_with_special_characters() -> None: