Skip to content

Commit 5ecd8c8

Browse files
authored
gh-104764: [Enum] fix 3.13-specific tests (GH-104779)
1 parent 2e5d8a9 commit 5ecd8c8

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

Lib/enum.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,8 @@ def __setitem__(self, key, value):
388388
389389
Single underscore (sunder) names are reserved.
390390
"""
391-
if _is_internal_class(self._cls_name, value):
392-
import warnings
393-
warnings.warn(
394-
"In 3.13 classes created inside an enum will not become a member. "
395-
"Use the `member` decorator to keep the current behavior.",
396-
DeprecationWarning,
397-
stacklevel=2,
398-
)
399391
if _is_private(self._cls_name, key):
400-
# also do nothing, name will be a normal attribute
392+
# do nothing, name will be a normal attribute
401393
pass
402394
elif _is_sunder(key):
403395
if key not in (
@@ -440,10 +432,9 @@ def __setitem__(self, key, value):
440432
value = value.value
441433
elif _is_descriptor(value):
442434
pass
443-
# TODO: uncomment next three lines in 3.13
444-
# elif _is_internal_class(self._cls_name, value):
445-
# # do nothing, name will be a normal attribute
446-
# pass
435+
elif _is_internal_class(self._cls_name, value):
436+
# do nothing, name will be a normal attribute
437+
pass
447438
else:
448439
if key in self:
449440
# enum overwriting a descriptor?
@@ -1169,28 +1160,13 @@ def _generate_next_value_(name, start, count, last_values):
11691160
if not last_values:
11701161
return start
11711162
try:
1172-
last = last_values[-1]
1173-
last_values.sort()
1174-
if last == last_values[-1]:
1175-
# no difference between old and new methods
1176-
return last + 1
1177-
else:
1178-
# trigger old method (with warning)
1179-
raise TypeError
1163+
last_value = sorted(last_values).pop()
11801164
except TypeError:
1181-
import warnings
1182-
warnings.warn(
1183-
"In 3.13 the default `auto()`/`_generate_next_value_` will require all values to be sortable and support adding +1\n"
1184-
"and the value returned will be the largest value in the enum incremented by 1",
1185-
DeprecationWarning,
1186-
stacklevel=3,
1187-
)
1188-
for v in last_values:
1189-
try:
1190-
return v + 1
1191-
except TypeError:
1192-
pass
1193-
return start
1165+
raise TypeError('unable to sort non-numeric values') from None
1166+
try:
1167+
return last_value + 1
1168+
except TypeError:
1169+
raise TypeError('unable to increment %r' % (last_value, )) from None
11941170

11951171
@classmethod
11961172
def _missing_(cls, value):

Lib/test/test_enum.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ class Inner(Enum):
10901090
)
10911091

10921092
@unittest.skipIf(
1093-
python_version < (3, 14),
1093+
python_version < (3, 13),
10941094
'inner classes are still members',
10951095
)
10961096
def test_nested_classes_in_enum_are_not_members(self):
@@ -4261,21 +4261,21 @@ class Color(Enum):
42614261
self.assertEqual(Color.green.value, 3)
42624262

42634263
@unittest.skipIf(
4264-
python_version < (3, 14),
4265-
'mixed types with auto() will raise in the future',
4264+
python_version < (3, 13),
4265+
'mixed types with auto() will raise in 3.13',
42664266
)
42674267
def test_auto_garbage_fail(self):
4268-
with self.assertRaisesRegex(TypeError, 'will require all values to be sortable'):
4268+
with self.assertRaisesRegex(TypeError, "unable to increment 'red'"):
42694269
class Color(Enum):
42704270
red = 'red'
42714271
blue = auto()
42724272

42734273
@unittest.skipIf(
4274-
python_version < (3, 14),
4275-
'mixed types with auto() will raise in the future',
4274+
python_version < (3, 13),
4275+
'mixed types with auto() will raise in 3.13',
42764276
)
42774277
def test_auto_garbage_corrected_fail(self):
4278-
with self.assertRaisesRegex(TypeError, 'will require all values to be sortable'):
4278+
with self.assertRaisesRegex(TypeError, 'unable to sort non-numeric values'):
42794279
class Color(Enum):
42804280
red = 'red'
42814281
blue = 2
@@ -4303,8 +4303,8 @@ def _generate_next_value_(name, start, count, last):
43034303
self.assertEqual(Color.blue.value, 'blue')
43044304

43054305
@unittest.skipIf(
4306-
python_version < (3, 14),
4307-
'auto() will return highest value + 1 in the future',
4306+
python_version < (3, 13),
4307+
'auto() will return highest value + 1 in 3.13',
43084308
)
43094309
def test_auto_with_aliases(self):
43104310
class Color(Enum):

0 commit comments

Comments
 (0)