MCPcopy Index your code
hub / github.com/python/cpython / enter_async_context

Method enter_async_context

Lib/contextlib.py:647–665  ·  view source on GitHub ↗

Enters the supplied async context manager. If successful, also pushes its __aexit__ method as a callback and returns the result of the __aenter__ method.

(self, cm)

Source from the content-addressed store, hash-verified

645 return _exit_wrapper
646
647 async def enter_async_context(self, cm):
648 """Enters the supplied async context manager.
649
650 If successful, also pushes its __aexit__ method as a callback and
651 returns the result of the __aenter__ method.
652 """
653 _enter = _lookup_special(cm, '__aenter__', _sentinel)
654 if _enter is _sentinel:
655 cls = type(cm)
656 raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
657 f"not support the asynchronous context manager protocol")
658 _exit = _lookup_special(cm, '__aexit__', _sentinel)
659 if _exit is _sentinel:
660 cls = type(cm)
661 raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
662 f"not support the asynchronous context manager protocol")
663 result = await _enter()
664 self._push_exit_callback(_exit, False)
665 return result
666
667 def push_async_exit(self, exit):
668 """Registers a coroutine function with the standard __aexit__ method

Calls 2

_lookup_specialFunction · 0.85
_push_exit_callbackMethod · 0.80