Skip to content

Commit 17b005a

Browse files
asvetlovcdce8p
andauthored
Add target-version to black config (#9962) (#9986)
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 (cherry picked from commit 00fd4eb) <!-- Thank you for your contribution! --> ## What do these changes do? <!-- Please give a short brief about these changes. --> ## Are there changes in behavior for the user? <!-- Outline any notable behaviour for the end users. --> ## Is it a substantial burden for the maintainers to support this? <!-- Stop right there! Pause. Just for a minute... Can you think of anything obvious that would complicate the ongoing development of this project? Try to consider if you'd be able to maintain it throughout the next 5 years. Does it seem viable? Tell us your thoughts! We'd very much love to hear what the consequences of merging this patch might be... This will help us assess if your change is something we'd want to entertain early in the review process. Thank you in advance! --> ## Related issue number <!-- Are there any issues opened that will be resolved by merging this change? --> <!-- Remember to prefix with 'Fixes' if it should close the issue (e.g. 'Fixes #123'). --> ## Checklist - [ ] I think the code is well written - [ ] Unit tests for the changes exist - [ ] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` * The format is &lt;Name&gt; &lt;Surname&gt;. * Please keep alphabetical order, the file is sorted by names. - [ ] Add a new news fragment into the `CHANGES/` folder * name it `<issue_or_pr_num>.<type>.rst` (e.g. `588.bugfix.rst`) * if you don't have an issue number, change it to the pull request number after creating the PR * `.bugfix`: A bug fix for something the maintainers deemed an improper undesired behavior that got corrected to match pre-agreed expectations. * `.feature`: A new behavior, public APIs. That sort of stuff. * `.deprecation`: A declaration of future API removals and breaking changes in behavior. * `.breaking`: When something public is removed in a breaking way. Could be deprecated in an earlier release. * `.doc`: Notable updates to the documentation structure or build process. * `.packaging`: Notes for downstreams about unobvious side effects and tooling. Changes in the test invocation considerations and runtime assumptions. * `.contrib`: Stuff that affects the contributor experience. e.g. Running tests, building the docs, setting up the development environment. * `.misc`: Changes that are hard to assign to any of the above categories. * Make sure to use full sentences with correct case and punctuation, for example: ```rst Fixed issue with non-ascii contents in doctest text files -- by :user:`contributor-gh-handle`. ``` Use the past tense or the present tense a non-imperative mood, referring to what's changed compared to the last released version of this project. Co-authored-by: Marc Mueller <[email protected]>
1 parent 7af8bbf commit 17b005a

14 files changed

+227
-144
lines changed

aiohttp/pytest_plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ async def __call__(
4343
__param: Application,
4444
*,
4545
server_kwargs: Optional[Dict[str, Any]] = None,
46-
**kwargs: Any
46+
**kwargs: Any,
4747
) -> TestClient[Request, Application]: ...
4848
@overload
4949
async def __call__(
5050
self,
5151
__param: BaseTestServer,
5252
*,
5353
server_kwargs: Optional[Dict[str, Any]] = None,
54-
**kwargs: Any
54+
**kwargs: Any,
5555
) -> TestClient[BaseRequest, None]: ...
5656

5757

@@ -379,22 +379,22 @@ async def go(
379379
__param: Application,
380380
*,
381381
server_kwargs: Optional[Dict[str, Any]] = None,
382-
**kwargs: Any
382+
**kwargs: Any,
383383
) -> TestClient[Request, Application]: ...
384384

385385
@overload
386386
async def go(
387387
__param: BaseTestServer,
388388
*,
389389
server_kwargs: Optional[Dict[str, Any]] = None,
390-
**kwargs: Any
390+
**kwargs: Any,
391391
) -> TestClient[BaseRequest, None]: ...
392392

393393
async def go(
394394
__param: Union[Application, BaseTestServer],
395395
*args: Any,
396396
server_kwargs: Optional[Dict[str, Any]] = None,
397-
**kwargs: Any
397+
**kwargs: Any,
398398
) -> TestClient[Any, Any]:
399399
if isinstance(__param, Callable) and not isinstance( # type: ignore[arg-type]
400400
__param, (Application, BaseTestServer)

aiohttp/resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
self,
8686
loop: Optional[asyncio.AbstractEventLoop] = None,
8787
*args: Any,
88-
**kwargs: Any
88+
**kwargs: Any,
8989
) -> None:
9090
if aiodns is None:
9191
raise RuntimeError("Resolver requires aiodns library")

aiohttp/web_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(
2020
request_factory: Optional[_RequestFactory] = None,
2121
handler_cancellation: bool = False,
2222
loop: Optional[asyncio.AbstractEventLoop] = None,
23-
**kwargs: Any
23+
**kwargs: Any,
2424
) -> None:
2525
self._loop = loop or asyncio.get_running_loop()
2626
self._connections: Dict[RequestHandler, asyncio.Transport] = {}

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ ignore-words-list = 'te'
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"]

tests/test_client_functional.py

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

29562956
connector = aiohttp.TCPConnector(resolver=FakeResolver(), ssl=False)
29572957

2958-
async with aiohttp.ClientSession(connector=connector) as client, client.get(
2959-
url_from, auth=aiohttp.BasicAuth("user", "pass")
2960-
) as resp:
2958+
async with (
2959+
aiohttp.ClientSession(connector=connector) as client,
2960+
client.get(url_from, auth=aiohttp.BasicAuth("user", "pass")) as resp,
2961+
):
29612962
assert len(resp.history) == 1
29622963
assert str(resp.url) == "http://example.com"
29632964
assert resp.status == 200

tests/test_client_session.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,12 @@ async def create_connection(req, traces, timeout):
515515
return create_mocked_conn()
516516

517517
connector = session._connector
518-
with mock.patch.object(connector, "connect", connect), mock.patch.object(
519-
connector, "_create_connection", create_connection
520-
), mock.patch.object(connector, "_release"), mock.patch(
521-
"aiohttp.client.os"
522-
) as m_os:
518+
with (
519+
mock.patch.object(connector, "connect", connect),
520+
mock.patch.object(connector, "_create_connection", create_connection),
521+
mock.patch.object(connector, "_release"),
522+
mock.patch("aiohttp.client.os") as m_os,
523+
):
523524
m_os.urandom.return_value = key_data
524525
await session.ws_connect(f"{protocol}://example")
525526

@@ -576,11 +577,12 @@ async def create_connection(
576577
return create_mocked_conn()
577578

578579
connector = session._connector
579-
with mock.patch.object(connector, "connect", connect), mock.patch.object(
580-
connector, "_create_connection", create_connection
581-
), mock.patch.object(connector, "_release"), mock.patch(
582-
"aiohttp.client.os"
583-
) as m_os:
580+
with (
581+
mock.patch.object(connector, "connect", connect),
582+
mock.patch.object(connector, "_create_connection", create_connection),
583+
mock.patch.object(connector, "_release"),
584+
mock.patch("aiohttp.client.os") as m_os,
585+
):
584586
m_os.urandom.return_value = key_data
585587
await session.ws_connect(f"{protocol}://example")
586588

tests/test_client_ws.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ async def test_ws_connect_read_timeout_is_reset_to_inf(
5151
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
5252
}
5353
resp.connection.protocol.read_timeout = 0.5
54-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
55-
"aiohttp.client.ClientSession.request"
56-
) as m_req:
54+
with (
55+
mock.patch("aiohttp.client.os") as m_os,
56+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
57+
):
5758
m_os.urandom.return_value = key_data
5859
m_req.return_value = loop.create_future()
5960
m_req.return_value.set_result(resp)
@@ -80,9 +81,10 @@ async def test_ws_connect_read_timeout_stays_inf(
8081
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
8182
}
8283
resp.connection.protocol.read_timeout = None
83-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
84-
"aiohttp.client.ClientSession.request"
85-
) as m_req:
84+
with (
85+
mock.patch("aiohttp.client.os") as m_os,
86+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
87+
):
8688
m_os.urandom.return_value = key_data
8789
m_req.return_value = loop.create_future()
8890
m_req.return_value.set_result(resp)
@@ -111,9 +113,10 @@ async def test_ws_connect_read_timeout_reset_to_max(
111113
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
112114
}
113115
resp.connection.protocol.read_timeout = 0.5
114-
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
115-
"aiohttp.client.ClientSession.request"
116-
) as m_req:
116+
with (
117+
mock.patch("aiohttp.client.os") as m_os,
118+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
119+
):
117120
m_os.urandom.return_value = key_data
118121
m_req.return_value = loop.create_future()
119122
m_req.return_value.set_result(resp)
@@ -416,9 +419,11 @@ async def test_close_connection_lost(
416419
hdrs.SEC_WEBSOCKET_ACCEPT: ws_key,
417420
}
418421
mresp.connection.protocol.read_timeout = None
419-
with mock.patch("aiohttp.client.WebSocketWriter"), mock.patch(
420-
"aiohttp.client.os"
421-
) as m_os, mock.patch("aiohttp.client.ClientSession.request") as m_req:
422+
with (
423+
mock.patch("aiohttp.client.WebSocketWriter"),
424+
mock.patch("aiohttp.client.os") as m_os,
425+
mock.patch("aiohttp.client.ClientSession.request") as m_req,
426+
):
422427
m_os.urandom.return_value = key_data
423428
m_req.return_value = loop.create_future()
424429
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
@@ -756,11 +756,14 @@ async def handler(request: web.Request) -> NoReturn:
756756
# since if we closed the connection normally, the client would
757757
# would cancel the heartbeat task and we wouldn't get a ping
758758
assert resp._conn is not None
759-
with mock.patch.object(
760-
resp._conn.transport, "write", side_effect=ClientConnectionResetError
761-
), mock.patch.object(
762-
resp._writer, "send_frame", wraps=resp._writer.send_frame
763-
) as send_frame:
759+
with (
760+
mock.patch.object(
761+
resp._conn.transport, "write", side_effect=ClientConnectionResetError
762+
),
763+
mock.patch.object(
764+
resp._writer, "send_frame", wraps=resp._writer.send_frame
765+
) as send_frame,
766+
):
764767
await resp.receive()
765768
ping_count = send_frame.call_args_list.count(mock.call(b"", WSMsgType.PING))
766769
# Connection should be closed roughly after 1.5x heartbeat.

0 commit comments

Comments
 (0)