mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
bpo-43162: [Enum] deprecate enum member.member access (GH-24486)
In 3.5 (?) a speed optimization made it possible to access members as attributes of other members, i.e. ``Color.RED.BLUE``. This was always discouraged in the docs, and other recent optimizations has made that one no longer necessary. Because some may be relying on it anyway, it is being deprecated in 3.10, and will be removed in 3.11.
This commit is contained in:
parent
e1f7769513
commit
d65b9033d6
3 changed files with 39 additions and 4 deletions
|
@ -2185,6 +2185,29 @@ class TestEnum(unittest.TestCase):
|
|||
self.assertEqual(Private._Private__corporal, 'Radar')
|
||||
self.assertEqual(Private._Private__major_, 'Hoolihan')
|
||||
|
||||
@unittest.skipUnless(
|
||||
sys.version_info[:2] == (3, 10),
|
||||
'member-member access now raises an exception',
|
||||
)
|
||||
def test_warning_for_member_from_member_access(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
class Di(Enum):
|
||||
YES = 1
|
||||
NO = 0
|
||||
nope = Di.YES.NO
|
||||
self.assertIs(Di.NO, nope)
|
||||
|
||||
@unittest.skipUnless(
|
||||
sys.version_info[:2] > (3, 10),
|
||||
'member-member access currently issues a warning',
|
||||
)
|
||||
def test_exception_for_member_from_member_access(self):
|
||||
with self.assertRaisesRegex(AttributeError, "Di: no instance attribute .NO."):
|
||||
class Di(Enum):
|
||||
YES = 1
|
||||
NO = 0
|
||||
nope = Di.YES.NO
|
||||
|
||||
def test_strenum_auto(self):
|
||||
class Strings(StrEnum):
|
||||
ONE = auto()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue