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-40066: [Enum] update str() and format() output #30582

Merged
merged 26 commits into from
Jan 16, 2022

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman commented Jan 13, 2022

@AlexWaygood
Copy link
Member

Omg, did not mean to close that at all — sorry!!

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work! Enums' text representation looks way better now.

Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Lib/enum.py Show resolved Hide resolved
Lib/enum.py Outdated Show resolved Hide resolved
Lib/enum.py Show resolved Hide resolved
Lib/enum.py Outdated Show resolved Hide resolved
Lib/enum.py Outdated Show resolved Hide resolved
@ethanfurman ethanfurman merged commit acf7403 into python:main Jan 16, 2022
@AlexWaygood
Copy link
Member

This change appears to be causing CI to fail on docs for unrelated PRs ☹️ https://github.com/python/cpython/runs/4831439882?check_suite_focus=true

@AdamWill
Copy link
Contributor

I'm curious: why does this define a __init__ for Enum which does nothing at all (just pass)?

It causes pylint to start throwing warnings about subclasses of Enum which have their own __init__ not calling super's __init__, which Python's own docs and examples don't say they should, and which of course would be pointless since it does nothing. I'm sending a PR for pylint to not emit this warning for subclasses of Enum, but I don't understand why the do-nothing __init__ was added at all.

@@ -2567,30 +2567,28 @@ class _empty:


class _ParameterKind(enum.IntEnum):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that inheritting correct where the values are changed to str?

Copy link
Member Author

@ethanfurman ethanfurman Nov 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gryznar Good question: only because the __new__ uses integers as the values, and the "value" on the assignment line is saved in the description attribute. Without the custom __new__ the enum creation would have failed, since strings are not integers.

@@ -427,8 +431,8 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k
# check for illegal enum names (any others?)
invalid_names = set(member_names) & {'mro', ''}
if invalid_names:
raise ValueError('Invalid enum member name: {0}'.format(
','.join(invalid_names)))
raise ValueError('invalid enum member name(s) '.format(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removing "{0}" proper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gryznar Only because it was changed to %s later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants