Single underscore (sunder) names are reserved.
"""
- if _is_internal_class(self._cls_name, value):
- import warnings
- warnings.warn(
- "In 3.13 classes created inside an enum will not become a member. "
- "Use the `member` decorator to keep the current behavior.",
- DeprecationWarning,
- stacklevel=2,
- )
if _is_private(self._cls_name, key):
- # also do nothing, name will be a normal attribute
+ # do nothing, name will be a normal attribute
pass
elif _is_sunder(key):
if key not in (
value = value.value
elif _is_descriptor(value):
pass
- # TODO: uncomment next three lines in 3.13
- # elif _is_internal_class(self._cls_name, value):
- # # do nothing, name will be a normal attribute
- # pass
+ elif _is_internal_class(self._cls_name, value):
+ # do nothing, name will be a normal attribute
+ pass
else:
if key in self:
# enum overwriting a descriptor?
if not last_values:
return start
try:
- last = last_values[-1]
- last_values.sort()
- if last == last_values[-1]:
- # no difference between old and new methods
- return last + 1
- else:
- # trigger old method (with warning)
- raise TypeError
+ last_value = sorted(last_values).pop()
except TypeError:
- import warnings
- warnings.warn(
- "In 3.13 the default `auto()`/`_generate_next_value_` will require all values to be sortable and support adding +1\n"
- "and the value returned will be the largest value in the enum incremented by 1",
- DeprecationWarning,
- stacklevel=3,
- )
- for v in last_values:
- try:
- return v + 1
- except TypeError:
- pass
- return start
+ raise TypeError('unable to sort non-numeric values') from None
+ try:
+ return last_value + 1
+ except TypeError:
+ raise TypeError('unable to increment %r' % (last_value, )) from None
@classmethod
def _missing_(cls, value):
)
@unittest.skipIf(
- python_version < (3, 14),
+ python_version < (3, 13),
'inner classes are still members',
)
def test_nested_classes_in_enum_are_not_members(self):
self.assertEqual(Color.green.value, 3)
@unittest.skipIf(
- python_version < (3, 14),
- 'mixed types with auto() will raise in the future',
+ python_version < (3, 13),
+ 'mixed types with auto() will raise in 3.13',
)
def test_auto_garbage_fail(self):
- with self.assertRaisesRegex(TypeError, 'will require all values to be sortable'):
+ with self.assertRaisesRegex(TypeError, "unable to increment 'red'"):
class Color(Enum):
red = 'red'
blue = auto()
@unittest.skipIf(
- python_version < (3, 14),
- 'mixed types with auto() will raise in the future',
+ python_version < (3, 13),
+ 'mixed types with auto() will raise in 3.13',
)
def test_auto_garbage_corrected_fail(self):
- with self.assertRaisesRegex(TypeError, 'will require all values to be sortable'):
+ with self.assertRaisesRegex(TypeError, 'unable to sort non-numeric values'):
class Color(Enum):
red = 'red'
blue = 2
self.assertEqual(Color.blue.value, 'blue')
@unittest.skipIf(
- python_version < (3, 14),
- 'auto() will return highest value + 1 in the future',
+ python_version < (3, 13),
+ 'auto() will return highest value + 1 in 3.13',
)
def test_auto_with_aliases(self):
class Color(Enum):