-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
TYP: semantics of enums in stub files changed #29362
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
Conversation
The issue is that we define an Enum subclass that has no members (because we subsequently sub-class it to add the actual values), I have a 🔨 solution. |
lib/matplotlib/_enums.py
Outdated
def _generate_next_value_(name, start, count, last_values): | ||
return name | ||
|
||
def __hash__(self): | ||
return str(self).__hash__() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these in all of the classes?
- Can we just explicitly list the string enumeration rather than auto?
miter = "miter"
(a bit odd we didn't go with caps for the enumJointStyle.MITER
is typically how I see them written... - Does
__hash__
not get string's hash automatically from subclassing?
edit: also a bummer we can't just directly go to StrEnum which looks like it was only released in 3.11: https://docs.python.org/3/library/enum.html#enum.StrEnum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"all" is only two, but this also seems to have also not worked (other attempts failed on import...this imported but made the tests fail).
e702b06
to
18d42a6
Compare
4c2aa05
to
57f95dd
Compare
Sigh, I thought it was working locally because I was using an old mypy 😞 |
57f95dd
to
5837e94
Compare
ok, 5th times the charm! @greglucas noted that On the other hand, doing a conditional import on |
2981b1f
to
45325ad
Compare
- The definition of `__hash__` was doing nothing - having a copy of a 1 line function in two sub-classes is simpler than having doing inheritance - fixes an issues with mypy failing on an Enum class with no entries
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
bbe91c9
to
91b26c3
Compare
I've taken the liberty to add the missing space and force-push to keep the sequence of commits. The way they are written, I assume they should not be squashed. |
…362-on-v3.10.x Backport PR #29362 on branch v3.10.x (TYP: semantics of enums in stub files changed)
@meeseeksdev backport to v3.10.0-doc |
See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members for details
I think this fix the mypy failures that have started happening on all PRs.