From 68d8967b939e5a08d152dcd463744253623bc77f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 16:23:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- aiohttp/client.py | 2 +- aiohttp/client_exceptions.py | 2 +- aiohttp/connector.py | 2 +- aiohttp/cookiejar.py | 2 +- aiohttp/helpers.py | 6 ++--- aiohttp/locks.py | 2 +- aiohttp/multipart.py | 2 +- aiohttp/payload.py | 4 +-- aiohttp/streams.py | 2 +- aiohttp/tracing.py | 34 +++++++++++++------------- aiohttp/web_app.py | 2 +- aiohttp/web_exceptions.py | 2 +- aiohttp/web_routedef.py | 2 +- examples/legacy/tcp_protocol_parser.py | 2 +- tests/test_client_functional.py | 2 +- tests/test_helpers.py | 2 +- tests/test_http_parser.py | 2 +- tests/test_resolver.py | 2 +- tests/test_web_functional.py | 2 +- tools/bench-asyncio-write.py | 8 +++--- 20 files changed, 42 insertions(+), 42 deletions(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index 1aab4829ffe..c14a682a404 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -263,7 +263,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() diff --git a/aiohttp/client_exceptions.py b/aiohttp/client_exceptions.py index 808c1cc614e..5f2f8958e84 100644 --- a/aiohttp/client_exceptions.py +++ b/aiohttp/client_exceptions.py @@ -85,7 +85,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})" class ContentTypeError(ClientResponseError): diff --git a/aiohttp/connector.py b/aiohttp/connector.py index 58c528de6fb..ab5124966b5 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -150,7 +150,7 @@ def closed(self) -> bool: class _TransportPlaceholder: - """ placeholder for BaseConnector.connect function """ + """placeholder for BaseConnector.connect function""" def __init__(self, loop: asyncio.AbstractEventLoop) -> None: fut = loop.create_future() diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py index 8d0a1edf49b..ef32f5faa53 100644 --- a/aiohttp/cookiejar.py +++ b/aiohttp/cookiejar.py @@ -320,7 +320,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: diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 418de0f6f9a..be76e0cec62 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -499,7 +499,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) @@ -593,7 +593,7 @@ def call_later( class TimeoutHandle: - """ Timeout handle """ + """Timeout handle""" def __init__( self, loop: asyncio.AbstractEventLoop, timeout: Optional[float] @@ -656,7 +656,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 diff --git a/aiohttp/locks.py b/aiohttp/locks.py index ce5b9c6f731..8ea99d70ce8 100644 --- a/aiohttp/locks.py +++ b/aiohttp/locks.py @@ -40,6 +40,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() diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index b5e78c835e6..b2c67baa45d 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -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("\\/")) diff --git a/aiohttp/payload.py b/aiohttp/payload.py index b88da2cd8ed..2afeadd5853 100644 --- a/aiohttp/payload.py +++ b/aiohttp/payload.py @@ -222,7 +222,7 @@ 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)) + f"value argument must be byte-ish, not {type(value)!r}" ) if "content_type" not in kwargs: @@ -251,7 +251,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, diff --git a/aiohttp/streams.py b/aiohttp/streams.py index a077b81b82d..185f46ecdab 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -480,7 +480,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: diff --git a/aiohttp/tracing.py b/aiohttp/tracing.py index 435bf3ddf73..7ffe93f8507 100644 --- a/aiohttp/tracing.py +++ b/aiohttp/tracing.py @@ -107,7 +107,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: @@ -219,7 +219,7 @@ def on_request_headers_sent( @dataclasses.dataclass(frozen=True) class TraceRequestStartParams: - """ Parameters sent by the `on_request_start` signal""" + """Parameters sent by the `on_request_start` signal""" method: str url: URL @@ -228,7 +228,7 @@ class TraceRequestStartParams: @dataclasses.dataclass(frozen=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 @@ -237,7 +237,7 @@ class TraceRequestChunkSentParams: @dataclasses.dataclass(frozen=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 @@ -246,7 +246,7 @@ class TraceResponseChunkReceivedParams: @dataclasses.dataclass(frozen=True) class TraceRequestEndParams: - """ Parameters sent by the `on_request_end` signal""" + """Parameters sent by the `on_request_end` signal""" method: str url: URL @@ -256,7 +256,7 @@ class TraceRequestEndParams: @dataclasses.dataclass(frozen=True) class TraceRequestExceptionParams: - """ Parameters sent by the `on_request_exception` signal""" + """Parameters sent by the `on_request_exception` signal""" method: str url: URL @@ -266,7 +266,7 @@ class TraceRequestExceptionParams: @dataclasses.dataclass(frozen=True) class TraceRequestRedirectParams: - """ Parameters sent by the `on_request_redirect` signal""" + """Parameters sent by the `on_request_redirect` signal""" method: str url: URL @@ -276,60 +276,60 @@ class TraceRequestRedirectParams: @dataclasses.dataclass(frozen=True) class TraceConnectionQueuedStartParams: - """ Parameters sent by the `on_connection_queued_start` signal""" + """Parameters sent by the `on_connection_queued_start` signal""" @dataclasses.dataclass(frozen=True) class TraceConnectionQueuedEndParams: - """ Parameters sent by the `on_connection_queued_end` signal""" + """Parameters sent by the `on_connection_queued_end` signal""" @dataclasses.dataclass(frozen=True) class TraceConnectionCreateStartParams: - """ Parameters sent by the `on_connection_create_start` signal""" + """Parameters sent by the `on_connection_create_start` signal""" @dataclasses.dataclass(frozen=True) class TraceConnectionCreateEndParams: - """ Parameters sent by the `on_connection_create_end` signal""" + """Parameters sent by the `on_connection_create_end` signal""" @dataclasses.dataclass(frozen=True) class TraceConnectionReuseconnParams: - """ Parameters sent by the `on_connection_reuseconn` signal""" + """Parameters sent by the `on_connection_reuseconn` signal""" @dataclasses.dataclass(frozen=True) class TraceDnsResolveHostStartParams: - """ Parameters sent by the `on_dns_resolvehost_start` signal""" + """Parameters sent by the `on_dns_resolvehost_start` signal""" host: str @dataclasses.dataclass(frozen=True) class TraceDnsResolveHostEndParams: - """ Parameters sent by the `on_dns_resolvehost_end` signal""" + """Parameters sent by the `on_dns_resolvehost_end` signal""" host: str @dataclasses.dataclass(frozen=True) class TraceDnsCacheHitParams: - """ Parameters sent by the `on_dns_cache_hit` signal""" + """Parameters sent by the `on_dns_cache_hit` signal""" host: str @dataclasses.dataclass(frozen=True) class TraceDnsCacheMissParams: - """ Parameters sent by the `on_dns_cache_miss` signal""" + """Parameters sent by the `on_dns_cache_miss` signal""" host: str @dataclasses.dataclass(frozen=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 diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index d78d603d38b..999ea9ceb95 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -359,7 +359,7 @@ def __call__(self) -> "Application": return self def __repr__(self) -> str: - return "".format(id(self)) + return f"" def __bool__(self) -> bool: return True diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index 28fe0aafcc5..b22995f39ac 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -431,7 +431,7 @@ def __init__( super().__init__( headers=headers, reason=reason, text=text, content_type=content_type ) - self.headers["Link"] = '<{}>; rel="blocked-by"'.format(str(link)) + self.headers["Link"] = f'<{str(link)}>; rel="blocked-by"' self._link = URL(link) @property diff --git a/aiohttp/web_routedef.py b/aiohttp/web_routedef.py index 787d9cbdeca..a22c3df4d0e 100644 --- a/aiohttp/web_routedef.py +++ b/aiohttp/web_routedef.py @@ -158,7 +158,7 @@ def __init__(self) -> None: self._items = [] # type: List[AbstractRouteDef] def __repr__(self) -> str: - return "".format(len(self._items)) + return f"" @overload def __getitem__(self, index: int) -> AbstractRouteDef: diff --git a/examples/legacy/tcp_protocol_parser.py b/examples/legacy/tcp_protocol_parser.py index ca49db7d8f9..1ef972758e5 100755 --- a/examples/legacy/tcp_protocol_parser.py +++ b/examples/legacy/tcp_protocol_parser.py @@ -60,7 +60,7 @@ def stop(self): self.transport.write(b"stop:\r\n") def send_text(self, text): - self.transport.write(f"text:{text.strip()}\r\n".encode("utf-8")) + self.transport.write(f"text:{text.strip()}\r\n".encode()) class EchoServer(asyncio.Protocol): diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 79e007537cd..b3a01957bf7 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -996,7 +996,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="/") diff --git a/tests/test_helpers.py b/tests/test_helpers.py index e9b99e12170..8f029f15666 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -172,7 +172,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 diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index 172d7bc30cf..80913ae4360 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -978,7 +978,7 @@ async def test_http_payload_parser_deflate(self, stream: Any) -> None: assert out.is_eof() async def test_http_payload_parser_deflate_no_hdrs(self, stream: Any) -> 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" diff --git a/tests/test_resolver.py b/tests/test_resolver.py index b74764525c2..d65479f6fa1 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -44,7 +44,7 @@ async def fake(*args: Any, **kwargs: Any) -> List[Any]: 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 diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 6a3b7a3fee5..c54db16bdc2 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -445,7 +445,7 @@ async def handler(request): def test_repr_for_application() -> None: app = web.Application() - assert "".format(id(app)) == repr(app) + assert f"" == repr(app) async def test_expect_default_handler_unknown(aiohttp_client: Any) -> None: diff --git a/tools/bench-asyncio-write.py b/tools/bench-asyncio-write.py index 6b34782d909..e94a76eaaaf 100644 --- a/tools/bench-asyncio-write.py +++ b/tools/bench-asyncio-write.py @@ -38,7 +38,7 @@ def fm_size(s, _fms=("", "K", "M", "G")): while s >= 1024: s /= 1024 i += 1 - return "{:.0f}{}B".format(s, _fms[i]) + return f"{s:.0f}{_fms[i]}B" def fm_time(s, _fms=("", "m", "µ", "n")): @@ -48,7 +48,7 @@ def fm_time(s, _fms=("", "m", "µ", "n")): while s < 1: s *= 1000 i += 1 - return "{:.2f}{}s".format(s, _fms[i]) + return f"{s:.2f}{_fms[i]}s" writes = [ @@ -74,7 +74,7 @@ def fm_time(s, _fms=("", "m", "µ", "n")): jobs = [ ( # always start with a 256B headers chunk - "{} / {}".format(fm_size(sum(j) if j else 0), len(j)), + f"{fm_size(sum(j) if j else 0)} / {len(j)}", [b"0" * s for s in [256] + list(j)], ) for j in bodies @@ -111,7 +111,7 @@ async def bench(job_title, w, body, base=None): fm_time(mean), fm_time(sd), str(it), - "{:.2%}".format(mean / base - 1) if base is not None else "", + f"{mean / base - 1:.2%}" if base is not None else "", ) ) return mean