Skip to content
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

Restrict type of AssignmentExpr.target to NameExpr #18714

Merged
merged 4 commits into from
Mar 6, 2025

Conversation

bzoracler
Copy link
Contributor

Assignment expression targets can only be identifiers. From the grammar:

assignment_expression:
    | NAME ':=' ~ expression 

This corresponds to the standard library AST node's target type:

class NamedExpr(expr):
    if sys.version_info >= (3, 10):
        __match_args__ = ("target", "value")
    target: Name

@bzoracler bzoracler marked this pull request as draft February 20, 2025 22:44

This comment has been minimized.

@bzoracler bzoracler marked this pull request as ready for review February 20, 2025 23:15
Copy link
Collaborator

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I actually just needed this fact in a PR (at which point I remembered this PR was a thing and that actually target is guaranteed to be a name).

Copy link
Contributor

github-actions bot commented Mar 6, 2025

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit efc045e into python:master Mar 6, 2025
18 checks passed
@bzoracler bzoracler deleted the assignment-expr-type branch March 6, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants