[Python-ideas] IntFlags

Luciano Ramalho luciano at ramalho.org
Thu Mar 5 18:20:27 CET 2015


On Thu, Mar 5, 2015 at 2:14 PM, Eugene Toder <eltoder at gmail.com> wrote:
> The flags discussed so far are unordered as well. E.g. OpenMode.RDONLY | OpenMode.WRONLY | OpenMode.CLOEXEC == OpenMode.RDONLY | OpenMode.CLOEXEC | OpenMode.WRONLY or any other permutation. In other words, flags (aka bitmasks) are just an optimized representation of an (unordered) set of small integer values.

I agree that they are unordered in the common use cases. But the kind
of low-level code where such flags are used often involves building a
byte or a word out of those flags to pass to a low-level C API. How do
you make sure that the byte you will build makes sense if you don't
care about the position, or the log2 of each flag value? So I
definitely think ordering and positioning are to be preserved in a
data structure intended to manage and combine bits.

Best,

Luciano




-- 
Luciano Ramalho
Twitter: @ramalhoorg

Professor em: http://python.pro.br
Twitter: @pythonprobr


More information about the Python-ideas mailing list