[Python-Dev] GH-6392: Enum, __contains__, TypeError, and DeprecationWarnings

Ethan Furman ethan at stoneleaf.us
Thu Apr 5 17:17:17 EDT 2018


Oh my!  ;)

So, after the previous discussion about when __contains__ should raise TypeError instead of returning False, it seems 
there are a couple cases where a TypeError should be raised now:

1)  non-enum-instance in EnumClass
2)  anything in enum_instance
3)  non-flag-instance in flag instance

(1) can be True/False if an Enum instance is checked for;
(2) should (and does already) always raise TypeError;
(3) can be True/False when a Flag instance is checked for in another flag instance.

I suspect these are corner cases, and infrequently, if ever, being used incorrectly now, but I would rather have a 
deprecation period in 3.7 instead of just changing in 3.8 to TypeErrors.  To that end I have a PR [1] readay, and would 
appreciate any review, thoughts, and/or comments.

--
~Ethan~

[1] https://github.com/python/cpython/pull/6392


More information about the Python-Dev mailing list