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

Method enter_context

Lib/contextlib.py:516–534  ·  view source on GitHub ↗

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

(self, cm)

Source from the content-addressed store, hash-verified

514 return exit # Allow use as a decorator.
515
516 def enter_context(self, cm):
517 """Enters the supplied context manager.
518
519 If successful, also pushes its __exit__ method as a callback and
520 returns the result of the __enter__ method.
521 """
522 _enter = _lookup_special(cm, '__enter__', _sentinel)
523 if _enter is _sentinel:
524 cls = type(cm)
525 raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
526 f"not support the context manager protocol")
527 _exit = _lookup_special(cm, '__exit__', _sentinel)
528 if _exit is _sentinel:
529 cls = type(cm)
530 raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
531 f"not support the context manager protocol")
532 result = _enter()
533 self._push_exit_callback(_exit)
534 return result
535
536 def callback(self, callback, /, *args, **kwds):
537 """Registers an arbitrary callback and arguments.

Callers 15

unix_getpassFunction · 0.80
attachFunction · 0.80
decoration_helperMethod · 0.80
__enter__Method · 0.80
stream_contextMethod · 0.80
do_testMethod · 0.80
setUpMethod · 0.80
test_headerMethod · 0.80
mock_sysMethod · 0.80
test_create_snapshotMethod · 0.80
run_testMethod · 0.80

Calls 2

_push_exit_callbackMethod · 0.95
_lookup_specialFunction · 0.85

Tested by 15

stream_contextMethod · 0.64
do_testMethod · 0.64
setUpMethod · 0.64
test_headerMethod · 0.64
mock_sysMethod · 0.64
test_create_snapshotMethod · 0.64
run_testMethod · 0.64
run_async_testMethod · 0.64
test_enter_contextMethod · 0.64