[Python-ideas] IntFlags

Nick Coghlan ncoghlan at gmail.com
Tue Mar 10 13:51:30 CET 2015


On 10 March 2015 at 01:54, Neil Girdhar <mistersheik at gmail.com> wrote:
> The differences are that the flags are used in a tiny portion of Python
> code, and of that tiny amount of code, 99% of it probably uses nothing more
> than the minimum "flags interface" that the composition solution has.  bool
> was not like that.  Changing bool to be its own type would led to many more
> problems.

The flag values in modules like "stat" and "socket" are not niche use
cases where we can be cavalier with backwards compatibility concerns,
as they get passed to operating system level APIs both inside and
outside the standard library. Most application level code will never
need to touch those modules, but system boundary code does it all the
time. It's the exact same rationale as was used for adopting IntEnum
in the socket and errno modules rather than the base Enum class.

There's likely no need to get especially creative with the overall
design here, as the 3.4 enum module should provide a good general
architecture to follow, it's just the runtime behaviour that will be
changing to be "ordered collection of combinatorial flags" rather than
"ordered collection of named values".

The main question in my mind is whether you might want named bitmask
support as well, but that's probably not worth the extra complexity,
since you don't need it for debugging purposes.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list