diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index aa0d48159c0..92b3529bf13 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -1054,7 +1054,7 @@ def update_headers(self, headers: LooseHeaders | None) -> None: if isinstance(headers, (dict, MultiDictProxy, MultiDict)): headers = headers.items() - for key, value in headers: # type: ignore[misc] + for key, value in headers: # type: ignore[str-unpack] # A special case for Host header if key in hdrs.HOST_ALL: self.headers[key] = value diff --git a/aiohttp/web_log.py b/aiohttp/web_log.py index 27b50adf6d6..9283cc08b12 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): @@ -198,7 +200,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 @@ -212,17 +214,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/requirements/constraints.txt b/requirements/constraints.txt index b66ab9a7524..c6d30465d32 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -119,7 +119,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 3ea0c9d728c..265223cd0ea 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -116,7 +116,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 77209a1d445..c9cf6e965dc 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 878bd428141..fd6f9729e3f 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 e83b5d1bb7f..5b4e6bd7428 100644 --- a/requirements/test-ft.txt +++ b/requirements/test-ft.txt @@ -67,7 +67,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 8b8e81854f0..ad46077728a 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -67,7 +67,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