Visitar URL original
bpo-44929: Fix enum string representation in the REPL by pablogsal · Pull Request #27789 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20250819001032/https://github.com/python/cpython/pull/27789
Skip to content

bpo-44929: Fix enum string representation in the REPL #27789

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

Merged
merged 5 commits into from
Aug 25, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Aug 16, 2021 •

@pablogsal pablogsal requested a review from ethanfurman as a code owner August 16, 2021 22:16
@pablogsal pablogsal changed the title Fix enum string representation in the REPL bpo-44929: Fix enum string representation in the REPL Aug 16, 2021
@ambv
Copy link
Contributor

ambv commented Aug 18, 2021

The entire global_flag_repr function is wrong and untested. I added a few failing tests for now, I'm not sure how they should be fixed since I can't figure out what the intent is from the docs.

Lib/enum.py Outdated
@@ -1396,7 +1396,7 @@ def global_flag_repr(self):
module = self.__class__.__module__
cls_name = self.__class__.__name__
if self._name_ is None:
return "%x" % (module, cls_name, self._value_)
return "%s.%s(%x)" % (module, cls_name, self._value_)
Copy link
Member

Choose a reason for hiding this comment

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

Do any of the unittests test this particular format codepath? none of the added tests have reprs that end with (0x8) or similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, no, I couldn't quite figure out how to make _name_ to be None. When we hear back from Ethan, he'll hopefully suggest a test for this, too. Worst case we can just add a test using repr(re.RegexFlag(0)).

Copy link
Member

Choose a reason for hiding this comment

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

@ethanfurman ethanfurman self-assigned this Aug 21, 2021
ethanfurman
ethanfurman previously approved these changes Aug 21, 2021
Copy link
Member

@ethanfurman ethanfurman left a comment

Choose a reason for hiding this comment

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

Fixed tests and global reprs. Thank you.

@ethanfurman ethanfurman dismissed their stale review August 21, 2021 21:13

Still need test for _name_ is None branch.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@ethanfurman ethanfurman merged commit 24da544 into python:main Aug 25, 2021
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.

6 participants