MCPcopy Index your code
hub / github.com/RustPython/RustPython / enter_context

Method enter_context

Lib/contextlib.py:515–532  ·  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

513 return exit # Allow use as a decorator.
514
515 def enter_context(self, cm):
516 """Enters the supplied context manager.
517
518 If successful, also pushes its __exit__ method as a callback and
519 returns the result of the __enter__ method.
520 """
521 # We look up the special methods on the type to match the with
522 # statement.
523 cls = type(cm)
524 try:
525 _enter = cls.__enter__
526 _exit = cls.__exit__
527 except AttributeError:
528 raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
529 f"not support the context manager protocol") from None
530 result = _enter(cm)
531 self._push_cm_exit(cm, _exit)
532 return result
533
534 def callback(self, callback, /, *args, **kwds):
535 """Registers an arbitrary callback and arguments.

Callers 15

unix_getpassFunction · 0.80
decoration_helperMethod · 0.80
__enter__Method · 0.80
stream_contextMethod · 0.80
setUpMethod · 0.80
mock_sysMethod · 0.80
test_enter_contextMethod · 0.80
my_cm_with_exit_stackMethod · 0.80
test_instance_bypassMethod · 0.80

Calls 1

_push_cm_exitMethod · 0.95

Tested by 15

stream_contextMethod · 0.64
setUpMethod · 0.64
mock_sysMethod · 0.64
test_enter_contextMethod · 0.64
my_cm_with_exit_stackMethod · 0.64
test_instance_bypassMethod · 0.64
setUpClassMethod · 0.64