Visitar URL original
bpo-43945: [Enum] reduce scope of new format() behavior by ethanfurman · Pull Request #26752 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223114907/https://github.com/python/cpython/pull/26752
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-43945: [Enum] reduce scope of new format() behavior #26752

Merged
merged 4 commits into from Jun 18, 2021

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman commented Jun 16, 2021 •

Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected. In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

class Grades(int, Enum):
    A = 5
    B = 4
    C = 3
    D = 2
    F = 0

Now: format(Grades.B) -> DeprecationWarning and '4'
3.12: -> no warning, and 'B'

https://bugs.python.org/issue43945

ethanfurman added 3 commits Jun 16, 2021
Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected.  In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

    class Grades(int, Enum):
        A = 5
        B = 4
        C = 3
        D = 2
        F = 0

Now:  format(Grades.B)  -> DeprecationWarning and '4'
3.12:                   -> no warning, and 'B'
clarify the backwards-compatible requirements of IntEnum, StrEnum and
IntFlag

add tests to cover user mixed-in int and str types
@ethanfurman ethanfurman merged commit f60b07a into python:main Jun 18, 2021
12 of 13 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Jun 18, 2021

Thanks @ethanfurman for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

miss-islington commented Jun 18, 2021

Sorry, @ethanfurman, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker f60b07ab6c943fce084772c3c7731ab3bbd213ff 3.10

ethanfurman added a commit that referenced this pull request Jun 18, 2021
…6752)

* [Enum] reduce scope of new format behavior

Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected.  In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

    class Grades(int, Enum):
        A = 5
        B = 4
        C = 3
        D = 2
        F = 0

Now:  format(Grades.B)  -> DeprecationWarning and '4'
3.12:                   -> no warning, and 'B'.
                    (cherry picked from commit f60b07a)

                    Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@bedevere-bot
Copy link

bedevere-bot commented Jun 18, 2021

GH-26791 is a backport of this pull request to the 3.10 branch.

ethanfurman added a commit that referenced this pull request Jun 18, 2021
)

* [Enum] reduce scope of new format behavior

Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected.  In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

    class Grades(int, Enum):
        A = 5
        B = 4
        C = 3
        D = 2
        F = 0

Now:  format(Grades.B)  -> DeprecationWarning and '4'
3.12:                   -> no warning, and 'B'.

(cherry picked from commit f60b07a)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@ethanfurman ethanfurman deleted the enum-new_format branch Jun 19, 2021
jdevries3133 pushed a commit to jdevries3133/cpython that referenced this pull request Jun 19, 2021
* [Enum] reduce scope of new format behavior

Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected.  In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

    class Grades(int, Enum):
        A = 5
        B = 4
        C = 3
        D = 2
        F = 0

Now:  format(Grades.B)  -> DeprecationWarning and '4'
3.12:                   -> no warning, and 'B'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants