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

Don't make underscored attributes as enum members #8302

Merged
merged 4 commits into from Jan 17, 2020
Merged

Conversation

@TH3CHARLie
Copy link
Contributor

TH3CHARLie commented Jan 17, 2020

fixes #5312

From @JelleZijlstra 's description, for underscored attributes, we don't make them as enum members

TH3CHARLie added 3 commits Jan 17, 2020
@bluetech

This comment has been minimized.

Copy link
Contributor

bluetech commented Jan 17, 2020

A bit silly, but the output of this program

import enum

class E(enum.Enum):
    _ = 1
    __ = 2
    ___ = 3
    ____ = 4
    _____ = 5
    __a__ = 6

print([e.value for e in E])

is [1, 2, 3, 4, 5], but your check if name.startswith('__') and name.endswith("__") rejects 2, 3, 4 and 5 😄

fix
@TH3CHARLie

This comment has been minimized.

Copy link
Contributor Author

TH3CHARLie commented Jan 17, 2020

print([e.value for e in E])

Good catch, I wouldn't think anyone would write code like this but it is definitely a valid case, thanks!

@JukkaL
JukkaL approved these changes Jan 17, 2020
Copy link
Collaborator

JukkaL left a comment

Looks great! Thanks for also refactoring the code into a new function. It makes the code easier to read and understand.

@JukkaL JukkaL merged commit 861f01c into python:master Jan 17, 2020
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@TH3CHARLie TH3CHARLie deleted the TH3CHARLie:fix-5312 branch Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.