[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Ethan Furman
Ethan Furman added the comment: Strings are actually the odd-man out -- dicts, sets, lists, tuples, etc., all return False instead of raising TypeError. The reason str raises an error is because `in`, for str, is a substring check, not a membership check. --

[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Dutcho
Dutcho added the comment: Ah, the mixin logic mentioned in 33219 solves most of my objections to returning False; agree that would make sense Only remaining inconsistency would be with 1 in 'hello' -- ___ Python tracker

[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Dutcho
Dutcho added the comment: Fully agree that Flag.__contains__ must RETURN False or True; that's why I suggested it RAISES TypeError The exception was to be consistent with e.g. Flag.__and__, which by returning NotImplemented transfers to type(other).__rand__, and assuming

[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Ethan Furman
Ethan Furman added the comment: Thanks for finding this! However, TypeError, an exception, is not the correct type of answer -- the correct type of answer for a yes/no question is either True or False. So the code should be changed from returning NotImplemented to

[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Ethan Furman
Change by Ethan Furman : -- assignee: -> ethan.furman nosy: +barry, eli.bendersky, ethan.furman versions: +Python 3.7, Python 3.8 ___ Python tracker

[issue33217] x in enum.Flag() is True when x is no Flag

2018-04-03 Thread Dutcho
New submission from Dutcho : While `Flag() in Flag()` and `Flag() | Flag()` result in the expected outcomes, e.g. `str() in Flag()` unexpectedly returns `True`, whereas `Flag() | str()` as expected raises a TypeError. >>> import enum >>> ABC = enum.Flag('ABC', 'a, b,