Skip to content

Commit f0feaa9

Browse files
committed
-
1 parent 5784e52 commit f0feaa9

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

source_py3/python_toolbox/context_management/functions.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)