Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 12 additions & 10 deletions aiohttp/web_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ 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()
if not HTTP_METHOD_RE.match(method):
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):
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/test-common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/test-ft.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading