Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
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
36 changes: 36 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2538,3 +2538,39 @@ 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 walrus_operator_in_comprehension_infers_type]
# Ensure that assignment expressions (:=) inside comprehensions
# correctly infer and propagate the assigned variable's type
# outside the comprehension scope.

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)
[out]
builtins.str
Loading