[Python-ideas] a set of enum.Enum values rather than the construction of bit-sets as the "norm"?

Guido van Rossum guido at python.org
Sun Dec 31 00:39:33 EST 2017

I should probably clarify that for this to work, Foo must derive from
enum.Flags. See https://docs.python.org/3/library/enum.html#flag.
(Or enum.IntFlag, https://docs.python.org/3/library/enum.html#intflag.)

Note that when using Flag, you can name the "zero" value (Color.BLACK in
the 3rd example). When using IntFlag, you just use 0.

On Sat, Dec 30, 2017 at 9:33 PM, Guido van Rossum <guido at python.org> wrote:

> On Sat, Dec 30, 2017 at 8:50 PM, Franklin? Lee <
> leewangzhong+python at gmail.com> wrote:
>> Paddy might want something like this:
>> - For existing APIs which take int or IntFlag flags, allow them to
>> also take a set (or perhaps any collection) of flags.
>> - In new APIs, take sets of Enum flags, and don't make them IntFlag.
>> - Documentation should show preference toward using sets of Enum
>> flags. Tutorials should pass sets.
> I'm not keen on this recommendation. An argument that takes a Set[Foo]
> would mean that in order to specify:
> - no flags: you'd have to pass set() -- you can't use {} since that's an
> empty dict, not an empty set
> - one flag: you'd have to pass {Foo.BAR} rather than just Foo.BAR
> - two flags: you'd have to pass {Foo.BAR, Foo.BAZ} rather than Foo.BAR |
> Foo.BAZ
> I think for each of these the proposal would be strictly worse than the
> current convention.
> --
> --Guido van Rossum (python.org/~guido)

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171230/23aeb988/attachment-0001.html>

More information about the Python-ideas mailing list