Registers a callback with the standard __exit__ method signature. Can suppress exceptions the same way __exit__ method can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself).
(self, exit)
| 493 | return new_stack |
| 494 | |
| 495 | def push(self, exit): |
| 496 | """Registers a callback with the standard __exit__ method signature. |
| 497 | |
| 498 | Can suppress exceptions the same way __exit__ method can. |
| 499 | Also accepts any object with an __exit__ method (registering a call |
| 500 | to the method instead of the object itself). |
| 501 | """ |
| 502 | # We use an unbound method rather than a bound method to follow |
| 503 | # the standard lookup behaviour for special methods. |
| 504 | _cb_type = type(exit) |
| 505 | |
| 506 | try: |
| 507 | exit_method = _cb_type.__exit__ |
| 508 | except AttributeError: |
| 509 | # Not a context manager, so assume it's a callable. |
| 510 | self._push_exit_callback(exit) |
| 511 | else: |
| 512 | self._push_cm_exit(exit, exit_method) |
| 513 | return exit # Allow use as a decorator. |
| 514 | |
| 515 | def enter_context(self, cm): |
| 516 | """Enters the supplied context manager. |
nothing calls this directly
no test coverage detected