[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
Mon Jan 1 17:16:26 EST 2018
The enum.Flag type solves all this neatly.
On Mon, Jan 1, 2018 at 2:43 PM, Barry Scott <barry at barrys-emacs.org> wrote:
> I'm guessing that what this thread is about is coming up with an API rule
> that makes
> providing a set of boolean options available to a function or class in the
> least error prone way.
> Its the error prone nature of integer bit masks that is behind the enum
> suggestion I assume.
> From the C tradition we have the integer bit mask which is error prone as
> there is no type checking that the masks belong to the option flags.
> Some APIs use calls with lots of keyword args that you set true or false
> and even none to mean default.
> The suggestion for a set of enums from this thread. You would need a class
> to represent a set of a particular enum to get type safety.
> List of strings or enums.
> You could even use a class that represents the options and set up an
> instance and pass it in. Hard to get wrong.
> I can see that all these styles have their place and each designer will
> pick the style they think fits the API they
> are designing.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas