File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -328,18 +328,15 @@ def push(self, exit: SE) -> SE:
328328 If a context manager must also be entered, use :py:meth:`~.enter_context`
329329 instead.
330330 """
331- try :
331+ aexit : Callable [..., Awaitable [Union [None , bool ]]]
332+ if hasattr (exit , "__aexit__" ):
332333 aexit = exit .__aexit__ # type: ignore
333- except AttributeError :
334- try :
335- aexit = awaitify (
336- exit .__exit__ , # type: ignore
337- )
338- except AttributeError :
339- assert callable (
340- exit
341- ), f"Expected (async) context manager or callable, got { exit } "
342- aexit = awaitify (exit )
334+ elif hasattr (exit , "__exit__" ):
335+ aexit = exit .__aexit__ # type: ignore
336+ elif callable (exit ):
337+ aexit = awaitify (exit ) # type: ignore
338+ else :
339+ raise TypeError (f"Expected (async) context manager or callable, got { exit } " )
343340 self ._exit_callbacks .append (aexit ) # pyright: ignore[reportUnknownArgumentType]
344341 return exit
345342
You can’t perform that action at this time.
0 commit comments