mirror of
https://github.com/python/cpython.git
synced 2025-08-07 02:18:59 +00:00
[3.9] bpo-42517: [Enum] deprecate private name members (GH-23722) (GH-23748)
private names will raise a DeprecationWarning; in 3.10 they will become normal attributes
This commit is contained in:
parent
6b2ed38509
commit
aba12b67c1
4 changed files with 51 additions and 0 deletions
|
@ -1147,6 +1147,7 @@ class TestEnum(unittest.TestCase):
|
|||
class auto_enum(type(Enum)):
|
||||
def __new__(metacls, cls, bases, classdict):
|
||||
temp = type(classdict)()
|
||||
temp._cls_name = cls
|
||||
names = set(classdict._member_names)
|
||||
i = 0
|
||||
for k in classdict._member_names:
|
||||
|
@ -2049,6 +2050,23 @@ class TestEnum(unittest.TestCase):
|
|||
exec(code, global_ns, local_ls)
|
||||
|
||||
|
||||
@unittest.skipUnless(
|
||||
sys.version_info[:2] == (3, 9),
|
||||
'private variables are now normal attributes',
|
||||
)
|
||||
def test_warning_for_private_variables(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
class Private(Enum):
|
||||
__corporal = 'Radar'
|
||||
self.assertEqual(Private._Private__corporal.value, 'Radar')
|
||||
try:
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
class Private(Enum):
|
||||
__major_ = 'Hoolihan'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
class TestOrder(unittest.TestCase):
|
||||
|
||||
def test_same_members(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue