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

Function _enter_context

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

Source from the content-addressed store, hash-verified

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

Callers 3

enterModuleContextFunction · 0.85
enterContextMethod · 0.85
enterClassContextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…