Skip to content

Commit 2ede7d7

Browse files
Fix annotations on __exit__ and __aexit__ (#274)
* Fix annotations on `__exit__` and `__aexit__` All parameters should be Optional, because they're None when no exception is thrown. * changelog * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8685c60 commit 2ede7d7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGES/274.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve type annotations for `__exit__` and `__aexit__` methods.

async_timeout/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ def __enter__(self) -> "Timeout":
109109

110110
def __exit__(
111111
self,
112-
exc_type: Type[BaseException],
113-
exc_val: BaseException,
114-
exc_tb: TracebackType,
112+
exc_type: Optional[Type[BaseException]],
113+
exc_val: Optional[BaseException],
114+
exc_tb: Optional[TracebackType],
115115
) -> Optional[bool]:
116116
self._do_exit(exc_type)
117117
return None
@@ -122,9 +122,9 @@ async def __aenter__(self) -> "Timeout":
122122

123123
async def __aexit__(
124124
self,
125-
exc_type: Type[BaseException],
126-
exc_val: BaseException,
127-
exc_tb: TracebackType,
125+
exc_type: Optional[Type[BaseException]],
126+
exc_val: Optional[BaseException],
127+
exc_tb: Optional[TracebackType],
128128
) -> Optional[bool]:
129129
self._do_exit(exc_type)
130130
return None
@@ -206,7 +206,7 @@ def _do_enter(self) -> None:
206206
self._state = _State.ENTER
207207
self._reschedule()
208208

209-
def _do_exit(self, exc_type: Type[BaseException]) -> None:
209+
def _do_exit(self, exc_type: Optional[Type[BaseException]]) -> None:
210210
if exc_type is asyncio.CancelledError and self._state == _State.TIMEOUT:
211211
self._timeout_handler = None
212212
raise asyncio.TimeoutError

0 commit comments

Comments
 (0)