[Python-ideas] IntFlags

Cameron Simpson cs at zip.com.au
Thu Mar 5 23:42:11 CET 2015


On 05Mar2015 19:26, Serhiy Storchaka <storchaka at gmail.com> wrote:
>On 05.03.15 18:15, Luciano Ramalho wrote:
>>I don't like the name IntFlags: BitFlags makes more sense to me, since
>>the key feature is supporting bitwise operators.
>
>I chose this name because the concept IntFlags is very similar to the 
>concept of Flags enums in C#. The Flags decorator in C# is as close to 
>IntFlags as enums in C# close to IntEnum. The Int prefix is here 
>because IntFlags is just an funny int (as IntEnum) and both IntFlags 
>and IntEnum are purposed to replace int constants.
>
>>Calling it BitFlags has the additional advantage of making it very
>>clear that it's not closely related to IntEnum.
>
>But it is closely related to IntEnum. Both are int subclass and fully 
>compatible with ints, both provides named constants, both have funny 
>str and repr, both inherit common useful interface from Enum, both are 
>purposed to replace integer constants.

I also prefer IntFlags, like IntEnum.

I certainly have use cases where I do not care that there is an underlying 
numeric value, and am treating things like a set. But with fixed names (versus 
sets, which are open ended in their native form) and using an int underneath is 
both efficient an natural.

But conversely, I have use cases where I do care.

I am -1 on BitFlags.

Cheers,
Cameron Simpson <cs at zip.com.au>

You can be psychotic and still be competent.
        - John L. Young, American Academy of Psychiatry and the Law on Ted
          Kaczynski, and probably most internet users


More information about the Python-ideas mailing list