Skip to content

Commit

Permalink
Update .pre-commit-config.yaml (#8384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Apr 25, 2024
1 parent a9200db commit 3e0b88d
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 140 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
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
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
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
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
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
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
@@ -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
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
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
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
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):
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
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
@@ -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
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
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"
),
(
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

0 comments on commit 3e0b88d

Please sign in to comment.