Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 13, 2021
1 parent 01fc3a0 commit 975e0a3
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -593,7 +593,7 @@ def call_later(


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

def __init__(
self, loop: asyncio.AbstractEventLoop, timeout: Optional[float]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
4 changes: 2 additions & 2 deletions aiohttp/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions aiohttp/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,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_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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
2 changes: 1 addition & 1 deletion examples/legacy/tcp_protocol_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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 @@ -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="/")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


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 @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ async def handler(request):

def test_repr_for_application() -> None:
app = web.Application()
assert "<Application 0x{:x}>".format(id(app)) == repr(app)
assert f"<Application 0x{id(app):x}>" == repr(app)


async def test_expect_default_handler_unknown(aiohttp_client: Any) -> None:
Expand Down
8 changes: 4 additions & 4 deletions tools/bench-asyncio-write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")):
Expand All @@ -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 = [
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 975e0a3

Please sign in to comment.