[Python-ideas] IntFlags

Chris Angelico rosuav at gmail.com
Wed Mar 4 17:04:09 CET 2015


On Thu, Mar 5, 2015 at 2:58 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> On 04.03.15 17:31, Chris Angelico wrote:
>>
>> On Thu, Mar 5, 2015 at 2:17 AM, Andrew Barnert
>> <abarnert at yahoo.com.dmarc.invalid> wrote:
>>>
>>> Another issue that came up was that C flags often have "combined" names
>>> that are ambiguous: RDWR = RDONLY | WRONLY), which is fine until you want a
>>> repr (in C, it's just going to print 3); does it have to be smart enough to
>>> show RDWR? (Or, worse, RDWR | CLOEXEC.)
>>
>> That could probably be handled by going through the flags in iteration
>> order. If the flag is present, emit it and move on. Something like
>> this:
>
>
> Yes, something like this, but with iterating flags in descended sorted
> order, and with special case for negative value.

Sure. Going automatically like that is a way of guaranteeing that the
combined flags will be used, which is probably what you want most of
the time anyway. And yes, I hadn't coped with negatives in that.

ChrisA


More information about the Python-ideas mailing list