Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 4 commits intomatplotlib:mainfromtacaswell:fix/mypy_enum_semantics
Dec 21, 2024

Conversation

tacaswell
Copy link
Member

Seehttps://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.

@tacaswell
Copy link
MemberAuthor

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.

Comment on lines 72 to 77
def _generate_next_value_(name, start, count, last_values):
return name

def __hash__(self):
return str(self).__hash__()

Copy link
Contributor

@greglucasgreglucasDec 20, 2024
edited
Loading

Choose a reason for hiding this comment

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

Do we reallyneed 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

Copy link
MemberAuthor

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).

greglucas reacted with thumbs up emoji
@tacaswell
Copy link
MemberAuthor

Sigh, I thought it was working locally because I was using an old mypy 😞

@tacaswell
Copy link
MemberAuthor

ok, 5th times the charm!

@greglucas noted that__hash__ was doing nothing (and moving it to the subclasses is what broke the tests) so the final version is to move just the_generate_next_value_ function to both sub-classes. At this point I think a single line function duplicated 2x is simpler than doing inheritance from a private class (that we want to get rid of anyway).

On the other hand, doing a conditional import onStrEnum may be better?

tacaswelland others added4 commitsDecember 21, 2024 16:32
- 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>
@timhoffm
Copy link
Member

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.

@timhoffmtimhoffm merged commit677d990 intomatplotlib:mainDec 21, 2024
39 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestDec 21, 2024
timhoffm added a commit that referenced this pull requestDec 21, 2024
…362-on-v3.10.xBackport PR#29362 on branch v3.10.x (TYP: semantics of enums in stub files changed)
@QuLogic
Copy link
Member

@meeseeksdev backport to v3.10.0-doc

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.10.1
Development

Successfully merging this pull request may close these issues.

4 participants
@tacaswell@timhoffm@QuLogic@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp