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

Function _enter_context

Lib/unittest/case.py:111–132  ·  view source on GitHub ↗
(cm, addcleanup)

Source from the content-addressed store, hash-verified

109
110
111def _enter_context(cm, addcleanup):
112 # We look up the special methods on the type to match the with
113 # statement.
114 cls = type(cm)
115 try:
116 enter = cls.__enter__
117 exit = cls.__exit__
118 except AttributeError:
119 msg = (f"'{cls.__module__}.{cls.__qualname__}' object does "
120 "not support the context manager protocol")
121 try:
122 cls.__aenter__
123 cls.__aexit__
124 except AttributeError:
125 pass
126 else:
127 msg += (" but it supports the asynchronous context manager "
128 "protocol. Did you mean to use enterAsyncContext()?")
129 raise TypeError(msg) from None
130 result = enter(cm)
131 addcleanup(exit, cm, None, None, None)
132 return result
133
134
135_module_cleanups = []

Callers 3

enterModuleContextFunction · 0.85
enterContextMethod · 0.85
enterClassContextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected