From a1059c387bea18289032693dd638768259da28f4 Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Tue, 16 Dec 2025 17:58:29 +0530 Subject: [PATCH 01/12] Fix walrus assignment type propagation in call arguments --- mypy/checkexpr.py | 7 +++++- test-data/unit/check-expressions.test | 32 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 447afc16c464..0eda5755fb4c 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -585,9 +585,14 @@ 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( diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 8a969fc54428..4d99325d9ee3 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2538,3 +2538,35 @@ 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] +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 From 7be65e3c94e31bd835e03e32edeeed7b55818598 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:45:59 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/checkexpr.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 0eda5755fb4c..248d408241de 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -587,12 +587,10 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> ) checked_args = [] for arg in e.args: - checked_args.append(self.accept(arg)) - + checked_args.append(self.accept(arg)) arg_types = [ - join.join_type_list([checked_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( From 870ca9ce1719a6f8d66e4b095682d99741bdf007 Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Tue, 16 Dec 2025 20:08:39 +0530 Subject: [PATCH 03/12] Clarify intent of walrus assignment inference test --- test-data/unit/check-expressions.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 4d99325d9ee3..0e01e6bbc497 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2540,6 +2540,10 @@ def last_known_value() -> None: [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 From a9572ffbcd4be9848cbd43e4bd42e4f3e9da31ff Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Wed, 17 Dec 2025 19:02:27 +0530 Subject: [PATCH 04/12] Fix walrus assignment test formatting and naming --- test-data/unit/check-expressions.test | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 0e01e6bbc497..04e12fe0db71 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2539,10 +2539,9 @@ def last_known_value() -> None: 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. +[case testWalrusAssignmentInCallArguments] +# Ensure that assignment expressions (:=) in earlier call arguments +# propagate type information to later arguments in the same call. from dataclasses import dataclass @@ -2571,6 +2570,4 @@ cases = [ ], ] -reveal_type(request_reference) -[out] -builtins.str +reveal_type(request_reference) # N: Revealed type is "builtins.str" From de43aba74a731dd1be1a756c44f81f938fbf3f72 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 17 Dec 2025 23:53:11 -0800 Subject: [PATCH 05/12] Update test-data/unit/check-expressions.test --- test-data/unit/check-expressions.test | 1 + 1 file changed, 1 insertion(+) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 04e12fe0db71..c80910c58a65 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2571,3 +2571,4 @@ cases = [ ] reveal_type(request_reference) # N: Revealed type is "builtins.str" +[builtins fixtures/tuple.pyi] From 049c197789a9ad7b0b2f9291fc908a8bcf79c16e Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Thu, 18 Dec 2025 19:48:48 +0530 Subject: [PATCH 06/12] Update expected output for walrus assignment test --- test-data/unit/check-expressions.test | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index c80910c58a65..3d832d89759e 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2571,4 +2571,9 @@ cases = [ ] reveal_type(request_reference) # N: Revealed type is "builtins.str" -[builtins fixtures/tuple.pyi] + +[out] +main:23: error: Cannot determine type of "request_reference" +main:31: note: Revealed type is "builtins.str" + + From 5e3bbf607d2badc3ccd6fd2fd7010cd25092d847 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Dec 2025 15:10:24 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test-data/unit/check-expressions.test | 2 -- 1 file changed, 2 deletions(-) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 3d832d89759e..7920f500d7dd 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2575,5 +2575,3 @@ reveal_type(request_reference) # N: Revealed type is "builtins.str" [out] main:23: error: Cannot determine type of "request_reference" main:31: note: Revealed type is "builtins.str" - - From 3d74de0e9ebf6a0de187b9617fa340acdd6cd7c7 Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Fri, 19 Dec 2025 21:15:25 +0530 Subject: [PATCH 08/12] Remove unstable [out] section from walrus assignment test --- test-data/unit/check-expressions.test | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 7920f500d7dd..62c927299b0a 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2540,6 +2540,10 @@ def last_known_value() -> None: [builtins fixtures/primitives.pyi] [case testWalrusAssignmentInCallArguments] +[builtins fixtures/tuple.pyi] + + + # Ensure that assignment expressions (:=) in earlier call arguments # propagate type information to later arguments in the same call. @@ -2572,6 +2576,3 @@ cases = [ reveal_type(request_reference) # N: Revealed type is "builtins.str" -[out] -main:23: error: Cannot determine type of "request_reference" -main:31: note: Revealed type is "builtins.str" From f27158a72fd69a3edbd5721f070192455105d015 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Dec 2025 15:52:55 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test-data/unit/check-expressions.test | 1 - 1 file changed, 1 deletion(-) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 62c927299b0a..55e643f74cbe 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2575,4 +2575,3 @@ cases = [ ] reveal_type(request_reference) # N: Revealed type is "builtins.str" - From bb5ddef69a9d93091aa8d773682037444ad20c14 Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Sat, 20 Dec 2025 10:59:00 +0530 Subject: [PATCH 10/12] Prefer list comprehension for checked_args --- mypy/checkexpr.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 248d408241de..80454a7d213f 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -585,9 +585,8 @@ 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)) + checked_args = [self.accept(arg) for arg in e.args] + arg_types = [ join.join_type_list([checked_args[j] for j in formal_to_actual[i]]) From 00ce257697ab06819b33fa99b95e32acfcd62dc9 Mon Sep 17 00:00:00 2001 From: Vaishnavi KN Date: Mon, 22 Dec 2025 13:51:36 +0530 Subject: [PATCH 11/12] Fix walrus assignment type propagation in call arguments --- "assignment inference test\357\200\242" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "assignment inference test\357\200\242" diff --git "a/assignment inference test\357\200\242" "b/assignment inference test\357\200\242" new file mode 100644 index 000000000000..d9842d517d38 --- /dev/null +++ "b/assignment inference test\357\200\242" @@ -0,0 +1,15 @@ +diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test +index 4d99325d9..0e01e6bbc 100644 +--- a/test-data/unit/check-expressions.test ++++ b/test-data/unit/check-expressions.test +@@ -2540,6 +2540,10 @@ def last_known_value() -> None: + [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 From b98960b0cacb49f3cc7203bc8b39483d24f461d1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Dec 2025 08:14:39 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/checkexpr.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 80454a7d213f..0fe6db9b4a5c 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -587,7 +587,6 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> ) checked_args = [self.accept(arg) for arg in e.args] - arg_types = [ join.join_type_list([checked_args[j] for j in formal_to_actual[i]]) for i in range(len(e.callee.arg_kinds))