Skip to content

Commit b71fe2d

Browse files
igor.stulikovigor.stulikov
igor.stulikov
authored and
igor.stulikov
committed
Fix linters (encode#550)
1 parent e061990 commit b71fe2d

File tree

5 files changed

+50
-33
lines changed

5 files changed

+50
-33
lines changed

httpcore/_async/connection_pool.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ async def _attempt_to_acquire_connection(self, status: RequestStatus) -> bool:
174174

175175
# Attempt to close CONNECTING connections that no one needs
176176
if self._is_pool_full:
177-
for idx, connection in enumerate(self._pool): # Try to check old connections first
177+
for idx, connection in enumerate(
178+
self._pool
179+
): # Try to check old connections first
178180
if not connection.is_connecting():
179181
continue
180182
for req_status in self._requests:

httpcore/_sync/connection_pool.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def _attempt_to_acquire_connection(self, status: RequestStatus) -> bool:
174174

175175
# Attempt to close CONNECTING connections that no one needs
176176
if self._is_pool_full:
177-
for idx, connection in enumerate(self._pool): # Try to check old connections first
177+
for idx, connection in enumerate(
178+
self._pool
179+
): # Try to check old connections first
178180
if not connection.is_connecting():
179181
continue
180182
for req_status in self._requests:

httpcore/backends/mock.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import anyio
77

88
from httpcore import ReadTimeout
9-
from .base import AsyncNetworkBackend, AsyncNetworkStream, NetworkBackend, NetworkStream
9+
1010
from .._exceptions import ReadError
11+
from .base import AsyncNetworkBackend, AsyncNetworkStream, NetworkBackend, NetworkStream
1112

1213

1314
class MockSSLObject:
@@ -59,10 +60,10 @@ def read(self, max_bytes: int, timeout: Optional[float] = None) -> bytes:
5960

6061
class MockBackend(NetworkBackend):
6162
def __init__(
62-
self,
63-
buffer: typing.List[bytes],
64-
http2: bool = False,
65-
resp_stream_cls: Optional[Type[NetworkStream]] = None,
63+
self,
64+
buffer: typing.List[bytes],
65+
http2: bool = False,
66+
resp_stream_cls: Optional[Type[MockStream]] = None,
6667
) -> None:
6768
self._buffer = buffer
6869
self._http2 = http2
@@ -127,14 +128,16 @@ async def read(self, max_bytes: int, timeout: Optional[float] = None) -> bytes:
127128

128129
class AsyncMockBackend(AsyncNetworkBackend):
129130
def __init__(
130-
self,
131-
buffer: typing.List[bytes],
132-
http2: bool = False,
133-
resp_stream_cls: Optional[Type[AsyncNetworkStream]] = None,
131+
self,
132+
buffer: typing.List[bytes],
133+
http2: bool = False,
134+
resp_stream_cls: Optional[Type[AsyncMockStream]] = None,
134135
) -> None:
135136
self._buffer = buffer
136137
self._http2 = http2
137-
self._resp_stream_cls: Type[AsyncMockStream] = resp_stream_cls or AsyncMockStream
138+
self._resp_stream_cls: Type[AsyncMockStream] = (
139+
resp_stream_cls or AsyncMockStream
140+
)
138141

139142
async def connect_tcp(
140143
self,

tests/_async/test_connection_pool.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
AsyncConnectionPool,
99
ConnectError,
1010
PoolTimeout,
11-
ReadTimeout,
1211
ReadError,
12+
ReadTimeout,
1313
UnsupportedProtocol,
1414
)
1515
from httpcore.backends.base import AsyncNetworkStream
16-
from httpcore.backends.mock import AsyncMockBackend, AsyncHangingStream
16+
from httpcore.backends.mock import AsyncHangingStream, AsyncMockBackend
1717

1818

1919
@pytest.mark.anyio
@@ -511,19 +511,21 @@ async def test_pool_under_load():
511511
"""
512512
network_backend = AsyncMockBackend([], resp_stream_cls=AsyncHangingStream)
513513

514-
async def fetch(_pool: AsyncConnectionPool, *exceptions: Type[BaseException]):
514+
async def fetch(
515+
_pool: AsyncConnectionPool, *exceptions: Type[BaseException]
516+
) -> None:
515517
with contextlib.suppress(*exceptions):
516518
async with pool.stream(
517-
"GET",
518-
"http://a.com/",
519-
extensions={
520-
"timeout": {
521-
"connect": 0.1,
522-
"read": 0.1,
523-
"pool": 0.1,
524-
"write": 0.1,
525-
},
519+
"GET",
520+
"http://a.com/",
521+
extensions={
522+
"timeout": {
523+
"connect": 0.1,
524+
"read": 0.1,
525+
"pool": 0.1,
526+
"write": 0.1,
526527
},
528+
},
527529
) as response:
528530
await response.aread()
529531

@@ -537,11 +539,12 @@ async def fetch(_pool: AsyncConnectionPool, *exceptions: Type[BaseException]):
537539
nursery.start_soon(fetch, pool, PoolTimeout, ReadTimeout)
538540
if pool.connections: # There is one connection in pool in "CONNECTING" state
539541
assert pool.connections[0].is_connecting()
540-
with pytest.raises(ReadTimeout): # ReadTimeout indicates that connection could be retrieved
542+
with pytest.raises(
543+
ReadTimeout
544+
): # ReadTimeout indicates that connection could be retrieved
541545
await fetch(pool)
542546

543547

544-
545548
@pytest.mark.trio
546549
async def test_pool_timeout_connection_cleanup():
547550
"""
@@ -555,7 +558,8 @@ async def test_pool_timeout_connection_cleanup():
555558
b"Content-Length: 13\r\n",
556559
b"\r\n",
557560
b"Hello, world!",
558-
] * 2,
561+
]
562+
* 2,
559563
)
560564

561565
async with AsyncConnectionPool(
@@ -568,12 +572,18 @@ async def test_pool_timeout_connection_cleanup():
568572
"write": 0.1,
569573
}
570574
with contextlib.suppress(PoolTimeout):
571-
await pool.request("GET", "https://example.com/", extensions={"timeout": timeout})
575+
await pool.request(
576+
"GET", "https://example.com/", extensions={"timeout": timeout}
577+
)
572578

573579
# wait for a considerable amount of time to make sure all requests time out
574580
await concurrency.sleep(0.1)
575581

576-
await pool.request("GET", "https://example.com/", extensions={"timeout": {**timeout, 'pool': 0.1}})
582+
await pool.request(
583+
"GET",
584+
"https://example.com/",
585+
extensions={"timeout": {**timeout, "pool": 0.1}},
586+
)
577587

578588
if pool.connections:
579589
for conn in pool.connections:

tests/_sync/test_connection_pool.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import pytest
66

77
from httpcore import (
8-
ConnectionPool,
98
ConnectError,
9+
ConnectionPool,
1010
PoolTimeout,
11-
ReadTimeout,
1211
ReadError,
12+
ReadTimeout,
1313
UnsupportedProtocol,
1414
)
1515
from httpcore.backends.base import NetworkStream
16-
from httpcore.backends.mock import MockBackend, HangingStream
16+
from httpcore.backends.mock import HangingStream, MockBackend
1717
from tests import concurrency
1818

1919

@@ -511,7 +511,7 @@ def test_pool_under_load():
511511
"""
512512
network_backend = MockBackend([], resp_stream_cls=HangingStream)
513513

514-
def fetch(_pool: ConnectionPool, *exceptions: Type[BaseException]):
514+
def fetch(_pool: ConnectionPool, *exceptions: Type[BaseException]) -> None:
515515
with contextlib.suppress(*exceptions):
516516
with pool.stream(
517517
"GET",

0 commit comments

Comments
 (0)