Wrapper for `contextlib.ExitStack` which enters a collection of context managers. Adaptation of `ContextManagers` in the `fastcore` library.
| 78 | |
| 79 | |
| 80 | class ContextManagers: |
| 81 | """ |
| 82 | Wrapper for `contextlib.ExitStack` which enters a collection of context managers. Adaptation of `ContextManagers` |
| 83 | in the `fastcore` library. |
| 84 | """ |
| 85 | |
| 86 | def __init__(self, context_managers: list[ContextManager]): |
| 87 | self.context_managers = context_managers |
| 88 | self.stack = ExitStack() |
| 89 | |
| 90 | def __enter__(self): |
| 91 | for context_manager in self.context_managers: |
| 92 | self.stack.enter_context(context_manager) |
| 93 | |
| 94 | def __exit__(self, *args, **kwargs): |
| 95 | self.stack.__exit__(*args, **kwargs) |
| 96 | |
| 97 | |
| 98 | logger = logging.get_logger(__name__) |
no outgoing calls
no test coverage detected
searching dependent graphs…