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

Steven D'Aprano steve at pearwood.info
Wed Dec 27 00:56:39 EST 2017


On Tue, Dec 26, 2017 at 12:07:52PM -0800, Paddy3118 wrote:

> Maybe it is time to deemphasize the creation and passing of what is, in 
> effect, bit-sets <https://en.wikipedia.org/wiki/Bit_array>as a single 
> argument, and instead promote the passing of a set of members of an 
> enum.Enum <https://docs.python.org/3/library/enum.html> constants.

That implies that we are promoting bit sets (not merely using them). 
Where are we doing that?


> Thi comes about because someone wrote a description, (since deleted), 

"Someone"? One of the Python core developers?

If not, well, the Python devs cannot be held responsible for what random 
people on the internet write.


> of 
> constructing bit-sets to use in passing flags to, for example, the 
> re.compile <https://docs.python.org/3/library/re.html#re.compile>function. 
> The use of individual bits in a bit-array/bit-set to pass multiple flags is 
> an implementation detail.

It certainly is not an implementation detail -- it is a part of the 
public, published interface to the re module.

Of course had history been different, re.compile *could* have taken a 
set of Enums instead. But that doesn't make it an implementation detail. 
That would be like saying that:

   re.search(pattern, text, flags=0)

is an implementation detail, and we should feel free to change it to

   re.examine(text, pattern, set_of_enums=frozenset())

We can't change a public interface documented as taking an integer to 
one taking a set of Enums without going through a deprecation period.

However, we could *add* an additional interface, where the re functions 
that currently accept an integer flag *also* accepts a set of Enums.


> Should we not *first *teach the passing of a set 
> of enum.Enum constant values in one argument as the *pythonic *way;

What makes you say that is the Pythonic way? (That's not a rhetorical 
question.)


-- 
Steve


More information about the Python-ideas mailing list