Skip to content

Commit 8fe7da5

Browse files
committed
-
1 parent f0feaa9 commit 8fe7da5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

source_py3/python_toolbox/context_management/functions.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,28 @@ def as_reentrant(context_manager):
109109
Note: The first value returned by `__enter__` will be returned by all the
110110
subsequent no-op `__enter__` calls.
111111
112-
blocktodo: add to docs about different ways of calling, ensure tests
112+
This can be used when calling an existing context manager:
113+
114+
with as_reentrant(some_context_manager):
115+
# Now we're reentrant!
116+
117+
Or it can be used when defining a context manager to make it reentrant:
118+
119+
@as_reentrant
120+
class MyContextManager(ContextManager):
121+
def __enter__(self):
122+
# ...
123+
def __exit__(self, exc_type, exc_value, exc_traceback):
124+
# ...
125+
126+
And also like this...
127+
128+
129+
@as_reentrant
130+
@ContextManagerType
131+
def Meow():
132+
yield # ...
133+
113134
'''
114135
return _ReentrantContextManager._wrap_context_manager_or_class(
115136
context_manager,

0 commit comments

Comments
 (0)