diff options
author | Rahul Jha <rj722@protonmail.com> | 2018-09-10 18:21:04 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2018-09-10 18:21:04 (GMT) |
commit | 9430652535f88125d8003f342a8884d34885d876 (patch) | |
tree | d0b6fff5561ab141a9209c9f78c242979b94e222 /Lib/enum.py | |
parent | 51a4743d19abd016f0772a57fb31df7af9220e18 (diff) | |
download | cpython-9430652535f88125d8003f342a8884d34885d876.zip cpython-9430652535f88125d8003f342a8884d34885d876.tar.gz cpython-9430652535f88125d8003f342a8884d34885d876.tar.bz2 |
bpo-33217: Raise TypeError for non-Enum lookups in Enums (GH-6651)
* bpo-33217: Raise TypeError for non-Enum lookups in Enums
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 04d8ec1..9d1aef3 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -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): |