mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Refs #32074 -- Fixed TextChoices/IntegerChoices crash on Python 3.10.
EnumMeta has a new keyword argument 'boundary' in Python 3.10. This is a new mechanism that controls how out-of-range / invalid bits are handled, see https://bugs.python.org/issue38250.
This commit is contained in:
parent
aa29c57bee
commit
5d9b065d3f
@ -8,7 +8,7 @@ __all__ = ['Choices', 'IntegerChoices', 'TextChoices']
|
|||||||
class ChoicesMeta(enum.EnumMeta):
|
class ChoicesMeta(enum.EnumMeta):
|
||||||
"""A metaclass for creating a enum choices."""
|
"""A metaclass for creating a enum choices."""
|
||||||
|
|
||||||
def __new__(metacls, classname, bases, classdict):
|
def __new__(metacls, classname, bases, classdict, **kwds):
|
||||||
labels = []
|
labels = []
|
||||||
for key in classdict._member_names:
|
for key in classdict._member_names:
|
||||||
value = classdict[key]
|
value = classdict[key]
|
||||||
@ -25,7 +25,7 @@ class ChoicesMeta(enum.EnumMeta):
|
|||||||
# Use dict.__setitem__() to suppress defenses against double
|
# Use dict.__setitem__() to suppress defenses against double
|
||||||
# assignment in enum's classdict.
|
# assignment in enum's classdict.
|
||||||
dict.__setitem__(classdict, key, value)
|
dict.__setitem__(classdict, key, value)
|
||||||
cls = super().__new__(metacls, classname, bases, classdict)
|
cls = super().__new__(metacls, classname, bases, classdict, **kwds)
|
||||||
cls._value2label_map_ = dict(zip(cls._value2member_map_, labels))
|
cls._value2label_map_ = dict(zip(cls._value2member_map_, labels))
|
||||||
# Add a label property to instances of enum which uses the enum member
|
# Add a label property to instances of enum which uses the enum member
|
||||||
# that is passed in as "self" as the value to use when looking up the
|
# that is passed in as "self" as the value to use when looking up the
|
||||||
|
Loading…
Reference in New Issue
Block a user