Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update .pre-commit-config.yaml #8384

Merged
merged 4 commits into from
Apr 25, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ repos:
entry: ./tools/check_changes.py
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.0.1'
rev: 'v4.6.0'
hooks:
- id: check-merge-conflict
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.5.0
hooks:
- id: yesqa
- repo: https://github.com/PyCQA/isort
rev: '5.11.5'
rev: '5.13.2'
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '22.3.0'
rev: '24.4.0'
hooks:
- id: black
language_version: python3 # Should be a command that runs python
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.0.1'
rev: 'v4.6.0'
hooks:
- id: end-of-file-fixer
exclude: >-
Expand Down Expand Up @@ -97,12 +97,12 @@ repos:
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.29.0'
rev: 'v3.15.2'
hooks:
- id: pyupgrade
args: ['--py37-plus']
- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
rev: '7.0.0'
hooks:
- id: flake8
additional_dependencies:
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def update_body_from_data(self, body: Any) -> None:

# copy payload headers
assert body.headers
for (key, value) in body.headers.items():
for key, value in body.headers.items():
if key in self.headers:
continue
if key in self.skip_auto_headers:
Expand Down Expand Up @@ -820,9 +820,9 @@ def __init__(
# work after the response has finished reading the body.
if session is None:
# TODO: Fix session=None in tests (see ClientRequest.__init__).
self._resolve_charset: Callable[
["ClientResponse", bytes], str
] = lambda *_: "utf-8"
self._resolve_charset: Callable[["ClientResponse", bytes], str] = (
lambda *_: "utf-8"
)
else:
self._resolve_charset = session._resolve_charset
if loop.get_debug():
Expand Down
16 changes: 10 additions & 6 deletions aiohttp/client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ def _reset_heartbeat(self) -> None:
self._send_heartbeat,
self._heartbeat,
self._loop,
timeout_ceil_threshold=self._conn._connector._timeout_ceil_threshold
if self._conn is not None
else 5,
timeout_ceil_threshold=(
self._conn._connector._timeout_ceil_threshold
if self._conn is not None
else 5
),
)

def _send_heartbeat(self) -> None:
Expand All @@ -108,9 +110,11 @@ def _send_heartbeat(self) -> None:
self._pong_not_received,
self._pong_heartbeat,
self._loop,
timeout_ceil_threshold=self._conn._connector._timeout_ceil_threshold
if self._conn is not None
else 5,
timeout_ceil_threshold=(
self._conn._connector._timeout_ceil_threshold
if self._conn is not None
else 5
),
)

def _pong_not_received(self) -> None:
Expand Down
8 changes: 5 additions & 3 deletions aiohttp/compression_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def __init__(
max_sync_chunk_size: Optional[int] = MAX_SYNC_CHUNK_SIZE,
):
super().__init__(
mode=encoding_to_mode(encoding, suppress_deflate_header)
if wbits is None
else wbits,
mode=(
encoding_to_mode(encoding, suppress_deflate_header)
if wbits is None
else wbits
),
executor=executor,
max_sync_chunk_size=max_sync_chunk_size,
)
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def __init__(
self._limit = limit
self._limit_per_host = limit_per_host
self._acquired: Set[ResponseHandler] = set()
self._acquired_per_host: DefaultDict[
ConnectionKey, Set[ResponseHandler]
] = defaultdict(set)
self._acquired_per_host: DefaultDict[ConnectionKey, Set[ResponseHandler]] = (
defaultdict(set)
)
self._keepalive_timeout = cast(float, keepalive_timeout)
self._force_close = force_close

Expand Down
18 changes: 6 additions & 12 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,7 @@ def set_exception(
self,
exc: BaseException,
exc_cause: BaseException = ...,
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover


def set_exception(
Expand Down Expand Up @@ -905,12 +904,10 @@ def __init_subclass__(cls) -> None:
)

@overload # type: ignore[override]
def __getitem__(self, key: AppKey[_T]) -> _T:
...
def __getitem__(self, key: AppKey[_T]) -> _T: ...

@overload
def __getitem__(self, key: str) -> Any:
...
def __getitem__(self, key: str) -> Any: ...

def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
for mapping in self._maps:
Expand All @@ -921,16 +918,13 @@ def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
raise KeyError(key)

@overload # type: ignore[override]
def get(self, key: AppKey[_T], default: _S) -> Union[_T, _S]:
...
def get(self, key: AppKey[_T], default: _S) -> Union[_T, _S]: ...

@overload
def get(self, key: AppKey[_T], default: None = ...) -> Optional[_T]:
...
def get(self, key: AppKey[_T], default: None = ...) -> Optional[_T]: ...

@overload
def get(self, key: str, default: Any = ...) -> Any:
...
def get(self, key: str, default: Any = ...) -> Any: ...

def get(self, key: Union[str, AppKey[_T]], default: Any = None) -> Any:
try:
Expand Down
1 change: 0 additions & 1 deletion aiohttp/http_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Low-level http related exceptions."""


from textwrap import indent
from typing import Optional, Union

Expand Down
21 changes: 10 additions & 11 deletions aiohttp/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def __call__(
__client_session: ClientSession,
__trace_config_ctx: SimpleNamespace,
__params: _ParamT_contra,
) -> Awaitable[None]:
...
) -> Awaitable[None]: ...


__all__ = (
Expand Down Expand Up @@ -50,9 +49,9 @@ class TraceConfig:
def __init__(
self, trace_config_ctx_factory: Type[SimpleNamespace] = SimpleNamespace
) -> None:
self._on_request_start: Signal[
_SignalCallback[TraceRequestStartParams]
] = Signal(self)
self._on_request_start: Signal[_SignalCallback[TraceRequestStartParams]] = (
Signal(self)
)
self._on_request_chunk_sent: Signal[
_SignalCallback[TraceRequestChunkSentParams]
] = Signal(self)
Expand Down Expand Up @@ -89,12 +88,12 @@ def __init__(
self._on_dns_resolvehost_end: Signal[
_SignalCallback[TraceDnsResolveHostEndParams]
] = Signal(self)
self._on_dns_cache_hit: Signal[
_SignalCallback[TraceDnsCacheHitParams]
] = Signal(self)
self._on_dns_cache_miss: Signal[
_SignalCallback[TraceDnsCacheMissParams]
] = Signal(self)
self._on_dns_cache_hit: Signal[_SignalCallback[TraceDnsCacheHitParams]] = (
Signal(self)
)
self._on_dns_cache_miss: Signal[_SignalCallback[TraceDnsCacheMissParams]] = (
Signal(self)
)
self._on_request_headers_sent: Signal[
_SignalCallback[TraceRequestHeadersSentParams]
] = Signal(self)
Expand Down
21 changes: 7 additions & 14 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,10 @@ def __eq__(self, other: object) -> bool:
return self is other

@overload # type: ignore[override]
def __getitem__(self, key: AppKey[_T]) -> _T:
...
def __getitem__(self, key: AppKey[_T]) -> _T: ...

@overload
def __getitem__(self, key: str) -> Any:
...
def __getitem__(self, key: str) -> Any: ...

def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
return self._state[key]
Expand All @@ -203,12 +201,10 @@ def _check_frozen(self) -> None:
)

@overload # type: ignore[override]
def __setitem__(self, key: AppKey[_T], value: _T) -> None:
...
def __setitem__(self, key: AppKey[_T], value: _T) -> None: ...

@overload
def __setitem__(self, key: str, value: Any) -> None:
...
def __setitem__(self, key: str, value: Any) -> None: ...

def __setitem__(self, key: Union[str, AppKey[_T]], value: Any) -> None:
self._check_frozen()
Expand All @@ -233,16 +229,13 @@ def __iter__(self) -> Iterator[Union[str, AppKey[Any]]]:
return iter(self._state)

@overload # type: ignore[override]
def get(self, key: AppKey[_T], default: None = ...) -> Optional[_T]:
...
def get(self, key: AppKey[_T], default: None = ...) -> Optional[_T]: ...

@overload
def get(self, key: AppKey[_T], default: _U) -> Union[_T, _U]:
...
def get(self, key: AppKey[_T], default: _U) -> Union[_T, _U]: ...

@overload
def get(self, key: str, default: Any = ...) -> Any:
...
def get(self, key: str, default: Any = ...) -> Any: ...

def get(self, key: Union[str, AppKey[_T]], default: Any = None) -> Any:
return self._state.get(key, default)
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class FileField:
qdtext=_QDTEXT, quoted_pair=_QUOTED_PAIR
)

_FORWARDED_PAIR: Final[
str
] = r"({token})=({token}|{quoted_string})(:\d{{1,4}})?".format(
token=_TOKEN, quoted_string=_QUOTED_STRING
_FORWARDED_PAIR: Final[str] = (
r"({token})=({token}|{quoted_string})(:\d{{1,4}})?".format(
token=_TOKEN, quoted_string=_QUOTED_STRING
)
)

_QUOTED_PAIR_REPLACE_RE: Final[Pattern[str]] = re.compile(r"\\([\t !-~])")
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def enable_compression(
) -> None:
"""Enables response compression encoding."""
# Backwards compatibility for when force was a bool <0.17.
if type(force) == bool:
if isinstance(force, bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are integers boolean? I remember there were some corner cases a around this. Or perhaps this was done with performance in mind.. FWIW this is not just a formatting change. It checks for subclasses too. Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are integers boolean

No, other way round. bool is subclass of int, so this shoudn't make any difference. It's also ancient code that could be removed at this point anyway..

force = ContentCoding.deflate if force else ContentCoding.identity
warnings.warn(
"Using boolean for force is deprecated #3318", DeprecationWarning
Expand Down Expand Up @@ -674,7 +674,7 @@ def body(self, body: bytes) -> None:

# copy payload headers
if body.headers:
for (key, value) in body.headers.items():
for key, value in body.headers.items():
if key not in headers:
headers[key] = value

Expand Down
6 changes: 2 additions & 4 deletions aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@ def __repr__(self) -> str:
return f"<RouteTableDef count={len(self._items)}>"

@overload
def __getitem__(self, index: int) -> AbstractRouteDef:
...
def __getitem__(self, index: int) -> AbstractRouteDef: ...

@overload
def __getitem__(self, index: slice) -> List[AbstractRouteDef]:
...
def __getitem__(self, index: slice) -> List[AbstractRouteDef]: ...

def __getitem__(self, index): # type: ignore[no-untyped-def]
return self._items[index]
Expand Down
1 change: 1 addition & 0 deletions aiohttp/web_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Low level HTTP server."""

import asyncio
from typing import Any, Awaitable, Callable, Dict, List, Optional # noqa

Expand Down
16 changes: 10 additions & 6 deletions aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ def _reset_heartbeat(self) -> None:
self._send_heartbeat,
self._heartbeat,
self._loop,
timeout_ceil_threshold=self._req._protocol._timeout_ceil_threshold
if self._req is not None
else 5,
timeout_ceil_threshold=(
self._req._protocol._timeout_ceil_threshold
if self._req is not None
else 5
),
)

def _send_heartbeat(self) -> None:
Expand All @@ -132,9 +134,11 @@ def _send_heartbeat(self) -> None:
self._pong_not_received,
self._pong_heartbeat,
self._loop,
timeout_ceil_threshold=self._req._protocol._timeout_ceil_threshold
if self._req is not None
else 5,
timeout_ceil_threshold=(
self._req._protocol._timeout_ceil_threshold
if self._req is not None
else 5
),
)

def _pong_not_received(self) -> None:
Expand Down
17 changes: 10 additions & 7 deletions tests/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* https://github.com/pytest-dev/pytest/blob/d18c75b/testing/test_meta.py
* https://twitter.com/codewithanthony/status/1229445110510735361
"""

import os
import pkgutil
import socket
Expand All @@ -30,14 +31,16 @@ def _mark_aiohttp_worker_for_skipping(
importables: List[str],
) -> List[Union[str, "ParameterSet"]]:
return [
pytest.param(
importable,
marks=pytest.mark.skipif(
not hasattr(socket, "AF_UNIX"), reason="It's a UNIX-only module"
),
(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which linter wanted this? It seems like too much..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this one just black formatting? I didn't touch this one.

pytest.param(
importable,
marks=pytest.mark.skipif(
not hasattr(socket, "AF_UNIX"), reason="It's a UNIX-only module"
),
)
if importable == "aiohttp.worker"
else importable
)
if importable == "aiohttp.worker"
else importable
for importable in importables
]

Expand Down