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

Barry Scott barry at barrys-emacs.org
Mon Jan 1 16:43:31 EST 2018


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.

Barry



More information about the Python-ideas mailing list