[issue38250] enum.Flag should be more set-like

John Belmonte report at bugs.python.org
Sun Oct 11 17:26:22 EDT 2020


John Belmonte <john at neggie.net> added the comment:

> Just a comment, (1) is analogous to str. iter('abc') gives only 'a', 'b' and 'c', while contains accepts '', 'ab', 'bc', and 'abc' too. At least in my mind, it's a pretty strong analogy.

I don't agree.  The "zero" bit does not exist, so having __contains__ return True on `Foo(0) in x` is misaligned with the iterator.  And having __contains__ return True for specific compound values just because they happen to be explicitly defined, while returning False for others, is arbitrary.  __contains__ seems to be of very little use, and moreover a trap for the unwary.  Assuming we have to live with that until Python 4, it's better to make an explicit iterator like `bits()` so that the API doesn't contradict itself.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38250>
_______________________________________


More information about the Python-bugs-list mailing list