From 78fa04019c49e87f352d89e000963c16af78cae1 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Tue, 20 Sep 2022 18:48:51 +0200 Subject: [PATCH] Exclude the `object` possibility from the `ClientSession.timeout` type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up PR to #6917, which fixes the overly inclusive typing of `ClientSession.timeout` attribute, which can never actually end up as an `object` instance. This leftover probably exists from the time when there was the `_sentinel` value being assigned to the attribute (see "3.8 branch `self._timeout` assignment" from the linked issue), hence why it ended up this way. For untyped code, there's absolutely no change — the `self._timeout` attribute was never actually assigned the sentinel value to. Most of the explanation already exists in #6917, here's the test code snippet from there again: ```py import asyncio import aiohttp async def main: session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) # read back the total time attribute total_time = session.timeout.total # "object" type of "Union[object, ClientTimeout]" has no attribute "total" print(total_time) asyncio.run(main()) ``` For typed code, the current solution would be to `assert isinstance(session.timeout, aiohttp.ClientTimeout)` everywhere the attribute is being accessed. This PR removes this "unnecessary necessity". Co-authored-by: Sviatoslav Sydorenko Fixes #6917 PR #6923 --- CHANGES/6917.bugfix | 3 +++ CHANGES/6917.doc | 1 + CHANGES/6923.bugfix | 1 + CHANGES/6923.doc | 1 + aiohttp/client.py | 2 +- 5 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 CHANGES/6917.bugfix create mode 120000 CHANGES/6917.doc create mode 120000 CHANGES/6923.bugfix create mode 120000 CHANGES/6923.doc diff --git a/CHANGES/6917.bugfix b/CHANGES/6917.bugfix new file mode 100644 index 00000000000..468e21a2b0f --- /dev/null +++ b/CHANGES/6917.bugfix @@ -0,0 +1,3 @@ +Dropped the :class:`object` type possibility from +the :py:attr:`aiohttp.ClientSession.timeout` +property return type declaration. diff --git a/CHANGES/6917.doc b/CHANGES/6917.doc new file mode 120000 index 00000000000..b8eddb8d6dc --- /dev/null +++ b/CHANGES/6917.doc @@ -0,0 +1 @@ +6917.bugfix \ No newline at end of file diff --git a/CHANGES/6923.bugfix b/CHANGES/6923.bugfix new file mode 120000 index 00000000000..b8eddb8d6dc --- /dev/null +++ b/CHANGES/6923.bugfix @@ -0,0 +1 @@ +6917.bugfix \ No newline at end of file diff --git a/CHANGES/6923.doc b/CHANGES/6923.doc new file mode 120000 index 00000000000..c05397962f9 --- /dev/null +++ b/CHANGES/6923.doc @@ -0,0 +1 @@ +6917.doc \ No newline at end of file diff --git a/aiohttp/client.py b/aiohttp/client.py index a97190d078a..b8c0e429495 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -1006,7 +1006,7 @@ def requote_redirect_url(self) -> bool: return self._requote_redirect_url @property - def timeout(self) -> Union[object, ClientTimeout]: + def timeout(self) -> ClientTimeout: """Timeout for the session.""" return self._timeout