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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ class AssignmentExpr(Expression):

__match_args__ = ("target", "value")

def __init__(self, target: Expression, value: Expression) -> None:
def __init__(self, target: NameExpr, value: Expression) -> None:
super().__init__()
self.target = target
self.value = value
Expand Down
4 changes: 3 additions & 1 deletion mypy/treetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ def visit_super_expr(self, node: SuperExpr) -> SuperExpr:
return new

def visit_assignment_expr(self, node: AssignmentExpr) -> AssignmentExpr:
return AssignmentExpr(self.expr(node.target), self.expr(node.value))
target = self.expr(node.target)
assert isinstance(target, NameExpr)
return AssignmentExpr(target, self.expr(node.value))

def visit_unary_expr(self, node: UnaryExpr) -> UnaryExpr:
new = UnaryExpr(node.op, self.expr(node.expr))
Expand Down