shaunduncan/smokesignal

Should use contextlib.contextmanager for emitting

Closed this issue · 0 comments

Basically the @contextmanager decorator allows you to write context managers as functions, saving the need for classes:

@contextmanager
def emitting(exit, enter=None):
    if enter is not None:
        emit(enter)
    try:
        yield
    finally:
        emit(exit)