Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix walrus assignment type propagation across call arguments#20427

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Vaishnavi-KN wants to merge5 commits intopython:master
base:master
Choose a base branch
Loading
fromVaishnavi-KN:fix-walrus-call-args
Open
Show file tree
Hide file tree
Changes fromall 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 deletionmypy/checkexpr.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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
34 changes: 34 additions & 0 deletionstest-data/unit/check-expressions.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2538,3 +2538,37 @@ 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"
[builtins fixtures/tuple.pyi]
Loading

[8]ページ先頭

©2009-2025 Movatter.jp