Skip to content

Commit

Permalink
Python implementation: avoid reference cycles introduced via _reraise
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Dec 6, 2021
1 parent 83c9bc0 commit 252932d
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/Acquisition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def _rebound_method(method, wrapper):
if isinstance(method, types.MethodType):
method = types.MethodType(method.im_func, wrapper, method.im_class)
return method
exec("""def _reraise(tp, value, tb=None):
raise tp, value, tb
""")
else: # pragma: PY3
PY2 = False
import copyreg as copy_reg
Expand All @@ -64,13 +61,6 @@ def _rebound_method(method, wrapper):
method = types.MethodType(method.__func__, wrapper)
return method

def _reraise(tp, value, tb=None):
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value

###
# Wrapper object protocol, mostly ported from C directly
###
Expand Down Expand Up @@ -758,14 +748,10 @@ class _Acquirer(ExtensionClass.Base):
def __getattribute__(self, name):
try:
return super(_Acquirer, self).__getattribute__(name)
except AttributeError:
except AttributeError as exc:
# the doctests have very specific error message
# requirements (but at least we can preserve the traceback)
tb = sys.exc_info()[2]
try:
_reraise(AttributeError, AttributeError(name), tb)
finally:
del tb
exc.args = AttributeError(name).args
raise

def __of__(self, context):
return type(self)._Wrapper(self, context)
Expand Down

0 comments on commit 252932d

Please sign in to comment.