-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
mypy interprets arguments which contains a pipe to Literal as type strings instead of literals #16367
Labels
Comments
Same issue with |
JelleZijlstra
added a commit
that referenced
this issue
Apr 22, 2024
Fixes #16367 During semantic analysis, we try to parse all strings as types, including those inside Literal[]. Previously, we preserved the original string in the `UnboundType.original_str_expr` attribute, but if a type is parsed as a Union, we didn't have a place to put the value. This PR instead always wraps string types in a RawExpressionType node, which now optionally includes a `.node` attribute containing the parsed type. This way, we don't need to worry about preserving the original string as a custom attribute on different kinds of types that can appear in this context. The downside is that more code needs to be aware of RawExpressionType.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Playground:
Expected behavior:
Actual behaviour:
Environment:
mypy.ini
(and other config files): None.This bug is found by StackOverflow user Håkon T. at this question.
It seems that mypy would try to interpret any string containing a pipe (
|
) as a type, and in this case it failed.The text was updated successfully, but these errors were encountered: