Fix issues with type aliases and new style unions#14181
Conversation
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
left a comment
There was a problem hiding this comment.
Looks good, but there is one important comment.
| # Per static analysis only: Is the right side unreachable? | ||
| right_unreachable: bool | ||
| # Used for expressions that represent a type "X | Y" in some contexts | ||
| analyzed: TypeAliasExpr | None |
There was a problem hiding this comment.
This should now be handled in various visitors. Three cases come to my mind: First, treetransform.py this is needed so that this error will not re-appear in a test case like this
T = TypeVar("T", int, str)
def foo(x: T) -> T:
A = type[int] | str
return xSecond, aststrip.py, be sure that when you switch imported names from types to variables, you do get an error about missing __or__ on update. Third, semanal_typeargs.py (uses MixedTraverserVisitor), since we should not carry malformed instances around (with number of type args), they may cause crashes, add a test just in case with a malformed instance in | alias.
And in general adding in to the basic TraverserVisitor is a good idea. Maybe just grep for def visit_index_expr( and see where we use analyzed.
There was a problem hiding this comment.
Very good points! I'll fix these.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/networks.py:16: error: Unused "type: ignore" comment
|
Fix aliases like this and other aliases involving new-style unions:
Fixes #12392. Fixes #14158.