(cm, addcleanup)
| 104 | |
| 105 | |
| 106 | def _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 = [] |
no outgoing calls
no test coverage detected
searching dependent graphs…