Skip to content

Commit 14016ce

Browse files
committed
.
1 parent 0a5235a commit 14016ce

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mypy/checker.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,16 +4116,14 @@ def check_multi_assignment(
41164116
lvalues, rvalue, rvalue_type, context, infer_lvalue_type
41174117
)
41184118
else:
4119+
rvalue_literal = rvalue_type
41194120
if isinstance(rvalue_type, Instance) and rvalue_type.type.fullname == "builtins.str":
4120-
if rvalue_type.last_known_value is None or (
4121-
isinstance(rvalue_type.last_known_value, str)
4122-
and len(rvalue_type.last_known_value) != len(lvalues)
4123-
):
4124-
self.msg.unpacking_strings_disallowed(context)
4121+
if rvalue_type.last_known_value is not None:
4122+
rvalue_literal = rvalue_type.last_known_value
41254123
if (
4126-
isinstance(rvalue_type, LiteralType)
4127-
and isinstance(rvalue_type.value, str)
4128-
and len(lvalues) != len(rvalue_type.value)
4124+
isinstance(rvalue_literal, LiteralType)
4125+
and isinstance(rvalue_literal.value, str)
4126+
and len(lvalues) != len(rvalue_literal.value)
41294127
):
41304128
self.msg.unpacking_strings_disallowed(context)
41314129

test-data/unit/check-expressions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,6 @@ def last_known_value() -> None:
25232523
reveal_type(x) # N: Revealed type is "builtins.str"
25242524
reveal_type(y) # N: Revealed type is "builtins.str"
25252525

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

0 commit comments

Comments
 (0)