Skip to content

Commit

Permalink
Fix annotations on __exit__ and __aexit__ (#274)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
JelleZijlstra and pre-commit-ci[bot] authored Dec 19, 2021
1 parent 8685c60 commit 2ede7d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/274.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type annotations for `__exit__` and `__aexit__` methods.
14 changes: 7 additions & 7 deletions async_timeout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def __enter__(self) -> "Timeout":

def __exit__(
self,
exc_type: Type[BaseException],
exc_val: BaseException,
exc_tb: TracebackType,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> Optional[bool]:
self._do_exit(exc_type)
return None
Expand All @@ -122,9 +122,9 @@ async def __aenter__(self) -> "Timeout":

async def __aexit__(
self,
exc_type: Type[BaseException],
exc_val: BaseException,
exc_tb: TracebackType,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> Optional[bool]:
self._do_exit(exc_type)
return None
Expand Down Expand Up @@ -206,7 +206,7 @@ def _do_enter(self) -> None:
self._state = _State.ENTER
self._reschedule()

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

0 comments on commit 2ede7d7

Please sign in to comment.