Skip to content

Commit f16304f

Browse files
committed
contextlib: modify ExitStack to work in uPy
1 parent 4977b21 commit f16304f

File tree

1 file changed

+0
-11
lines changed

1 file changed

+0
-11
lines changed

contextlib/contextlib.py

-11
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,12 @@ def __exit__(self, exctype, excinst, exctb):
165165
# Inspired by discussions on http://bugs.python.org/issue13585
166166
class ExitStack(object):
167167
"""Context manager for dynamic management of a stack of exit callbacks
168-
169168
For example:
170-
171169
with ExitStack() as stack:
172170
files = [stack.enter_context(open(fname)) for fname in filenames]
173171
# All opened files will automatically be closed at the end of
174172
# the with statement, even if attempts to open files later
175173
# in the list raise an exception
176-
177174
"""
178175
def __init__(self):
179176
self._exit_callbacks = deque()
@@ -189,14 +186,11 @@ def _push_cm_exit(self, cm, cm_exit):
189186
"""Helper to correctly register callbacks to __exit__ methods"""
190187
def _exit_wrapper(*exc_details):
191188
return cm_exit(cm, *exc_details)
192-
_exit_wrapper.__self__ = cm
193189
self.push(_exit_wrapper)
194190

195191
def push(self, exit):
196192
"""Registers a callback with the standard __exit__ method signature
197-
198193
Can suppress exceptions the same way __exit__ methods can.
199-
200194
Also accepts any object with an __exit__ method (registering a call
201195
to the method instead of the object itself)
202196
"""
@@ -214,20 +208,15 @@ def push(self, exit):
214208

215209
def callback(self, callback, *args, **kwds):
216210
"""Registers an arbitrary callback and arguments.
217-
218211
Cannot suppress exceptions.
219212
"""
220213
def _exit_wrapper(exc_type, exc, tb):
221214
callback(*args, **kwds)
222-
# We changed the signature, so using @wraps is not appropriate, but
223-
# setting __wrapped__ may still help with introspection
224-
_exit_wrapper.__wrapped__ = callback
225215
self.push(_exit_wrapper)
226216
return callback # Allow use as a decorator
227217

228218
def enter_context(self, cm):
229219
"""Enters the supplied context manager
230-
231220
If successful, also pushes its __exit__ method as a callback and
232221
returns the result of the __enter__ method.
233222
"""

0 commit comments

Comments
 (0)