Skip to content

Commit 838252c

Browse files
committed
Fixed linting/formatting
1 parent d4651f3 commit 838252c

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

httpcore/_async/connection_pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3-
from collections.abc import AsyncGenerator
4-
53
import ssl
64
import sys
75
import types
86
import typing
7+
from collections.abc import AsyncGenerator
98

109
from .._backends.auto import AutoBackend
1110
from .._backends.base import SOCKET_OPTION, AsyncNetworkBackend
@@ -17,8 +16,9 @@
1716
from .interfaces import AsyncConnectionInterface, AsyncRequestInterface
1817

1918
if typing.TYPE_CHECKING:
20-
from .http11 import HTTP11ConnectionByteStream
2119
from .http2 import HTTP2ConnectionByteStream
20+
from .http11 import HTTP11ConnectionByteStream
21+
2222

2323
class AsyncPoolRequest:
2424
def __init__(self, request: Request) -> None:

httpcore/_async/http11.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from .._models import Origin, Request, Response
2222
from .._synchronization import AsyncLock, AsyncShieldCancellation
2323
from .._trace import Trace
24-
from .interfaces import AsyncConnectionInterface
2524
from .._utils import aclosing
25+
from .interfaces import AsyncConnectionInterface
2626

2727
logger = logging.getLogger("httpcore.http11")
2828

@@ -331,7 +331,9 @@ async def __aiter__(self) -> AsyncGenerator[bytes]:
331331
kwargs = {"request": self._request}
332332
try:
333333
async with Trace("receive_response_body", logger, self._request, kwargs):
334-
async with aclosing(self._connection._receive_response_body(**kwargs)) as body:
334+
async with aclosing(
335+
self._connection._receive_response_body(**kwargs)
336+
) as body:
335337
async for chunk in body:
336338
yield chunk
337339
except BaseException as exc:

httpcore/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
if sys.version_info >= (3, 10):
88
from contextlib import aclosing as aclosing
99
else:
10+
from contextlib import AbstractAsyncContextManager
11+
1012
class aclosing(AbstractAsyncContextManager):
1113
def __init__(self, thing):
1214
self.thing = thing

scripts/unasync.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,36 @@
55
from pprint import pprint
66

77
SUBS = [
8-
('from .._backends.auto import AutoBackend', 'from .._backends.sync import SyncBackend'),
9-
('import trio as concurrency', 'from tests import concurrency'),
10-
('AsyncIterator', 'Iterator'),
11-
('Async([A-Z][A-Za-z0-9_]*)', r'\2'),
12-
('async def', 'def'),
13-
('async with', 'with'),
14-
('async for', 'for'),
15-
('await ', ''),
16-
('handle_async_request', 'handle_request'),
17-
('aclose', 'close'),
18-
('aiter_stream', 'iter_stream'),
19-
('aread', 'read'),
20-
('asynccontextmanager', 'contextmanager'),
21-
('__aenter__', '__enter__'),
22-
('__aexit__', '__exit__'),
23-
('__aiter__', '__iter__'),
24-
('@pytest.mark.anyio', ''),
25-
('@pytest.mark.trio', ''),
26-
('AutoBackend', 'SyncBackend'),
8+
(
9+
"from .._backends.auto import AutoBackend",
10+
"from .._backends.sync import SyncBackend",
11+
),
12+
("import trio as concurrency", "from tests import concurrency"),
13+
("AsyncIterator", "Iterator"),
14+
("Async([A-Z][A-Za-z0-9_]*)", r"\2"),
15+
("async def", "def"),
16+
("async with", "with"),
17+
("async for", "for"),
18+
("await ", ""),
19+
("handle_async_request", "handle_request"),
20+
("aclose", "close"),
21+
("aiter_stream", "iter_stream"),
22+
("aread", "read"),
23+
("asynccontextmanager", "contextmanager"),
24+
("__aenter__", "__enter__"),
25+
("__aexit__", "__exit__"),
26+
("__aiter__", "__iter__"),
27+
("@pytest.mark.anyio", ""),
28+
("@pytest.mark.trio", ""),
29+
("AutoBackend", "SyncBackend"),
2730
]
2831
COMPILED_SUBS = [
29-
(re.compile(r'(^|\b)' + regex + r'($|\b)'), repl)
30-
for regex, repl in SUBS
32+
(re.compile(r"(^|\b)" + regex + r"($|\b)"), repl) for regex, repl in SUBS
3133
]
3234

3335
USED_SUBS = set()
3436

37+
3538
def unasync_line(line):
3639
for index, (regex, repl) in enumerate(COMPILED_SUBS):
3740
old_line = line
@@ -55,30 +58,30 @@ def unasync_file_check(in_path, out_path):
5558
for in_line, out_line in zip(in_file.readlines(), out_file.readlines()):
5659
expected = unasync_line(in_line)
5760
if out_line != expected:
58-
print(f'unasync mismatch between {in_path!r} and {out_path!r}')
59-
print(f'Async code: {in_line!r}')
60-
print(f'Expected sync code: {expected!r}')
61-
print(f'Actual sync code: {out_line!r}')
61+
print(f"unasync mismatch between {in_path!r} and {out_path!r}")
62+
print(f"Async code: {in_line!r}")
63+
print(f"Expected sync code: {expected!r}")
64+
print(f"Actual sync code: {out_line!r}")
6265
sys.exit(1)
6366

6467

6568
def unasync_dir(in_dir, out_dir, check_only=False):
6669
for dirpath, dirnames, filenames in os.walk(in_dir):
6770
for filename in filenames:
68-
if not filename.endswith('.py'):
71+
if not filename.endswith(".py"):
6972
continue
7073
rel_dir = os.path.relpath(dirpath, in_dir)
7174
in_path = os.path.normpath(os.path.join(in_dir, rel_dir, filename))
7275
out_path = os.path.normpath(os.path.join(out_dir, rel_dir, filename))
73-
print(in_path, '->', out_path)
76+
print(in_path, "->", out_path)
7477
if check_only:
7578
unasync_file_check(in_path, out_path)
7679
else:
7780
unasync_file(in_path, out_path)
7881

7982

8083
def main():
81-
check_only = '--check' in sys.argv
84+
check_only = "--check" in sys.argv
8285
unasync_dir("httpcore/_async", "httpcore/_sync", check_only=check_only)
8386
unasync_dir("tests/_async", "tests/_sync", check_only=check_only)
8487

@@ -87,8 +90,8 @@ def main():
8790

8891
print("These patterns were not used:")
8992
pprint(unused_subs)
90-
exit(1)
91-
93+
exit(1)
94+
9295

93-
if __name__ == '__main__':
96+
if __name__ == "__main__":
9497
main()

0 commit comments

Comments
 (0)