Skip to content

Commit cd1400e

Browse files
committed
Use nicer type formatting for error.
1 parent 6c33453 commit cd1400e

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def has_no_attr(self, original_type: Type, typ: Type, member: str, context: Cont
427427
member), context)
428428
else:
429429
self.fail('Element {} of {} has no attribute "{}"'.format(
430-
typ, original_type, member), context)
430+
self.format(typ), self.format(original_type), member), context)
431431
return AnyType()
432432

433433
def unsupported_operand_types(self, op: str, left_type: Any,

test-data/unit/check-generics.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ if not isinstance(s, str):
779779

780780
z = None # type: TNode # Same as TNode[Any]
781781
z.x
782-
z.foo() # E: Element __main__.Node[builtins.int] of Union[Any, __main__.Node[builtins.int]] has no attribute "foo"
782+
z.foo() # E: Element "Node[int]" of "Union[Any, Node[int]]" has no attribute "foo"
783783

784784
[builtins fixtures/isinstance.pyi]
785785

test-data/unit/check-isinstance.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ v = A() # type: Union[A, B, C]
548548

549549
if isinstance(v, (B, C)):
550550
v.method2(123)
551-
v.method3('xyz') # E: Element __main__.B of Union[__main__.B, __main__.C] has no attribute "method3"
551+
v.method3('xyz') # E: Element "B" of "Union[B, C]" has no attribute "method3"
552552
[builtins fixtures/isinstance.pyi]
553553

554554
[case testIsinstanceNeverWidens]
@@ -945,7 +945,7 @@ def bar() -> None:
945945
if isinstance(x, int):
946946
x + 1
947947
else:
948-
x.a # E: Element builtins.str of Union[builtins.str, __main__.A] has no attribute "a"
948+
x.a # E: Element "str" of "Union[str, A]" has no attribute "a"
949949
x = 'a'
950950

951951
[builtins fixtures/isinstancelist.pyi]

test-data/unit/check-optional.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ x = None # type: ONode[int]
534534
x = f(1)
535535
x = f('x') # E: Argument 1 to "f" has incompatible type "str"; expected "int"
536536

537-
x.x = 1 # E: Element builtins.object of Union[__main__.Node[builtins.int], builtins.None] has no attribute "x"
537+
x.x = 1 # E: Element "object" of "Optional[Node[int]]" has no attribute "x"
538538
if x is not None:
539539
x.x = 1 # OK here
540540

@@ -572,7 +572,7 @@ A = None # type: Any
572572
class C(A):
573573
pass
574574
x = None # type: Optional[C]
575-
x.foo() # E: Element builtins.object of Union[__main__.C, builtins.None] has no attribute "foo"
575+
x.foo() # E: Element "object" of "Optional[C]" has no attribute "foo"
576576

577577
[case testIsinstanceAndOptionalAndAnyBase]
578578
from typing import Any, Optional

test-data/unit/check-unions.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ z = None # type: str
6060
y = w.y
6161
z = w.y # E: Incompatible types in assignment (expression has type "int", variable has type "str")
6262
w.y = 'a' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
63-
y = x.y # E: Element __main__.C of Union[__main__.A, __main__.C] has no attribute "y"
64-
zz = x.y # E: Element __main__.C of Union[__main__.A, __main__.C] has no attribute "y"
63+
y = x.y # E: Element "C" of "Union[A, C]" has no attribute "y"
64+
zz = x.y # E: Element "C" of "Union[A, C]" has no attribute "y"
6565
z = zz # E: Incompatible types in assignment (expression has type "Union[int, Any]", variable has type "str")
6666

6767
[builtins fixtures/isinstance.pyi]
@@ -296,8 +296,8 @@ def foo(a: Union[A, B, C]):
296296
if isinstance(a, (B, C)):
297297
reveal_type(a) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]'
298298
a.x
299-
a.y # E: Element __main__.B of Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]] has no attribute "y" \
300-
# E: Element __main__.C of Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]] has no attribute "y"
299+
a.y # E: Element "B" of "Union[B, C]" has no attribute "y" \
300+
# E: Element "C" of "Union[B, C]" has no attribute "y"
301301
b = a # type: Union[B, C]
302302
[builtins fixtures/isinstance.pyi]
303303

0 commit comments

Comments
 (0)