diff --git a/CHANGES/274.misc b/CHANGES/274.misc new file mode 100644 index 0000000..4e2e6db --- /dev/null +++ b/CHANGES/274.misc @@ -0,0 +1 @@ +Improve type annotations for `__exit__` and `__aexit__` methods. diff --git a/async_timeout/__init__.py b/async_timeout/__init__.py index e5b2caa..26c50c2 100644 --- a/async_timeout/__init__.py +++ b/async_timeout/__init__.py @@ -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 @@ -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 @@ -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