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

John Belmonte report at bugs.python.org
Sun Oct 11 10:24:15 EDT 2020


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

Part of this issue (#1) was intended to be addressed by https://github.com/python/cpython/pull/22221 which added an `__iter__` implementation to Flag and IntFlag.  (The PR did not reference this issue, and was already merged last month.)

However that PR seems problematic on several counts:
   1. `__iter__` diverges from the existing `__contains__`.  The latter includes 0 and compound values
   2. the implementation is fairly heavy
   3. len() on an enum instance is going to be O(n)

I've put post-merge comments on the PR.

I think it would be safer to have an explicitly named `bits()` iterator on flag instances, rather than use `__iter__()`.

----------
keywords: +patch
message_count: 3.0 -> 4.0
pull_requests: +21621
stage:  -> patch review
versions: +Python 3.10 -Python 3.9
pull_request: https://github.com/python/cpython/pull/22221

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


More information about the Python-bugs-list mailing list