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: Tomas R. <tomas.roun8@gmail.com>
This commit is contained in:
Ethan Furman 2025-03-12 12:10:47 -07:00 committed by GitHub
parent db6a998b18
commit 17d06aeb54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 2 deletions

View file

@ -739,12 +739,14 @@ 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
try:
return value in cls._value2member_map_
except TypeError:
cls(value)
return True
except ValueError:
return (
value in cls._unhashable_values_ # both structures are lists
or value in cls._hashable_values_