Skip to content

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
@github-actions

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).

@github-actions
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