Skip to content

Commit 00fd4eb

Browse files
authored
Add target-version to black config (#9962)
## What do these changes do? Add `target-version` option to black config in `pyproject.toml` and reformat code. https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#t-target-version
1 parent 3e81852 commit 00fd4eb

12 files changed

+227
-144
lines changed

aiohttp/pytest_plugin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ async def __call__(
4646
__param: Application,
4747
*,
4848
server_kwargs: Optional[Dict[str, Any]] = None,
49-
**kwargs: Any
49+
**kwargs: Any,
5050
) -> TestClient[Request, Application]: ...
5151
@overload
5252
async def __call__(
5353
self,
5454
__param: BaseTestServer[_Request],
5555
*,
5656
server_kwargs: Optional[Dict[str, Any]] = None,
57-
**kwargs: Any
57+
**kwargs: Any,
5858
) -> TestClient[_Request, None]: ...
5959

6060

@@ -70,7 +70,7 @@ def __call__(
7070
handler: _RequestHandler[BaseRequest],
7171
*,
7272
port: Optional[int] = None,
73-
**kwargs: Any
73+
**kwargs: Any,
7474
) -> Awaitable[RawTestServer]: ...
7575

7676

@@ -332,7 +332,7 @@ async def go(
332332
handler: _RequestHandler[BaseRequest],
333333
*,
334334
port: Optional[int] = None,
335-
**kwargs: Any
335+
**kwargs: Any,
336336
) -> RawTestServer:
337337
server = RawTestServer(handler, port=port)
338338
await server.start_server(**kwargs)
@@ -392,20 +392,20 @@ async def go(
392392
__param: Application,
393393
*,
394394
server_kwargs: Optional[Dict[str, Any]] = None,
395-
**kwargs: Any
395+
**kwargs: Any,
396396
) -> TestClient[Request, Application]: ...
397397
@overload
398398
async def go(
399399
__param: BaseTestServer[_Request],
400400
*,
401401
server_kwargs: Optional[Dict[str, Any]] = None,
402-
**kwargs: Any
402+
**kwargs: Any,
403403
) -> TestClient[_Request, None]: ...
404404
async def go(
405405
__param: Union[Application, BaseTestServer[Any]],
406406
*,
407407
server_kwargs: Optional[Dict[str, Any]] = None,
408-
**kwargs: Any
408+
**kwargs: Any,
409409
) -> TestClient[Any, Any]:
410410
if isinstance(__param, Application):
411411
server_kwargs = server_kwargs or {}

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ ignore-words-list = 'te,assertIn'
8787
# TODO(3.13): Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771
8888
# is available in all supported cpython versions
8989
exclude-modules = "(^aiohttp\\.helpers)"
90+
91+
[tool.black]
92+
# TODO: Remove when project metadata is moved here.
93+
# Black can read the value from [project.requires-python].
94+
target-version = ["py39", "py310", "py311", "py312", "py313"]

tests/test_client_functional.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,9 +2993,10 @@ async def close(self) -> None:
29932993

29942994
connector = aiohttp.TCPConnector(resolver=FakeResolver(), ssl=False)
29952995

2996-
async with aiohttp.ClientSession(connector=connector) as client, client.get(
2997-
url_from, auth=aiohttp.BasicAuth("user", "pass")
2998-
) as resp:
2996+
async with (
2997+
aiohttp.ClientSession(connector=connector) as client,
2998+
client.get(url_from, auth=aiohttp.BasicAuth("user", "pass")) as resp,
2999+
):
29993000
assert len(resp.history) == 1
30003001
assert str(resp.url) == "http://example.com"
30013002
assert resp.status == 200

tests/test_client_session.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,12 @@ async def create_connection(
574574
return create_mocked_conn()
575575

576576
connector = session._connector
577-
with mock.patch.object(connector, "connect", connect), mock.patch.object(
578-
connector, "_create_connection", create_connection
579-
), mock.patch.object(connector, "_release"), mock.patch(
580-
"aiohttp.client.os"
581-
) as m_os:
577+
with (
578+
mock.patch.object(connector, "connect", connect),
579+
mock.patch.object(connector, "_create_connection", create_connection),
580+
mock.patch.object(connector, "_release"),
581+
mock.patch("aiohttp.client.os") as m_os,
582+
):
582583
m_os.urandom.return_value = key_data
583584
await session.ws_connect(f"{protocol}://example")
584585

@@ -635,11 +636,12 @@ async def create_connection(
635636
return create_mocked_conn()
636637

637638
connector = session._connector
638-
with mock.patch.object(connector, "connect", connect), mock.patch.object(
639-
connector, "_create_connection", create_connection
640-
), mock.patch.object(connector, "_release"), mock.patch(
641-
"aiohttp.client.os"
642-
) as m_os:
639+
with (
640+
mock.patch.object(connector, "connect", connect),
641+
mock.patch.object(connector, "_create_connection", create_connection),
642+
mock.patch.object(connector, "_release"),
643+
mock.patch("aiohttp.client.os") as m_os,
644+
):
643645
m_os.urandom.return_value = key_data
644646
await session.ws_connect(f"{protocol}://example")
645647

tests/test_client_ws.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ async def test_ws_connect_read_timeout_is_reset_to_inf(
6060
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
6161
}
6262
resp.connection.protocol.read_timeout = 0.5
63-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
64-
"aiohttp.client.ClientSession.request"
65-
) as m_req:
63+
with (
64+
mock.patch("aiohttp.client.os") as m_os,
65+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
66+
):
6667
m_os.urandom.return_value = key_data
6768
m_req.return_value = loop.create_future()
6869
m_req.return_value.set_result(resp)
@@ -89,9 +90,10 @@ async def test_ws_connect_read_timeout_stays_inf(
8990
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
9091
}
9192
resp.connection.protocol.read_timeout = None
92-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
93-
"aiohttp.client.ClientSession.request"
94-
) as m_req:
93+
with (
94+
mock.patch("aiohttp.client.os") as m_os,
95+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
96+
):
9597
m_os.urandom.return_value = key_data
9698
m_req.return_value = loop.create_future()
9799
m_req.return_value.set_result(resp)
@@ -120,9 +122,10 @@ async def test_ws_connect_read_timeout_reset_to_max(
120122
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
121123
}
122124
resp.connection.protocol.read_timeout = 0.5
123-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
124-
"aiohttp.client.ClientSession.request"
125-
) as m_req:
125+
with (
126+
mock.patch("aiohttp.client.os") as m_os,
127+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
128+
):
126129
m_os.urandom.return_value = key_data
127130
m_req.return_value = loop.create_future()
128131
m_req.return_value.set_result(resp)
@@ -447,9 +450,11 @@ async def test_close_connection_lost(
447450
hdrs.SEC_WEBSOCKET_ACCEPT: ws_key,
448451
}
449452
mresp.connection.protocol.read_timeout = None
450-
with mock.patch("aiohttp.client.WebSocketWriter"), mock.patch(
451-
"aiohttp.client.os"
452-
) as m_os, mock.patch("aiohttp.client.ClientSession.request") as m_req:
453+
with (
454+
mock.patch("aiohttp.client.WebSocketWriter"),
455+
mock.patch("aiohttp.client.os") as m_os,
456+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
457+
):
453458
m_os.urandom.return_value = key_data
454459
m_req.return_value = loop.create_future()
455460
m_req.return_value.set_result(mresp)

tests/test_client_ws_functional.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,14 @@ async def handler(request: web.Request) -> NoReturn:
777777
# since if we closed the connection normally, the client would
778778
# would cancel the heartbeat task and we wouldn't get a ping
779779
assert resp._conn is not None
780-
with mock.patch.object(
781-
resp._conn.transport, "write", side_effect=ClientConnectionResetError
782-
), mock.patch.object(
783-
resp._writer, "send_frame", wraps=resp._writer.send_frame
784-
) as send_frame:
780+
with (
781+
mock.patch.object(
782+
resp._conn.transport, "write", side_effect=ClientConnectionResetError
783+
),
784+
mock.patch.object(
785+
resp._writer, "send_frame", wraps=resp._writer.send_frame
786+
) as send_frame,
787+
):
785788
await resp.receive()
786789
ping_count = send_frame.call_args_list.count(mock.call(b"", WSMsgType.PING))
787790
# Connection should be closed roughly after 1.5x heartbeat.

0 commit comments

Comments
 (0)