Skip to content

Commit

Permalink
make the type checker happy
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Oct 6, 2024
1 parent d803f52 commit dc3ae1c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions asyncstdlib/contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,15 @@ def push(self, exit: SE) -> SE:
If a context manager must also be entered, use :py:meth:`~.enter_context`
instead.
"""
try:
aexit: Callable[..., Awaitable[Union[None, bool]]]
if hasattr(exit, "__aexit__"):
aexit = exit.__aexit__ # type: ignore
except AttributeError:
try:
aexit = awaitify(
exit.__exit__, # type: ignore
)
except AttributeError:
assert callable(
exit
), f"Expected (async) context manager or callable, got {exit}"
aexit = awaitify(exit)
elif hasattr(exit, "__exit__"):
aexit = exit.__aexit__ # type: ignore
elif callable(exit):
aexit = awaitify(exit) # type: ignore
else:
raise TypeError(f"Expected (async) context manager or callable, got {exit}")
self._exit_callbacks.append(aexit) # pyright: ignore[reportUnknownArgumentType]
return exit

Expand Down

0 comments on commit dc3ae1c

Please sign in to comment.