bpo-32218: make Flag
and IntFlag
members iterable by ethanfurman · Pull Request #22221 · python/cpython (original) (raw)
I have become increasingly unhappy with the the multiple calls to _decompose. Your ideas (and others, too) are welcome.
I do have ideas on it, and intended to open a separate issue for refactoring _decompose()
and make a PR replacing it with something simpler, faster, and less buggy. (E.g. use the _bits()
iterator; and I noticed that all callers of it either use the members
or extra_flags
output, never both; and the computation of extra_flags
would be trivial if we had an __all__
attribute on the class.)
Regarding bugs, when it's used by repr()
or str()
, I don't think it's intended that a lone compound value is represented as-is, while a compound plus other value is represented as a redundant "compound plus underlying bits":
class Foo(Flag): ... A = auto() ... B = auto() ... C = auto() ... BC = B | C repr(Foo.BC) '<Foo.BC: 6>' repr(Foo.A | Foo.BC) '<Foo.BC|C|B|A: 7>'