mirror of
https://github.com/python/cpython.git
synced 2025-08-08 02:48:55 +00:00
[3.12] gh-131045: [Enum] fix flag containment checks when using values (GH-131053) (#131232)
* gh-131045: [Enum] fix flag containment checks when using values (GH-131053) Check would fail if value would create a pseudo-member, but that member had not yet been created. We now attempt to create a pseudo-member for a passed-in value first. --------- Co-authored-by: Ethan Furman <ethan@stoneleaf.us> Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
This commit is contained in:
parent
7f2de07808
commit
8a9aee7126
3 changed files with 9 additions and 1 deletions
|
@ -771,10 +771,15 @@ class EnumType(type):
|
|||
`value` is in `cls` if:
|
||||
1) `value` is a member of `cls`, or
|
||||
2) `value` is the value of one of the `cls`'s members.
|
||||
3) `value` is a pseudo-member (flags)
|
||||
"""
|
||||
if isinstance(value, cls):
|
||||
return True
|
||||
return value in cls._value2member_map_ or value in cls._unhashable_values_
|
||||
try:
|
||||
cls(value)
|
||||
return True
|
||||
except ValueError:
|
||||
return value in cls._unhashable_values_
|
||||
|
||||
def __delattr__(cls, attr):
|
||||
# nicer error message when someone tries to delete an attribute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue