This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
def default___with__(obj, depth): | |
# Exception in __enter__ should be propagated. | |
enter_result = obj.__enter__() | |
try: | |
yield enter_result | |
except BaseException as e: | |
if not obj.__exit__(type(e), e, e.__traceback__): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
def CMProtocolV2(typ): | |
# Copy from contextlib._GeneratorContextManager | |
def __enter__(self): | |
self._gen = self.__with__() | |
try: | |
return next(self._gen) | |
except StopIteration: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
class CMProtocolV2: | |
def __init__(self, manager_expr: str, manager_name: str | None = None, result_name: str | None = None): | |
self.manager_expr = manager_expr | |
self.manager_name = manager_name | |
self.result_name = result_name | |
self._inited_manager = None |