python (3.11.7)
       1  from contextlib import ExitStack, contextmanager
       2  from typing import ContextManager, Generator, TypeVar
       3  
       4  _T = TypeVar("_T", covariant=True)
       5  
       6  
       7  class ESC[4;38;5;81mCommandContextMixIn:
       8      def __init__(self) -> None:
       9          super().__init__()
      10          self._in_main_context = False
      11          self._main_context = ExitStack()
      12  
      13      @contextmanager
      14      def main_context(self) -> Generator[None, None, None]:
      15          assert not self._in_main_context
      16  
      17          self._in_main_context = True
      18          try:
      19              with self._main_context:
      20                  yield
      21          finally:
      22              self._in_main_context = False
      23  
      24      def enter_context(self, context_provider: ContextManager[_T]) -> _T:
      25          assert self._in_main_context
      26  
      27          return self._main_context.enter_context(context_provider)