[Python-ideas] IntFlags

random832 at fastmail.us random832 at fastmail.us
Wed Mar 4 20:52:50 CET 2015


On Wed, Mar 4, 2015, at 10:17, Andrew Barnert wrote:
> One of the big questions that (IIRC) derailed this last time and got it
> dropped from the enum stdlib design was: what does ~ do? Does it give you
> the 2's complement negative integer? What does that display as in the str
> and repr? And, if you add in conversion from an IntFlags to/from a set of
> separate values, as has been suggested again in this thread, how does
> that work? All of this is trivial when you're dealing with C fixed-size
> unsigned ints: ~READ means 15 of the 16 bits (all except the READ bit)
> are set.

str should be ~(READ) obviously. And more generally
~(all|bits|that|are|not|set).

> Another issue that came up was that C flags often have "combined" names
> that are ambiguous: RDWR = RDONLY | WRONLY), 

Nope. You've actually got a different, much worse, issue: traditionally,
RDONLY is 0 (and should be printed if and only if 1 and 2 are not set),
WRONLY is 1, RDWR is 2, and 3 is traditionally invalid and may have a
platform-dependent meaning.


More information about the Python-ideas mailing list