diff options
author | Colin Watson <cjwatson@debian.org> | 2021-05-15 11:49:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-15 11:49:40 +0100 |
commit | bb1eb6f46d2f220f060a765cb292ecdae933b0f6 (patch) | |
tree | bd20b38adba58c80b04f2d57ffccc24db91f4742 | |
parent | 022ff7a08af430f9159ffb1574fd908c17745b45 (diff) | |
parent | 9f56bdf774adf6531252f604d5130be4236f856f (diff) | |
download | zope-configuration-bb1eb6f46d2f220f060a765cb292ecdae933b0f6.tar.gz |
Merge pull request #53 from cjwatson/traceback-reference-cycle
Avoid creating reference cycles through tracebacks in reraise
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | src/zope/configuration/_compat.py | 19 |
2 files changed, 15 insertions, 7 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index f2eb62a..b75a207 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changes 4.4.1 (unreleased) ------------------ -- Nothing changed yet. +- Avoid creating reference cycles through tracebacks in ``reraise`` (change + imported from ``six``). 4.4.0 (2020-03-22) diff --git a/src/zope/configuration/_compat.py b/src/zope/configuration/_compat.py index e8b1b51..6a1eebc 100644 --- a/src/zope/configuration/_compat.py +++ b/src/zope/configuration/_compat.py @@ -24,11 +24,15 @@ if PY3: # pragma: no cover # borrowed from 'six' 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 + try: + if value is None: + value = tp + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None else: # pragma: no cover @@ -40,7 +44,10 @@ else: # pragma: no cover # borrowed from 'six' exec("""\ def reraise(tp, value, tb=None): - raise tp, value, tb + try: + raise tp, value, tb + finally: + tb = None """) |