Skip to content
Open
5 changes: 4 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,12 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
e.callee.arg_names,
lambda i: self.accept(e.args[i]),
)
checked_args = []
for arg in e.args:
checked_args.append(self.accept(arg))

arg_types = [
join.join_type_list([self.accept(e.args[j]) for j in formal_to_actual[i]])
join.join_type_list([checked_args[j] for j in formal_to_actual[i]])
for i in range(len(e.callee.arg_kinds))
]
type_context = CallableType(
Expand Down
33 changes: 33 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2538,3 +2538,36 @@ def last_known_value() -> None:
x, y, z = xy # E: Unpacking a string is disallowed
reveal_type(z) # N: Revealed type is "builtins.str"
[builtins fixtures/primitives.pyi]

[case testWalrusAssignmentInCallArguments]
# Ensure that assignment expressions (:=) in earlier call arguments
# propagate type information to later arguments in the same call.

from dataclasses import dataclass

@dataclass
class Notification:
request_reference: str

@dataclass
class Case:
title: str
notifications: list[Notification]
initial_reference: str = ""

cases = [
*[
Case(
title="example",
initial_reference=(request_reference := "abc"),
notifications=[
Notification(
request_reference=request_reference,
),
],
)
for _ in (1, 2)
],
]

reveal_type(request_reference) # N: Revealed type is "builtins.str"
Loading