[Python-ideas] a set of enum.Enum values rather than the construction of bit-sets as the "norm"?
MRAB
python at mrabarnett.plus.com
Sun Dec 31 12:09:34 EST 2017
On 2017-12-31 08:13, Paddy3118 wrote:
> Hmm, yea I had not thought of how it would look - I had thought formost
> of not needing to necessarily learn about bitsets.when learning about
> passing a large number of optional flags to a function.
>
> Although the default could be None, interpreted as an empty set of zero
> values.; a set of one or more enums does use more characters compared to
> or-ing flags...
>
None is often used to represent a default, which might not be an empty set.
> On Sunday, 31 December 2017 05:34:23 UTC, Guido van Rossum wrote:
>
> On Sat, Dec 30, 2017 at 8:50 PM, Franklin? Lee
> <leewangzh... at gmail.com <javascript:>> 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.
>
More information about the Python-ideas
mailing list