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

Improve misleading message in Enum() (#5317) #14590

Merged
merged 3 commits into from
Feb 2, 2023
Merged

Improve misleading message in Enum() (#5317) #14590

merged 3 commits into from
Feb 2, 2023

Conversation

MestreLion
Copy link
Contributor

Clarifying this is a mypy limitation, not an Enum() requirement.

Not a true fix, but a workaround for #5317 to avoid confusion (as seen by the many duplicates

Just clarifying a somewhat misleading error message

Clarifying this is a mypy limitation, not an Enum() requirement.
@JelleZijlstra
Copy link
Member

Looks good, you'll likely have to update some test cases.

@JelleZijlstra JelleZijlstra self-assigned this Feb 2, 2023
@MestreLion
Copy link
Contributor Author

Looks good, you'll likely have to update some test cases.

I was already doing so, took a bit longer than expected, was side-tracked when I realized I forked from a fork instead of the original repo. And it seems Github does not allow changing source repo. Oh my... will fix that after (and if) this gets merged

@MestreLion
Copy link
Contributor Author

If merged, will this be a rebase or a plain merge? Given my fork was based on an outdated fork by mistake, a plain merge will create an "arc" of ~3700 commits, which I admit looks awful in repository tree views.

If this is undesirable, just say the word and I'll promptly re-create my fork and rebase my branch onto your master

@JelleZijlstra
Copy link
Member

We'll squash merge. I couldn't even create a merge commit if I wanted to :)

Screen Shot 2023-02-02 at 11 59 10 AM

I'm planning to merge once CI passes. Thanks for your contribution!

@MestreLion
Copy link
Contributor Author

We'll squash merge. I couldn't even create a merge commit if I wanted to :)

Phew, great! Glad my silly mistake will not taint my first contribution here :) Would be a shame if the parent commit was some random commit of years ago.

I'm planning to merge once CI passes. Thanks for your contribution!

🥇 👍 :-)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/cli/deployment.py:667: error: Enum() expects a string, tuple, list or dict literal as the second argument  [misc]
+ src/prefect/cli/deployment.py:667: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported  [misc]

@hauntsaninja
Copy link
Collaborator

Thank you! I do like having "literal" be after, since it avoids confusion with typing.LiteralString.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 2, 2023

What about "Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members"

(I think this also helps clarify that it isn't a thing that mypy could support)

@MestreLion
Copy link
Contributor Author

What about "Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members"

Looks nice too. I initially chose "is not supported" idiom just to follow suit with similar error messages (which I believe also mean that this is on mypy's side, not Enum's)

(I think this also helps clarify that it isn't a thing that mypy could support)

Well... theoretically it could. It might be unfeasible or too complex to implement, but conceptually it is not impossible. Or is it?

@AlexWaygood
Copy link
Member

Well... theoretically it could. It might be unfeasible or too complex to implement, but conceptually it is not impossible. Or is it?

It could be supported in the sense of "if you rewrote mypy from the ground up and made it a runtime type checker as well as a static type checker, it could be supported". But that's not realistically going to happen, and it's stretching the meaning of the word "could" a bit far :)

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 2, 2023

Enum("name", open("https://adsf").split()), Enum("name", x if solve_halting_problem(program) else y), nope!

@hauntsaninja hauntsaninja merged commit 50717cf into python:master Feb 2, 2023
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 2, 2023

Oh weird, I may have merged prematurely, seems like that didn't trigger Github Actions checks for some reason.

But thank you for the improvement!

@MestreLion MestreLion deleted the patch-1 branch February 3, 2023 01:58
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.

None yet

4 participants