diff --git a/Lib/asyncio/timeouts.py b/Lib/asyncio/timeouts.py index 029c468739bf2d..826201b8b06e34 100644 --- a/Lib/asyncio/timeouts.py +++ b/Lib/asyncio/timeouts.py @@ -84,9 +84,9 @@ def __repr__(self) -> str: async def __aenter__(self) -> "Timeout": self._state = _State.ENTERED self._task = tasks.current_task() - self._cancelling = self._task.cancelling() if self._task is None: raise RuntimeError("Timeout should be used inside a task") + self._cancelling = self._task.cancelling() self.reschedule(self._when) return self diff --git a/Misc/ACKS b/Misc/ACKS index 94cb1965676f48..3783f511bb7240 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -760,6 +760,7 @@ Aaron Hill Joel Hillacre Richie Hindle Konrad Hinsen +James Hilton-Balfe Richard Hoberecht David Hobley Tim Hochberg diff --git a/Misc/NEWS.d/next/Library/2023-10-19-11-40-38.gh-issue-111085.hBPpQr.rst b/Misc/NEWS.d/next/Library/2023-10-19-11-40-38.gh-issue-111085.hBPpQr.rst new file mode 100644 index 00000000000000..ff4229dae8480a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-19-11-40-38.gh-issue-111085.hBPpQr.rst @@ -0,0 +1 @@ +Fix :class:`asyncio.Timeout` raising an :exc:`AttributeError` over a :exc:`RuntimeError` due to logic bug. Patch by James Hilton-Balfe