[Python-ideas] IntFlags

Cameron Simpson cs at zip.com.au
Thu Mar 5 23:34:03 CET 2015


On 03Mar2015 17:52, Serhiy Storchaka <storchaka at gmail.com> wrote:
>Enum and IntEnum classes allow constants to have nice str() and repr() 
>representations. [...]
>3. It should have nice str() and repr().
>>>> print(stat.S_IROTH | stat.S_IWOTH)
>stat.S_IROTH|stat.S_IWOTH
>>>> stat.S_IROTH | stat.S_IWOTH
><StatFlags.S_IROTH|S_IWOTH: 6>

Regarding this one, and regarding some of the later discussion about 
"meaningless" values from some operations, when I wrote my _Clock_Flags I made 
the repr() pull off known flags and include the remainer if not zero. So your 
example above would come out:

  <StatFlags S_IROTH|S_IWOTH 0>
and:
  <StatFlags S_IROTH|S_IWOTH 32>

if there was an extra unknown "32" bit in the mix.

On reflection, I'd like these to come out:

  <StatFlags S_IROTH|S_IWOTH>
  <StatFlags S_IROTH|S_IWOTH|32>

(with space or "." or whatever).

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

Isaac Asimov once remarked that friends had chided him for not patenting the
electronic pocket calculator, since he wrote of similar devices back in the
1940's.  His reply, "Have you ever noticed I only described what it looked
like on the *outside*?" - ijl at mediaone.net


More information about the Python-ideas mailing list