epy.ContextManager

Contents

epy.ContextManager#

class etils.epy.ContextManager[source]#

Bases: abc.ABC, Generic[etils.epy.contextlib._T]

ContextManager allows to define contextmanager class using yield-syntax.

Example:

class A(epy.ContextManager):

  def __contextmanager__(self) -> Iterable[A]:
    yield self


with A() as a:
  pass

One the code is more mature, this could be merged to contextlib directly. https://discuss.python.org/t/yield-based-contextmanager-for-classes/8453