mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-33217: Raise TypeError for non-Enum lookups in Enums (GH-6651)
* bpo-33217: Raise TypeError for non-Enum lookups in Enums
This commit is contained in:
parent
51a4743d19
commit
9430652535
4 changed files with 62 additions and 5 deletions
|
@ -303,6 +303,10 @@ class EnumMeta(type):
|
|||
return cls._create_(value, names, module=module, qualname=qualname, type=type, start=start)
|
||||
|
||||
def __contains__(cls, member):
|
||||
if not isinstance(member, Enum):
|
||||
raise TypeError(
|
||||
"unsupported operand type(s) for 'in': '%s' and '%s'" % (
|
||||
type(member).__qualname__, cls.__class__.__qualname__))
|
||||
return isinstance(member, cls) and member._name_ in cls._member_map_
|
||||
|
||||
def __delattr__(cls, attr):
|
||||
|
@ -705,7 +709,9 @@ class Flag(Enum):
|
|||
|
||||
def __contains__(self, other):
|
||||
if not isinstance(other, self.__class__):
|
||||
return NotImplemented
|
||||
raise TypeError(
|
||||
"unsupported operand type(s) for 'in': '%s' and '%s'" % (
|
||||
type(other).__qualname__, self.__class__.__qualname__))
|
||||
return other._value_ & self._value_ == other._value_
|
||||
|
||||
def __repr__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue