GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Default enum.FlagBoundary should be KEEP? · Issue #93250 · python/cpython

Default enum.FlagBoundary should be KEEP? #93250

New issue
Copy link
New issue
Copy link
Closed
Closed
Default enum.FlagBoundary should be KEEP?#93250
Copy link
Assignees
ethanfurman
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@philthompson10
philthompson10
opened on May 26, 2022
Issue body actions

The FlagBoundary added to enums in Python v3.11 has defaults that break compatibility with previous versions. Shouldn't the default initially be KEEP, with a deprecation warning that it will be changed in a future version?

Activity

  1. philthompson10
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 26, 2022
  2. AlexWaygood
    added
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on May 26, 2022
  3. AlexWaygood
    assigned
    ethanfurman
    on May 26, 2022
  4. The-Compiler commented on May 26, 2022

    @The-Compiler
    The-Compiler
    on May 26, 2022
    Contributor
    More actions

    For some context: Python 3.11 and mixing of enum.IntFlag.

    Reproducer:

    import enum
    A = enum.IntFlag("A", {"x": 1})
    B = enum.IntFlag("B", {"y": 2})
    val = A.x | B.y
    print(val, type(val))
    $ python3.10 -c 'import enum; A = enum.IntFlag("A", {"x": 1}); B = enum.IntFlag("B", {"y": 2}); val = A.x | B.y; print(val, type(val))'
    A.B.y|x <enum 'A'>
    

    but

    $ python3.11 -c '...'
    3 <class 'int'>
    

    Relevant commit: 7aaeb2a ("bpo-38250: [Enum] single-bit flags are canonical (GH-24215)").

  5. ethanfurman commented on May 26, 2022

    @ethanfurman
    ethanfurman
    on May 26, 2022
    Member
    More actions

    Are you concerned that the repr() has changed, or that the result is no longer of type flag?

  6. philthompson10 commented on May 26, 2022

    @philthompson10
    philthompson10
    on May 26, 2022
    Author
    More actions

    The change in type is the problem.

  7. ethanfurman commented on May 26, 2022

    @ethanfurman
    ethanfurman
    on May 26, 2022
    Member
    More actions

    Changing the default to KEEP make sense.

    Out of curiosity, and ignoring backwards compatibility, do you think the default for an IntFlag should be KEEP or EJECT?

  8. philthompson10 commented on May 27, 2022

    @philthompson10
    philthompson10
    on May 27, 2022
    Author
    More actions

    I don't feel comfortable with the type being different depending on the values provided, so I don't like EJECT as a default as the behaviour might be too surprising.

    My use case is atypical. I am wrapping the enums of a C++ library and can't guarantee that the wrappers know about all the possible values that the library might provide. KEEP solves this problem. I have the same problem with Enum and IntEnum and have effectively implemented KEEP for those by providing them with an appropriate implementation of _missing_.

    Note that my original concern was about the lack of the usual deprecation cycle for a change in behaviour rather than the change itself.

  9. ethanfurman
    added a commit that references this issue on May 27, 2022

    gh-93250: [Enum] Change IntEnum boundary to KEEP for backwards compat…

    70cfe56
  10. miss-islington
    added a commit that references this issue on May 27, 2022

    pythongh-93250: [Enum] Change IntEnum boundary to KEEP for backwards …

    ba3cf54
  11. ethanfurman
    added a commit that references this issue on May 27, 2022

    gh-93250: [Enum] Change IntEnum boundary to KEEP for backwards compat…

    647426d
  12. ethanfurman commented on May 27, 2022

    @ethanfurman
    ethanfurman
    on May 27, 2022
    Member
    More actions

    KEEP restored as the default, and likely to stay that way -- an early design decision was to persist the flag type for bit-wise operations. The exact flag type and behavior will depend on the left-most operand.

    Reacted by Freya Bruhin
  13. ethanfurman
    closed this as completedon May 27, 2022
  14. The-Compiler
    added a commit that references this issue on May 30, 2022

    Patch PyQt6 QUrl flag behavior for Python 3.11

    14c1593
  15. The-Compiler
    added 5 commits that reference this issue on Jun 17, 2022

    Patch PyQt6 QUrl flag behavior for Python 3.11

    81094be

    Patch PyQt6 QUrl flag behavior for Python 3.11

    30012ca

    Patch PyQt6 QUrl flag behavior for Python 3.11

    b6a22a5

    Patch PyQt6 QUrl flag behavior for Python 3.11

    2538015

    Patch PyQt6 QUrl flag behavior for Python 3.11

    6b1f21d
  16. The-Compiler
    added 3 commits that reference this issue on Aug 22, 2022

    Patch PyQt6 QUrl flag behavior for Python 3.11

    081fb3e

    Patch PyQt6 QUrl flag behavior for Python 3.11

    80d4ae3

    Patch PyQt6 QUrl flag behavior for Python 3.11

    4de0e90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ethanfurman
    ethanfurman

Labels

3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.