diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2021-04-12 22:03:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 22:03:29 (GMT) |
commit | 6379924ecd51e346b42b0293da0f4442a0f67707 (patch) | |
tree | 5ea83c80634db152d57e904579e9f66e1e42fe09 /Lib/test/test_enum.py | |
parent | de06baa9de109a00c26de0dc5a248fe7aafe09f5 (diff) | |
download | cpython-6379924ecd51e346b42b0293da0f4442a0f67707.zip cpython-6379924ecd51e346b42b0293da0f4442a0f67707.tar.gz cpython-6379924ecd51e346b42b0293da0f4442a0f67707.tar.bz2 |
[3.9] bpo-42248: [Enum] ensure exceptions raised in ``_missing_`` are released (GH-25350). (GH-25370)
(cherry picked from commit 8c14f5a787b21d5a1eae5d5ee981431d1c0e055f)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r-- | Lib/test/test_enum.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 4e22986..fc2d61d 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1897,6 +1897,38 @@ class TestEnum(unittest.TestCase): else: raise Exception('Exception not raised.') + def test_missing_exceptions_reset(self): + import weakref + # + class TestEnum(enum.Enum): + VAL1 = 'val1' + VAL2 = 'val2' + # + class Class1: + def __init__(self): + # Gracefully handle an exception of our own making + try: + raise ValueError() + except ValueError: + pass + # + class Class2: + def __init__(self): + # Gracefully handle an exception of Enum's making + try: + TestEnum('invalid_value') + except ValueError: + pass + # No strong refs here so these are free to die. + class_1_ref = weakref.ref(Class1()) + class_2_ref = weakref.ref(Class2()) + # + # The exception raised by Enum creates a reference loop and thus + # Class2 instances will stick around until the next gargage collection + # cycle, unlike Class1. + self.assertIs(class_1_ref(), None) + self.assertIs(class_2_ref(), None) + def test_multiple_mixin(self): class MaxMixin: @classproperty |