diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-01-07 21:44:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 21:44:21 (GMT) |
commit | 74d1663580d1914bd110c3ab7282451f5e2cd2b5 (patch) | |
tree | 0f2c442a8c18ada0102701bd3adaa8a27f04c7cc /Lib | |
parent | d382f7ee0b98e4ab6ade9384268f25c06be462ad (diff) | |
download | cpython-74d1663580d1914bd110c3ab7282451f5e2cd2b5.zip cpython-74d1663580d1914bd110c3ab7282451f5e2cd2b5.tar.gz cpython-74d1663580d1914bd110c3ab7282451f5e2cd2b5.tar.bz2 |
bpo-46296: [Enum] add a test for missing `value` recovery (GH-30458)
In `__set_name__` there is a check for the `_value_` attribute and an attempt to add it if missing; this adds a test to cover the case for simple enums with a custom `__new__` method.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_enum.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 51a31e5..2b3eac5 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1022,6 +1022,16 @@ class TestEnum(unittest.TestCase): class Huh(MyStr, MyInt, Enum): One = 1 + def test_value_auto_assign(self): + class Some(Enum): + def __new__(cls, val): + return object.__new__(cls) + x = 1 + y = 2 + + self.assertEqual(Some.x.value, 1) + self.assertEqual(Some.y.value, 2) + def test_hash(self): Season = self.Season dates = {} |