Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Fix issues with type aliases and new style unions#14181
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This comment has been minimized.
This comment has been minimized.
ilevkivskyi left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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)deffoo(x:T)->T:A=type[int]|strreturnx
Second,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 (usesMixedTraverserVisitor), 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 basicTraverserVisitor is a good idea. Maybe just grep fordef visit_index_expr( and see where we useanalyzed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 frommypy_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.