Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotations on __exit__ and __aexit__ #274

Merged
merged 3 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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