-
-
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
Fix Literal strings containing pipe characters #17148
Conversation
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Commit 1072c78 (python#17148) converted all quoted types into RawExpressionType, which raised an AssertionError when accepting a TypeTriggersVisitor. Fixes python#17587. Signed-off-by: Anders Kaseorg <[email protected]>
) Commit 1072c78 (#17148) converted all quoted types into `RawExpressionType`, which raised an `AssertionError` when `accept`ing a `TypeTriggersVisitor`. - Fixes #17574. - Fixes #17587. Signed-off-by: Anders Kaseorg <[email protected]>
) Commit 1072c78 (#17148) converted all quoted types into `RawExpressionType`, which raised an `AssertionError` when `accept`ing a `TypeTriggersVisitor`. - Fixes #17574. - Fixes #17587. Signed-off-by: Anders Kaseorg <[email protected]>
I am going to revert this. This breaks a fundamental invariant that synthetic types do not leak from semantic analysis. It looks like the code that caused the problem in the first place was intended to support something like this: x: Literal["A", "B"]
A = Literal[1, 2]
B = Literal[3, 4]
reveal_type(x) # Literal[1, 2, 3, 4] But I am not sure it ever worked (or at least not consistently). Instead I am going to change (either limit or completely prohibit) this behavior. |
This reverts commit 1072c78.
Reverts python#17148 (cherry picked from commit bc39f17)
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.