Skip to content

Commit

Permalink
Add target-version to black config (#9962) (#9986)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
asvetlov and cdce8p authored Nov 19, 2024
1 parent 7af8bbf commit 17b005a
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 144 deletions.
10 changes: 5 additions & 5 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ async def __call__(
__param: Application,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Request, Application]: ...
@overload
async def __call__(
self,
__param: BaseTestServer,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[BaseRequest, None]: ...


Expand Down Expand Up @@ -379,22 +379,22 @@ async def go(
__param: Application,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Request, Application]: ...

@overload
async def go(
__param: BaseTestServer,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[BaseRequest, None]: ...

async def go(
__param: Union[Application, BaseTestServer],
*args: Any,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Any, Any]:
if isinstance(__param, Callable) and not isinstance( # type: ignore[arg-type]
__param, (Application, BaseTestServer)
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
self,
loop: Optional[asyncio.AbstractEventLoop] = None,
*args: Any,
**kwargs: Any
**kwargs: Any,
) -> None:
if aiodns is None:
raise RuntimeError("Resolver requires aiodns library")
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
request_factory: Optional[_RequestFactory] = None,
handler_cancellation: bool = False,
loop: Optional[asyncio.AbstractEventLoop] = None,
**kwargs: Any
**kwargs: Any,
) -> None:
self._loop = loop or asyncio.get_running_loop()
self._connections: Dict[RequestHandler, asyncio.Transport] = {}
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ ignore-words-list = 'te'
# TODO(3.13): Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771
# is available in all supported cpython versions
exclude-modules = "(^aiohttp\\.helpers)"

[tool.black]
# TODO: Remove when project metadata is moved here.
# Black can read the value from [project.requires-python].
target-version = ["py39", "py310", "py311", "py312"]
7 changes: 4 additions & 3 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2955,9 +2955,10 @@ async def close(self) -> None:

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

async with aiohttp.ClientSession(connector=connector) as client, client.get(
url_from, auth=aiohttp.BasicAuth("user", "pass")
) as resp:
async with (
aiohttp.ClientSession(connector=connector) as client,
client.get(url_from, auth=aiohttp.BasicAuth("user", "pass")) as resp,
):
assert len(resp.history) == 1
assert str(resp.url) == "http://example.com"
assert resp.status == 200
Expand Down
22 changes: 12 additions & 10 deletions tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,12 @@ async def create_connection(req, traces, timeout):
return create_mocked_conn()

connector = session._connector
with mock.patch.object(connector, "connect", connect), mock.patch.object(
connector, "_create_connection", create_connection
), mock.patch.object(connector, "_release"), mock.patch(
"aiohttp.client.os"
) as m_os:
with (
mock.patch.object(connector, "connect", connect),
mock.patch.object(connector, "_create_connection", create_connection),
mock.patch.object(connector, "_release"),
mock.patch("aiohttp.client.os") as m_os,
):
m_os.urandom.return_value = key_data
await session.ws_connect(f"{protocol}://example")

Expand Down Expand Up @@ -576,11 +577,12 @@ async def create_connection(
return create_mocked_conn()

connector = session._connector
with mock.patch.object(connector, "connect", connect), mock.patch.object(
connector, "_create_connection", create_connection
), mock.patch.object(connector, "_release"), mock.patch(
"aiohttp.client.os"
) as m_os:
with (
mock.patch.object(connector, "connect", connect),
mock.patch.object(connector, "_create_connection", create_connection),
mock.patch.object(connector, "_release"),
mock.patch("aiohttp.client.os") as m_os,
):
m_os.urandom.return_value = key_data
await session.ws_connect(f"{protocol}://example")

Expand Down
29 changes: 17 additions & 12 deletions tests/test_client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ async def test_ws_connect_read_timeout_is_reset_to_inf(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = 0.5
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand All @@ -80,9 +81,10 @@ async def test_ws_connect_read_timeout_stays_inf(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = None
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand Down Expand Up @@ -111,9 +113,10 @@ async def test_ws_connect_read_timeout_reset_to_max(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = 0.5
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand Down Expand Up @@ -416,9 +419,11 @@ async def test_close_connection_lost(
hdrs.SEC_WEBSOCKET_ACCEPT: ws_key,
}
mresp.connection.protocol.read_timeout = None
with mock.patch("aiohttp.client.WebSocketWriter"), mock.patch(
"aiohttp.client.os"
) as m_os, mock.patch("aiohttp.client.ClientSession.request") as m_req:
with (
mock.patch("aiohttp.client.WebSocketWriter"),
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(mresp)
Expand Down
13 changes: 8 additions & 5 deletions tests/test_client_ws_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,14 @@ async def handler(request: web.Request) -> NoReturn:
# since if we closed the connection normally, the client would
# would cancel the heartbeat task and we wouldn't get a ping
assert resp._conn is not None
with mock.patch.object(
resp._conn.transport, "write", side_effect=ClientConnectionResetError
), mock.patch.object(
resp._writer, "send_frame", wraps=resp._writer.send_frame
) as send_frame:
with (
mock.patch.object(
resp._conn.transport, "write", side_effect=ClientConnectionResetError
),
mock.patch.object(
resp._writer, "send_frame", wraps=resp._writer.send_frame
) as send_frame,
):
await resp.receive()
ping_count = send_frame.call_args_list.count(mock.call(b"", WSMsgType.PING))
# Connection should be closed roughly after 1.5x heartbeat.
Expand Down
Loading

0 comments on commit 17b005a

Please sign in to comment.