Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
.
  • Loading branch information
hauntsaninja committed Dec 2, 2025
commit 14016ce99463e2694f24b15b49dfcdd098943ef9
14 changes: 6 additions & 8 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4116,16 +4116,14 @@ def check_multi_assignment(
lvalues, rvalue, rvalue_type, context, infer_lvalue_type
)
else:
rvalue_literal = rvalue_type
if isinstance(rvalue_type, Instance) and rvalue_type.type.fullname == "builtins.str":
if rvalue_type.last_known_value is None or (
isinstance(rvalue_type.last_known_value, str)
and len(rvalue_type.last_known_value) != len(lvalues)
):
self.msg.unpacking_strings_disallowed(context)
if rvalue_type.last_known_value is not None:
rvalue_literal = rvalue_type.last_known_value
if (
isinstance(rvalue_type, LiteralType)
and isinstance(rvalue_type.value, str)
and len(lvalues) != len(rvalue_type.value)
isinstance(rvalue_literal, LiteralType)
and isinstance(rvalue_literal.value, str)
and len(lvalues) != len(rvalue_literal.value)
):
self.msg.unpacking_strings_disallowed(context)

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,6 @@ def last_known_value() -> None:
reveal_type(x) # N: Revealed type is "builtins.str"
reveal_type(y) # N: Revealed type is "builtins.str"

x, y, z = xy
x, y, z = xy # E: Unpacking a string is disallowed
reveal_type(z) # N: Revealed type is "builtins.str"
[builtins fixtures/primitives.pyi]
Loading