FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix missing error context for unpacking assignment involving star expression by brianschubert · Pull Request #19258 · python/mypy · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .test  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion mypy/checker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3864,7 +3864,7 @@ def check_assignment_to_multiple_lvalues(
if rvalue_needed > 0:
rvalues = (
rvalues[0:iterable_start]
+ [TempNode(iterable_type) for i in range(rvalue_needed)]
+ [TempNode(iterable_type, context=rval) for _ in range(rvalue_needed)]
Comment thread
brianschubert marked this conversation as resolved.
+ rvalues[iterable_end + 1 :]
)

Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-lists.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,12 @@ def foo(x: object) -> None:
[reveal_type(x) for x in [1, 2, 3]] # N: Revealed type is "builtins.int"

[builtins fixtures/isinstancelist.pyi]

[case testUnpackAssignmentWithStarExpr]
a: A
b: list[B]
if int():
(a,) = [*b] # E: Incompatible types in assignment (expression has type "B", variable has type "A")

class A: pass
class B: pass
9 changes: 9 additions & 0 deletions test-data/unit/check-tuples.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,15 @@ u, v, w = r, s = 1, 1 # E: Need more than 2 values to unpack (3 expected)
d, e = f, g, h = 1, 1 # E: Need more than 2 values to unpack (3 expected)
[builtins fixtures/tuple.pyi]

[case testUnpackAssignmentWithStarExpr]
a: A
b: list[B]
if int():
(a,) = (*b,) # E: Incompatible types in assignment (expression has type "B", variable has type "A")

class A: pass
class B: pass


-- Assignment to starred expressions
-- ---------------------------------
Expand Down

Back | FazBrowse Home | New Git URL