[Python-ideas] IntFlags

Ethan Furman ethan at stoneleaf.us
Sat Mar 7 19:51:18 CET 2015


On 03/07/2015 10:21 AM, Neil Girdhar wrote:
> On Sat, Mar 7, 2015 at 10:05 AM, Ethan Furman wrote:

>> or, even more illustratively, instead of:
>> 
>>   x = Stat(some_Stat_value_from_somewhere)
>>   x &= ~Stat.NOEXEC  # to clear the bit
>> 
>> we can have:
>> 
>>   x = Stat(some_Stat_value_from_somewhere)
>>   x.NOEXEC = False  # much more readable
> 
> Yes, +1 

>> Drat.  Instances of Stat would not be immutuable, but that means they can't be thin wrappers around `int`, doesn't it?
>> Which also means more work around C call sites.  Drat and double-drat.
> 
> Can't your C call sites cast the object to int?

They could, but then you no longer have a drop-in replacement, which is what IntEnum is.  Plus it's a hassle.  So
IntFlag (or whatever it's called) would to be immutable, which means no neat tricks like `obj.bit_name = False`.

> Why do you need ~ at all?  Do any API calls that you want to make want the inverted
> flags?  Isn't the only point of inverting the bits in order to clear a field?

Hopefully somebody else can address this point.

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150307/0fdd0942/attachment-0001.sig>


More information about the Python-ideas mailing list