Skip to content

Don't make underscored attributes as enum members #8302

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 4 commits into from
Jan 17, 2020
Merged

Don't make underscored attributes as enum members #8302

merged 4 commits into from
Jan 17, 2020

Conversation

TH3CHARLie
Copy link
Collaborator

fixes #5312

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

@bluetech
Copy link
Contributor

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 😄

@TH3CHARLie
Copy link
Collaborator Author

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!

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

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
@TH3CHARLie TH3CHARLie deleted the fix-5312 branch January 17, 2020 13:44
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.

Private property in subclass of Enum is not indexable
3 participants