Skip to content

Commit dde8fd8

Browse files
Use format_type for msg.type_not_iterable (#11490)
1 parent 47b22c5 commit dde8fd8

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

mypy/messages.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def unpacking_strings_disallowed(self, context: Context) -> None:
798798
self.fail("Unpacking a string is disallowed", context)
799799

800800
def type_not_iterable(self, type: Type, context: Context) -> None:
801-
self.fail('"{}" object is not iterable'.format(type), context)
801+
self.fail('{} object is not iterable'.format(format_type(type)), context)
802802

803803
def incompatible_operator_assignment(self, op: str,
804804
context: Context) -> None:
@@ -1613,8 +1613,8 @@ def generate_incompatible_tuple_error(self,
16131613
for i, (lhs_t, rhs_t) in enumerate(zip(lhs_types, rhs_types)):
16141614
if not is_subtype(lhs_t, rhs_t):
16151615
if error_cnt < 3:
1616-
notes.append('Expression tuple item {} has type "{}"; "{}" expected; '
1617-
.format(str(i), format_type_bare(rhs_t), format_type_bare(lhs_t)))
1616+
notes.append('Expression tuple item {} has type {}; {} expected; '
1617+
.format(str(i), format_type(rhs_t), format_type(lhs_t)))
16181618
error_cnt += 1
16191619

16201620
error_msg = msg + ' ({} tuple items are incompatible'.format(str(error_cnt))

test-data/unit/check-inference.test

+5-5
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,17 @@ main:6: error: Need more than 3 values to unpack (4 expected)
287287
[case testInvalidRvalueTypeInInferredMultipleLvarDefinition]
288288
import typing
289289
def f() -> None:
290-
a, b = f # E: "def ()" object is not iterable
291-
c, d = A() # E: "__main__.A" object is not iterable
290+
a, b = f # E: "Callable[[], None]" object is not iterable
291+
c, d = A() # E: "A" object is not iterable
292292
class A: pass
293293
[builtins fixtures/for.pyi]
294294
[out]
295295

296296
[case testInvalidRvalueTypeInInferredNestedTupleAssignment]
297297
import typing
298298
def f() -> None:
299-
a1, (a2, b) = A(), f # E: "def ()" object is not iterable
300-
a3, (c, d) = A(), A() # E: "__main__.A" object is not iterable
299+
a1, (a2, b) = A(), f # E: "Callable[[], None]" object is not iterable
300+
a3, (c, d) = A(), A() # E: "A" object is not iterable
301301
class A: pass
302302
[builtins fixtures/for.pyi]
303303
[out]
@@ -1004,7 +1004,7 @@ main:4: error: Incompatible types in assignment (expression has type "A", variab
10041004
main:5: error: Incompatible types in assignment (expression has type "B", variable has type "C")
10051005
main:6: error: Incompatible types in assignment (expression has type "C", variable has type "A")
10061006
main:10: error: Need more than 2 values to unpack (3 expected)
1007-
main:12: error: "__main__.B" object is not iterable
1007+
main:12: error: "B" object is not iterable
10081008

10091009
[case testInferenceOfFor3]
10101010

test-data/unit/check-modules.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1676,10 +1676,10 @@ reveal_type(n2.b) # N: Revealed type is "builtins.str"
16761676
reveal_type(m3.a) # N: Revealed type is "builtins.str"
16771677
reveal_type(n3.b) # N: Revealed type is "builtins.str"
16781678

1679-
x, y = m # E: "types.ModuleType" object is not iterable
1679+
x, y = m # E: Module object is not iterable
16801680
x, y, z = m, n # E: Need more than 2 values to unpack (3 expected)
16811681
x, y = m, m, m # E: Too many values to unpack (2 expected, 3 provided)
1682-
x, (y, z) = m, n # E: "types.ModuleType" object is not iterable
1682+
x, (y, z) = m, n # E: Module object is not iterable
16831683
x, (y, z) = m, (n, n, n) # E: Too many values to unpack (2 expected, 3 provided)
16841684

16851685
[file m.py]

test-data/unit/check-tuples.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ a, b = None, None # type: (A, B)
405405

406406
a1, b1 = a, a # type: (A, B) # E: Incompatible types in assignment (expression has type "A", variable has type "B")
407407
a2, b2 = b, b # type: (A, B) # E: Incompatible types in assignment (expression has type "B", variable has type "A")
408-
a3, b3 = a # type: (A, B) # E: "__main__.A" object is not iterable
408+
a3, b3 = a # type: (A, B) # E: "A" object is not iterable
409409
a4, b4 = None # type: (A, B) # E: "None" object is not iterable
410410
a5, b5 = a, b, a # type: (A, B) # E: Too many values to unpack (2 expected, 3 provided)
411411

@@ -421,8 +421,8 @@ a, b = None, None # type: (A, B)
421421
def f(): pass
422422

423423
a, b = None # E: "None" object is not iterable
424-
a, b = a # E: "__main__.A" object is not iterable
425-
a, b = f # E: "def () -> Any" object is not iterable
424+
a, b = a # E: "A" object is not iterable
425+
a, b = f # E: "Callable[[], Any]" object is not iterable
426426

427427
class A: pass
428428
class B: pass
@@ -1468,7 +1468,7 @@ x9, y9, x10, y10, z5 = *points2, 1, *points2 # E: Contiguous iterable with same
14681468
() = [] # E: can't assign to ()
14691469

14701470
[case testAssignEmptyBogus]
1471-
() = 1 # E: "Literal[1]?" object is not iterable
1471+
() = 1 # E: "int" object is not iterable
14721472
[builtins fixtures/tuple.pyi]
14731473

14741474
[case testMultiplyTupleByIntegerLiteral]

test-data/unit/check-unions.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ reveal_type(d1) # N: Revealed type is "Union[Any, builtins.float]"
556556
reveal_type(d2) # N: Revealed type is "Union[Any, builtins.float]"
557557

558558
e: Union[Any, Tuple[float, float], int]
559-
(e1, e2) = e # E: "builtins.int" object is not iterable
559+
(e1, e2) = e # E: "int" object is not iterable
560560
[builtins fixtures/tuple.pyi]
561561

562562
[case testUnionMultiassignNotJoin]
@@ -694,7 +694,7 @@ reveal_type(d) # N: Revealed type is "builtins.list[builtins.int*]"
694694
from typing import Union
695695
bad: Union[int, str]
696696

697-
x, y = bad # E: "builtins.int" object is not iterable \
697+
x, y = bad # E: "int" object is not iterable \
698698
# E: Unpacking a string is disallowed
699699
reveal_type(x) # N: Revealed type is "Any"
700700
reveal_type(y) # N: Revealed type is "Any"

0 commit comments

Comments
 (0)