Skip to content

Commit ee960d7

Browse files
pre-commit-ci[bot]rodrigo.nogueira
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4a9bac4 commit ee960d7

3 files changed

Lines changed: 7 additions & 11 deletions

File tree

CHANGES.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010

1111
.. towncrier release notes start
1212
13-
Features
14-
--------
15-
16-
- Added a ``port`` property to ``web.TCPSite``, returning the dynamically assigned port when the site is created with ``port=0``.
17-
18-
1913
3.13.3 (2026-01-03)
2014
===================
2115

aiohttp/web_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
if port is None:
102102
port = 8443 if self._ssl_context else 8080
103103
self._port = port
104-
self._bound_port: Optional[int] = None
104+
self._bound_port: int | None = None
105105
self._reuse_address = reuse_address
106106
self._reuse_port = reuse_port
107107

@@ -140,9 +140,9 @@ async def start(self) -> None:
140140
reuse_port=self._reuse_port,
141141
)
142142
if self._server.sockets:
143-
self._bound_port = self._server.sockets[0].getsockname()[1]
144-
else:
145-
self._bound_port = self._port
143+
port = self._server.sockets[0].getsockname()[1]
144+
if isinstance(port, int):
145+
self._bound_port = port
146146

147147

148148
class UnixSite(BaseSite):

examples/fake_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def __init__(self) -> None:
6060

6161
async def start(self) -> dict[str, int]:
6262
await self.runner.setup()
63-
site = web.TCPSite(self.runner, "127.0.0.1", port=0, ssl_context=self.ssl_context)
63+
site = web.TCPSite(
64+
self.runner, "127.0.0.1", port=0, ssl_context=self.ssl_context
65+
)
6466
await site.start()
6567
return {"graph.facebook.com": site.port}
6668

0 commit comments

Comments
 (0)