Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
JukkaL merged 16 commits intomasterfromfix-type-union
Nov 25, 2022
Merged

Conversation

@JukkaL
Copy link
Collaborator

Fix aliases like this and other aliases involving new-style unions:

A = type[int] | str

Fixes#12392.Fixes#14158.

AlexWaygood reacted with hooray emoji
@github-actions

This comment has been minimized.

Copy link
Member

@ilevkivskyiilevkivskyi left a 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
Copy link
Member

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.

hauntsaninja reacted with heart emoji
Copy link
CollaboratorAuthor

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.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ilevkivskyiilevkivskyiilevkivskyi approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

2 participants

@JukkaL@ilevkivskyi

[8]ページ先頭

©2009-2025 Movatter.jp