Skip to content

Commit

Permalink
Update pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 1, 2021
1 parent 9dbebc0 commit 252e1d6
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 58 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ repos:
entry: ./tools/check_changes.py
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v3.3.0'
rev: 'v4.0.1'
hooks:
- id: check-merge-conflict
- repo: https://github.com/asottile/yesqa
rev: v1.2.2
rev: v1.3.0
hooks:
- id: yesqa
- repo: https://github.com/pre-commit/mirrors-isort
rev: 'v5.6.4'
- repo: https://github.com/PyCQA/isort
rev: '5.9.3'
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '20.8b1'
rev: '21.10b0'
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v3.3.0'
rev: 'v4.0.1'
hooks:
- id: end-of-file-fixer
exclude: >-
Expand Down Expand Up @@ -71,17 +71,17 @@ repos:
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.7.3'
rev: 'v2.29.0'
hooks:
- id: pyupgrade
args: ['--py36-plus']
- repo: https://gitlab.com/pycqa/flake8
rev: '3.8.4'
- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
hooks:
- id: flake8
exclude: "^docs/"
- repo: git://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.0
rev: v1.0.1
hooks:
- id: rst-linter
files: >-
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def __init__(
real_headers = CIMultiDict()
self._default_headers = real_headers # type: CIMultiDict[str]
if skip_auto_headers is not None:
self._skip_auto_headers = frozenset([istr(i) for i in skip_auto_headers])
self._skip_auto_headers = frozenset(istr(i) for i in skip_auto_headers)
else:
self._skip_auto_headers = frozenset()

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __repr__(self) -> str:
args += f", message={self.message!r}"
if self.headers is not None:
args += f", headers={self.headers!r}"
return "{}({})".format(type(self).__name__, args)
return f"{type(self).__name__}({args})"

@property
def code(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def closed(self) -> bool:


class _TransportPlaceholder:
""" placeholder for BaseConnector.connect function """
"""placeholder for BaseConnector.connect function"""

def close(self) -> None:
pass
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _parse_date(cls, date_str: str) -> Optional[datetime.datetime]:
time_match = cls.DATE_HMS_TIME_RE.match(token)
if time_match:
found_time = True
hour, minute, second = [int(s) for s in time_match.groups()]
hour, minute, second = (int(s) for s in time_match.groups())
continue

if not found_day:
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def _is_ip_address(
elif isinstance(host, (bytes, bytearray, memoryview)):
return bool(regexb.match(host))
else:
raise TypeError("{} [{}] is not a str or bytes".format(host, type(host)))
raise TypeError(f"{host} [{type(host)}] is not a str or bytes")


is_ipv4_address = functools.partial(_is_ip_address, _ipv4_regex, _ipv4_regexb)
Expand Down Expand Up @@ -621,7 +621,7 @@ def call_later(


class TimeoutHandle:
""" Timeout handle """
"""Timeout handle"""

def __init__(
self, loop: asyncio.AbstractEventLoop, timeout: Optional[float]
Expand Down Expand Up @@ -684,7 +684,7 @@ def __exit__(


class TimerContext(BaseTimerContext):
""" Low resolution timeout context manager """
"""Low resolution timeout context manager"""

def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
self._loop = loop
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ async def wait(self) -> Any:
return val

def cancel(self) -> None:
""" Cancel all waiters """
"""Cancel all waiters"""
for waiter in self._waiters:
waiter.cancel()
2 changes: 1 addition & 1 deletion aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def unescape(text: str, *, chars: str = "".join(map(re.escape, CHAR))) -> str:
elif parts:
# maybe just ; in filename, in any case this is just
# one case fix, for proper fix we need to redesign parser
_value = "{};{}".format(value, parts[0])
_value = f"{value};{parts[0]}"
if is_quoted(_value):
parts.pop(0)
value = unescape(_value[1:-1].lstrip("\\/"))
Expand Down
7 changes: 2 additions & 5 deletions aiohttp/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Dict,
Iterable,
Optional,
Text,
TextIO,
Tuple,
Type,
Expand Down Expand Up @@ -219,9 +218,7 @@ async def write(self, writer: AbstractStreamWriter) -> None:
class BytesPayload(Payload):
def __init__(self, value: ByteString, *args: Any, **kwargs: Any) -> None:
if not isinstance(value, (bytes, bytearray, memoryview)):
raise TypeError(
"value argument must be byte-ish, not {!r}".format(type(value))
)
raise TypeError(f"value argument must be byte-ish, not {type(value)!r}")

if "content_type" not in kwargs:
kwargs["content_type"] = "application/octet-stream"
Expand Down Expand Up @@ -253,7 +250,7 @@ async def write(self, writer: AbstractStreamWriter) -> None:
class StringPayload(BytesPayload):
def __init__(
self,
value: Text,
value: str,
*args: Any,
encoding: Optional[str] = None,
content_type: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def _read_nowait_chunk(self, n: int) -> bytes:
return data

def _read_nowait(self, n: int) -> bytes:
""" Read not more than n bytes, or whole buffer if n == -1 """
"""Read not more than n bytes, or whole buffer if n == -1"""
chunks = []

while self._buffer:
Expand Down
34 changes: 17 additions & 17 deletions aiohttp/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
def trace_config_ctx(
self, trace_request_ctx: Optional[SimpleNamespace] = None
) -> SimpleNamespace:
""" Return a new trace_config_ctx instance """
"""Return a new trace_config_ctx instance"""
return self._trace_config_ctx_factory(trace_request_ctx=trace_request_ctx)

def freeze(self) -> None:
Expand Down Expand Up @@ -218,7 +218,7 @@ def on_request_headers_sent(

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestStartParams:
""" Parameters sent by the `on_request_start` signal"""
"""Parameters sent by the `on_request_start` signal"""

method: str
url: URL
Expand All @@ -227,7 +227,7 @@ class TraceRequestStartParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestChunkSentParams:
""" Parameters sent by the `on_request_chunk_sent` signal"""
"""Parameters sent by the `on_request_chunk_sent` signal"""

method: str
url: URL
Expand All @@ -236,7 +236,7 @@ class TraceRequestChunkSentParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceResponseChunkReceivedParams:
""" Parameters sent by the `on_response_chunk_received` signal"""
"""Parameters sent by the `on_response_chunk_received` signal"""

method: str
url: URL
Expand All @@ -245,7 +245,7 @@ class TraceResponseChunkReceivedParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestEndParams:
""" Parameters sent by the `on_request_end` signal"""
"""Parameters sent by the `on_request_end` signal"""

method: str
url: URL
Expand All @@ -255,7 +255,7 @@ class TraceRequestEndParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestExceptionParams:
""" Parameters sent by the `on_request_exception` signal"""
"""Parameters sent by the `on_request_exception` signal"""

method: str
url: URL
Expand All @@ -265,7 +265,7 @@ class TraceRequestExceptionParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestRedirectParams:
""" Parameters sent by the `on_request_redirect` signal"""
"""Parameters sent by the `on_request_redirect` signal"""

method: str
url: URL
Expand All @@ -275,60 +275,60 @@ class TraceRequestRedirectParams:

@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceConnectionQueuedStartParams:
""" Parameters sent by the `on_connection_queued_start` signal"""
"""Parameters sent by the `on_connection_queued_start` signal"""


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceConnectionQueuedEndParams:
""" Parameters sent by the `on_connection_queued_end` signal"""
"""Parameters sent by the `on_connection_queued_end` signal"""


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceConnectionCreateStartParams:
""" Parameters sent by the `on_connection_create_start` signal"""
"""Parameters sent by the `on_connection_create_start` signal"""


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceConnectionCreateEndParams:
""" Parameters sent by the `on_connection_create_end` signal"""
"""Parameters sent by the `on_connection_create_end` signal"""


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceConnectionReuseconnParams:
""" Parameters sent by the `on_connection_reuseconn` signal"""
"""Parameters sent by the `on_connection_reuseconn` signal"""


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceDnsResolveHostStartParams:
""" Parameters sent by the `on_dns_resolvehost_start` signal"""
"""Parameters sent by the `on_dns_resolvehost_start` signal"""

host: str


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceDnsResolveHostEndParams:
""" Parameters sent by the `on_dns_resolvehost_end` signal"""
"""Parameters sent by the `on_dns_resolvehost_end` signal"""

host: str


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceDnsCacheHitParams:
""" Parameters sent by the `on_dns_cache_hit` signal"""
"""Parameters sent by the `on_dns_cache_hit` signal"""

host: str


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceDnsCacheMissParams:
""" Parameters sent by the `on_dns_cache_miss` signal"""
"""Parameters sent by the `on_dns_cache_miss` signal"""

host: str


@attr.s(auto_attribs=True, frozen=True, slots=True)
class TraceRequestHeadersSentParams:
""" Parameters sent by the `on_request_headers_sent` signal"""
"""Parameters sent by the `on_request_headers_sent` signal"""

method: str
url: URL
Expand Down
6 changes: 1 addition & 5 deletions aiohttp/typedefs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import pathlib
import sys
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -62,7 +61,4 @@

Handler = Callable[["Request"], Awaitable["StreamResponse"]]

if sys.version_info >= (3, 6):
PathLike = Union[str, "os.PathLike[str]"]
else:
PathLike = Union[str, pathlib.PurePath]
PathLike = Union[str, "os.PathLike[str]"]
3 changes: 1 addition & 2 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@ def run_app(
finally:
_cancel_tasks({main_task}, loop)
_cancel_tasks(all_tasks(loop), loop)
if sys.version_info >= (3, 6): # don't use PY_36 to pass mypy
loop.run_until_complete(loop.shutdown_asyncgens())
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()


Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def __call__(self) -> "Application":
return self

def __repr__(self) -> str:
return "<Application 0x{:x}>".format(id(self))
return f"<Application 0x{id(self):x}>"

def __bool__(self) -> bool:
return True
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(self) -> None:
self._items = [] # type: List[AbstractRouteDef]

def __repr__(self) -> str:
return "<RouteTableDef count={}>".format(len(self._items))
return f"<RouteTableDef count={len(self._items)}>"

@overload
def __getitem__(self, index: int) -> AbstractRouteDef:
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def run(self) -> None:
self.loop.run_until_complete(self._task)
except Exception:
self.log.exception("Exception in gunicorn worker")
if sys.version_info >= (3, 6):
self.loop.run_until_complete(self.loop.shutdown_asyncgens())
self.loop.run_until_complete(self.loop.shutdown_asyncgens())
self.loop.close()

sys.exit(self.exit_code)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ async def handler(request):
async def redirect(request):
count = int(request.match_info["count"])
if count:
raise web.HTTPFound(location="/redirect/{}".format(count - 1))
raise web.HTTPFound(location=f"/redirect/{count - 1}")
else:
raise web.HTTPFound(location="/")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_basic_auth_decode_invalid_credentials() -> None:
),
)
def test_basic_auth_decode_blank_username(credentials, expected_auth) -> None:
header = "Basic {}".format(base64.b64encode(credentials.encode()).decode())
header = f"Basic {base64.b64encode(credentials.encode()).decode()}"
assert helpers.BasicAuth.decode(header) == expected_auth


Expand Down
2 changes: 1 addition & 1 deletion tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ async def test_http_payload_parser_deflate(self, stream) -> None:
assert out.is_eof()

async def test_http_payload_parser_deflate_no_hdrs(self, stream) -> None:
"""Tests incorrectly formed data (no zlib headers) """
"""Tests incorrectly formed data (no zlib headers)"""

# c=compressobj(wbits=-15); b''.join([c.compress(b'data'), c.flush()])
COMPRESSED = b"KI,I\x04\x00"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def fake(*args, **kwargs):
if not hosts:
raise socket.gaierror

return list([(None, None, None, None, [h, 0]) for h in hosts])
return list((None, None, None, None, [h, 0]) for h in hosts)

return fake

Expand Down

0 comments on commit 252e1d6

Please sign in to comment.