Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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__() | ||
greglucasDec 20, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 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
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
to18d42a6
Compare4c2aa05
to57f95dd
CompareSigh, I thought it was working locally because I was using an old mypy 😞 |
57f95dd
to5837e94
Compareok, 5th times the charm! @greglucas noted that On the other hand, doing a conditional import on |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
2981b1f
to45325ad
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
to91b26c3
CompareI'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. |
677d990
intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
…362-on-v3.10.xBackport PR#29362 on branch v3.10.x (TYP: semantics of enums in stub files changed)
@meeseeksdev backport to v3.10.0-doc |
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.