File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
source_py3/python_toolbox/context_management Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,30 @@ def as_idempotent(context_manager):
6868 Note: The first value returned by `__enter__` will be returned by all the
6969 subsequent no-op `__enter__` calls.
7070
71- blocktodo: add to docs about different ways of calling, ensure tests
71+ This can be used when calling an existing context manager:
72+
73+ with as_idempotent(some_context_manager):
74+ # Now we're idempotent!
75+
76+ Or it can be used when defining a context manager to make it idempotent:
77+
78+ @as_idempotent
79+ class MyContextManager(ContextManager):
80+ def __enter__(self):
81+ # ...
82+ def __exit__(self, exc_type, exc_value, exc_traceback):
83+ # ...
84+
85+ And also like this...
86+
87+
88+ @as_idempotent
89+ @ContextManagerType
90+ def Meow():
91+ yield # ...
92+
93+ blocktodo: add tests for decorating ContextManager class and
94+ @ContextManagerType generator.
7295 '''
7396 return _IdempotentContextManager ._wrap_context_manager_or_class (
7497 context_manager ,
You can’t perform that action at this time.
0 commit comments