Skip to content

IntFlag breaks backward compatibility with __repr__ #140703

@Brendon-Mendicino

Description

@Brendon-Mendicino

Bug report

Bug description:

I was doing some testing with doctest for my python library, I noticed that the CI was failing for python3.10. The issue is that the __repr__ for IntFlag (but I assume for Flag in general) breaks backward compatibility due to printing the flags in reverse order.

from enum import IntFlag

class Flag(IntFlag):
    A = 1 << 0
    B = 1 << 1
    C = 1 << 2

print(f"{Flag.B | Flag.C!r}")
# output in python 3.10:
# <Flag.C|B: 6>
# output in python 3.11 onwards
# <Flag.B|C: 6>

CPython versions tested on:

3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions