(cm, addcleanup)
| 109 | |
| 110 | |
| 111 | def _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 = [] |
no outgoing calls
no test coverage detected