You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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: