From b4b7de98d016287e2147f603a1fdd19ea7c43b8a Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 14:28:03 -0700 Subject: [PATCH 01/25] Consistent quote wrapping around MessageBuilder.format as per issue #3409 --- mypy/messages.py | 25 ++++--- test-data/unit/check-async-await.test | 40 +++++----- test-data/unit/check-class-namedtuple.test | 6 +- test-data/unit/check-classes.test | 52 ++++++------- test-data/unit/check-dynamic-typing.test | 2 +- test-data/unit/check-enum.test | 2 +- test-data/unit/check-expressions.test | 36 ++++----- test-data/unit/check-flags.test | 4 +- test-data/unit/check-functions.test | 16 ++-- test-data/unit/check-generic-subtyping.test | 66 ++++++++--------- test-data/unit/check-generics.test | 66 ++++++++--------- test-data/unit/check-ignore.test | 6 +- test-data/unit/check-incremental.test | 6 +- test-data/unit/check-inference-context.test | 46 ++++++------ test-data/unit/check-inference.test | 82 ++++++++++----------- test-data/unit/check-isinstance.test | 16 ++-- test-data/unit/check-kwargs.test | 24 +++--- test-data/unit/check-modules.test | 44 +++++------ test-data/unit/check-namedtuple.test | 6 +- test-data/unit/check-newsyntax.test | 14 ++-- test-data/unit/check-optional.test | 24 +++--- test-data/unit/check-overloading.test | 12 +-- test-data/unit/check-python2.test | 4 +- test-data/unit/check-statements.test | 10 +-- test-data/unit/check-tuples.test | 24 +++--- test-data/unit/check-type-checks.test | 2 +- test-data/unit/check-typeddict.test | 8 +- test-data/unit/check-typevar-values.test | 2 +- test-data/unit/check-unreachable-code.test | 2 +- test-data/unit/check-varargs.test | 44 +++++------ 30 files changed, 347 insertions(+), 344 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index e8fb537f6fa5..ad158d4edc9f 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -183,7 +183,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: Mostly behave like format_simple below, but never return an empty string. """ s = self.format_simple(typ, verbosity) - if s != '': + if s != '' and s != '""': # If format_simple returns a non-trivial result, use that. return s elif isinstance(typ, FunctionLike): @@ -241,6 +241,9 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: None -> None callable type -> "" (empty string) """ + return '"{}"'.format(self._format_simple(typ, verbosity)) + + def _format_simple(self, typ: Type, verbosity: int = 0) -> str: if isinstance(typ, Instance): itype = typ # Get the short name of the type. @@ -256,7 +259,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: # No type arguments. Place the type name in quotes to avoid # potential for confusion: otherwise, the type name could be # interpreted as a normal word. - return '"{}"'.format(base_str) + return base_str elif itype.type.fullname() == 'builtins.tuple': item_type_str = strip_quotes(self.format(itype.args[0])) return 'Tuple[{}, ...]'.format(item_type_str) @@ -280,15 +283,15 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: return '{}[...]'.format(base_str) elif isinstance(typ, TypeVarType): # This is similar to non-generic instance types. - return '"{}"'.format(typ.name) + return typ.name elif isinstance(typ, TupleType): # Prefer the name of the fallback class (if not tuple), as it's more informative. if typ.fallback.type.fullname() != 'builtins.tuple': - return self.format_simple(typ.fallback) + return self._format_simple(typ.fallback) items = [] for t in typ.items: items.append(strip_quotes(self.format(t))) - s = '"Tuple[{}]"'.format(', '.join(items)) + s = 'Tuple[{}]'.format(', '.join(items)) if len(s) < 400: return s else: @@ -296,11 +299,11 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, TypedDictType): # If the TypedDictType is named, return the name if typ.fallback.type.fullname() != 'typing.Mapping': - return self.format_simple(typ.fallback) + return self._format_simple(typ.fallback) items = [] for (item_name, item_type) in typ.items.items(): items.append('{}={}'.format(item_name, strip_quotes(self.format(item_type)))) - s = '"TypedDict({})"'.format(', '.join(items)) + s = 'TypedDict({})'.format(', '.join(items)) return s elif isinstance(typ, UnionType): # Only print Unions as Optionals if the Optional wouldn't have to contain another Union @@ -308,12 +311,12 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: sum(isinstance(t, NoneTyp) for t in typ.items) == 1) if print_as_optional: rest = [t for t in typ.items if not isinstance(t, NoneTyp)] - return '"Optional[{}]"'.format(strip_quotes(self.format(rest[0]))) + return 'Optional[{}]'.format(strip_quotes(self.format(rest[0]))) else: items = [] for t in typ.items: items.append(strip_quotes(self.format(t))) - s = '"Union[{}]"'.format(', '.join(items)) + s = 'Union[{}]'.format(', '.join(items)) if len(s) < 400: return s else: @@ -321,7 +324,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, NoneTyp): return 'None' elif isinstance(typ, AnyType): - return '"Any"' + return 'Any' elif isinstance(typ, DeletedType): return '' elif isinstance(typ, UninhabitedType): @@ -331,7 +334,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: return '' elif isinstance(typ, TypeType): return 'Type[{}]'.format( - strip_quotes(self.format_simple(typ.item, verbosity))) + strip_quotes(self._format_simple(typ.item, verbosity))) elif typ is None: raise RuntimeError('Type is None') else: diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 672bf2b408b8..7d9f7bde2a13 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -84,7 +84,7 @@ async def f() -> int: x = await g() return x [out] -main:7: error: Incompatible types in await (actual type Generator[int, None, str], expected type Awaitable[Any]) +main:7: error: Incompatible types in await (actual type "Generator[int, None, str]", expected type "Awaitable[Any]") [case testAwaitIteratorError] @@ -95,7 +95,7 @@ async def f() -> int: x = await g() return x [out] -main:6: error: Incompatible types in await (actual type Iterator[Any], expected type Awaitable[Any]) +main:6: error: Incompatible types in await (actual type "Iterator[Any]", expected type "Awaitable[Any]") [case testAwaitArgumentError] @@ -106,7 +106,7 @@ async def f() -> int: return x [builtins fixtures/async_await.pyi] [out] -main:5: error: Incompatible types in await (actual type "int", expected type Awaitable[Any]) +main:5: error: Incompatible types in await (actual type "int", expected type "Awaitable[Any]") [case testAwaitResultError] @@ -150,7 +150,7 @@ async def f() -> None: [builtins fixtures/async_await.pyi] [out] main:4: error: AsyncIterable expected -main:4: error: List[int] has no attribute "__aiter__" +main:4: error: "List[int]" has no attribute "__aiter__" [case testAsyncForTypeComments] @@ -232,13 +232,13 @@ async def wrong_iterable(obj: Iterable[int]): [out] main:18: error: AsyncIterable expected -main:18: error: Iterable[int] has no attribute "__aiter__"; maybe "__iter__"? +main:18: error: "Iterable[int]" has no attribute "__aiter__"; maybe "__iter__"? main:19: error: Iterable expected -main:19: error: asyncify[int] has no attribute "__iter__"; maybe "__aiter__"? +main:19: error: "asyncify[int]" has no attribute "__iter__"; maybe "__aiter__"? main:20: error: AsyncIterable expected -main:20: error: Iterable[int] has no attribute "__aiter__"; maybe "__iter__"? +main:20: error: "Iterable[int]" has no attribute "__aiter__"; maybe "__iter__"? main:21: error: Iterable expected -main:21: error: asyncify[int] has no attribute "__iter__"; maybe "__aiter__"? +main:21: error: "asyncify[int]" has no attribute "__iter__"; maybe "__aiter__"? [builtins fixtures/async_await.pyi] [case testAsyncWith] @@ -271,7 +271,7 @@ class C: def __aenter__(self) -> int: pass async def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: Incompatible types in "async with" for __aenter__ (actual type "int", expected type Awaitable[Any]) + async with C() as x: # E: Incompatible types in "async with" for __aenter__ (actual type "int", expected type "Awaitable[Any]") pass [builtins fixtures/async_await.pyi] [out] @@ -282,7 +282,7 @@ class C: def __aenter__(self) -> None: pass async def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: None has no attribute "__await__" + async with C() as x: # E: "None" has no attribute "__await__" pass [builtins fixtures/async_await.pyi] [out] @@ -293,7 +293,7 @@ class C: async def __aenter__(self) -> int: pass def __aexit__(self, x, y, z) -> int: pass async def f() -> None: - async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type Awaitable[Any]) + async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type "Awaitable[Any]") pass [builtins fixtures/async_await.pyi] [out] @@ -304,7 +304,7 @@ class C: async def __aenter__(self) -> int: pass def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: None has no attribute "__await__" + async with C() as x: # E: "None" has no attribute "__await__" pass [builtins fixtures/async_await.pyi] [out] @@ -362,7 +362,7 @@ def g() -> Generator[Any, None, str]: return x [builtins fixtures/async_await.pyi] [out] -main:6: error: "yield from" can't be applied to Awaitable[str] +main:6: error: "yield from" can't be applied to "Awaitable[str]" [case testAwaitableSubclass] @@ -523,7 +523,7 @@ def h() -> None: [out] main:9: error: Iterable expected -main:9: error: AsyncGenerator[int, None] has no attribute "__iter__"; maybe "__aiter__"? +main:9: error: "AsyncGenerator[int, None]" has no attribute "__iter__"; maybe "__aiter__"? [case testAsyncGeneratorNoYieldFrom] # flags: --fast-parser --python-version 3.6 @@ -607,19 +607,19 @@ def plain_host_generator() -> Generator[str, None, None]: yield 'a' x = 0 x = yield from plain_generator() - x = yield from plain_coroutine() # E: "yield from" can't be applied to Awaitable[int] + x = yield from plain_coroutine() # E: "yield from" can't be applied to "Awaitable[int]" x = yield from decorated_generator() - x = yield from decorated_coroutine() # E: "yield from" can't be applied to AwaitableGenerator[Any, Any, int, Awaitable[int]] + x = yield from decorated_coroutine() # E: "yield from" can't be applied to "AwaitableGenerator[Any, Any, int, Awaitable[int]]" x = yield from other_iterator() x = yield from other_coroutine() # E: "yield from" can't be applied to "Aw" async def plain_host_coroutine() -> None: x = 0 - x = await plain_generator() # E: Incompatible types in await (actual type Generator[str, None, int], expected type Awaitable[Any]) + x = await plain_generator() # E: Incompatible types in await (actual type "Generator[str, None, int]", expected type "Awaitable[Any]") x = await plain_coroutine() x = await decorated_generator() x = await decorated_coroutine() - x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type Awaitable[Any]) + x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type "Awaitable[Any]") x = await other_coroutine() @coroutine @@ -636,11 +636,11 @@ def decorated_host_generator() -> Generator[str, None, None]: @coroutine async def decorated_host_coroutine() -> None: x = 0 - x = await plain_generator() # E: Incompatible types in await (actual type Generator[str, None, int], expected type Awaitable[Any]) + x = await plain_generator() # E: Incompatible types in await (actual type "Generator[str, None, int]", expected type "Awaitable[Any]") x = await plain_coroutine() x = await decorated_generator() x = await decorated_coroutine() - x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type Awaitable[Any]) + x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type "Awaitable[Any]") x = await other_coroutine() [builtins fixtures/async_await.pyi] diff --git a/test-data/unit/check-class-namedtuple.test b/test-data/unit/check-class-namedtuple.test index 7a81adb0a672..7ae6c1f936bf 100644 --- a/test-data/unit/check-class-namedtuple.test +++ b/test-data/unit/check-class-namedtuple.test @@ -221,7 +221,7 @@ class MyNamedTuple(NamedTuple): a: int b: str -MyNamedTuple.x # E: Type[MyNamedTuple] has no attribute "x" +MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" [case testNewNamedTupleEmptyItems] # flags: --python-version 3.6 @@ -439,13 +439,13 @@ class HasNone(NamedTuple): y: Optional[int] = None reveal_type(HasNone(1)) # E: Revealed type is 'Tuple[builtins.int, Union[builtins.int, builtins.None], fallback=__main__.HasNone]' -HasNone(None) # E: Argument 1 to "HasNone" has incompatible type None; expected "int" +HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int" HasNone(1, y=None) HasNone(1, y=2) class CannotBeNone(NamedTuple): x: int - y: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + y: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index a257fa0375f0..f1c9373ba580 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -514,7 +514,7 @@ b = A.x # type: B # E: Incompatible types in assignment (expression has type "A" [case testAccessingUndefinedAttributeViaClass] import typing class A: pass -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAccessingUndefinedAttributeViaClassWithOverloadedInit] from foo import * @@ -525,7 +525,7 @@ class A: def __init__(self): pass @overload def __init__(self, x): pass -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAccessMethodOfClassWithOverloadedInit] from foo import * @@ -812,7 +812,7 @@ class C: cls(1) # E: Too many arguments for "C" cls.bar() cls.bar(1) # E: Too many arguments for "bar" of "C" - cls.bozo() # E: Type[C] has no attribute "bozo" + cls.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [out] @@ -823,7 +823,7 @@ class C: def foo(cls) -> None: pass C.foo() C.foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: Type[C] has no attribute "bozo" +C.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodCalledOnInstance] @@ -833,7 +833,7 @@ class C: def foo(cls) -> None: pass C().foo() C().foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: Type[C] has no attribute "bozo" +C.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodMayCallAbstractMethod] @@ -1278,7 +1278,7 @@ class D: def __get__(self, inst: Any, own: str) -> Any: pass class A: f = D() -A().f # E: Argument 2 to "__get__" of "D" has incompatible type Type[A]; expected "str" +A().f # E: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "str" [case testDescriptorGetSetDifferentTypes] from typing import Any @@ -1722,7 +1722,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type Type[C]; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testClassWith__new__AndCompatibilityWithType2] @@ -1733,7 +1733,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type Type[C]; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testGenericClassWith__new__] @@ -1813,7 +1813,7 @@ class B: [case testClassVsInstanceDisambiguation] class A: pass def f(x: A) -> None: pass -f(A) # E: Argument 1 to "f" has incompatible type Type[A]; expected "A" +f(A) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "A" [out] -- TODO @@ -2020,7 +2020,7 @@ class User: pass def new_user(user_class: Type[User]): return user_class() def foo(arg: Type[int]): - new_user(arg) # E: Argument 1 to "new_user" has incompatible type Type[int]; expected Type[User] + new_user(arg) # E: Argument 1 to "new_user" has incompatible type "Type[int]"; expected "Type[User]" [out] [case testTypeUsingTypeCUnionOverload] @@ -2059,7 +2059,7 @@ def foo(arg: Type[Any]): # Member access is ok and types as Any reveal_type(x) # E: Revealed type is 'Any' # But Type[Any] is distinct from Any - y: int = arg # E: Incompatible types in assignment (expression has type Type[Any], variable has type "int") + y: int = arg # E: Incompatible types in assignment (expression has type "Type[Any]", variable has type "int") [out] [case testTypeUsingTypeCTypeAnyMemberFallback] @@ -2100,7 +2100,7 @@ def process(cls: Type[User]): obj = cls() reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' cls.mro() # Defined in class type - cls.error # E: Type[User] has no attribute "error" + cls.error # E: "Type[User]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2114,11 +2114,11 @@ class User: class ProUser(User): pass class BasicUser(User): pass def process(cls: Type[Union[BasicUser, ProUser]]): - cls.foo() # E: Type[Union[BasicUser, ProUser]] has no attribute "foo" + cls.foo() # E: "Type[Union[BasicUser, ProUser]]" has no attribute "foo" obj = cls() - cls.bar(obj) # E: Type[Union[BasicUser, ProUser]] has no attribute "bar" + cls.bar(obj) # E: "Type[Union[BasicUser, ProUser]]" has no attribute "bar" cls.mro() # Defined in class type - cls.error # E: Type[Union[BasicUser, ProUser]] has no attribute "error" + cls.error # E: "Type[Union[BasicUser, ProUser]]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2134,7 +2134,7 @@ def process(cls: Type[U]): obj = cls() reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' cls.mro() # Defined in class type - cls.error # E: Type[U] has no attribute "error" + cls.error # E: "Type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2149,11 +2149,11 @@ class ProUser(User): pass class BasicUser(User): pass U = TypeVar('U', bound=Union[ProUser, BasicUser]) def process(cls: Type[U]): - cls.foo() # E: Type[U] has no attribute "foo" + cls.foo() # E: "Type[U]" has no attribute "foo" obj = cls() - cls.bar(obj) # E: Type[U] has no attribute "bar" + cls.bar(obj) # E: "Type[U]" has no attribute "bar" cls.mro() # Defined in class type - cls.error # E: Type[U] has no attribute "error" + cls.error # E: "Type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2621,7 +2621,7 @@ int.__eq__(3, 4) [builtins fixtures/args.pyi] [out] main:33: error: Too few arguments for "__eq__" of "int" -main:33: error: Unsupported operand types for == ("int" and Type[int]) +main:33: error: Unsupported operand types for == ("int" and "Type[int]") [case testMroSetAfterError] class C(str, str): @@ -2986,7 +2986,7 @@ class M: class A(metaclass=M): pass # E: Metaclasses not inheriting from 'type' are not supported -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testMetaclassTypeReveal] from typing import Type @@ -3057,7 +3057,7 @@ class Concrete(metaclass=Meta): pass reveal_type(Concrete + X()) # E: Revealed type is 'builtins.str' -Concrete + "hello" # E: Unsupported operand types for + (Type[Concrete] and "str") +Concrete + "hello" # E: Unsupported operand types for + ("Type[Concrete]" and "str") [case testMetaclassGetitem] class M(type): @@ -3085,7 +3085,7 @@ from missing import M class A(metaclass=M): y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyMetaclass] from typing import Any @@ -3093,7 +3093,7 @@ M = None # type: Any class A(metaclass=M): y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testInvalidVariableAsMetaclass] from typing import Any @@ -3104,7 +3104,7 @@ class A(metaclass=M): # E: Invalid metaclass 'M' class B(metaclass=MM): # E: Invalid metaclass 'MM' y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] from typing import Any, Type @@ -3119,7 +3119,7 @@ class A(metaclass=MM): def h(a: Type[A], b: Type[object]) -> None: h(a, a) - h(b, a) # E: Argument 1 to "h" has incompatible type Type[object]; expected Type[A] + h(b, a) # E: Argument 1 to "h" has incompatible type "Type[object]"; expected "Type[A]" a.f(1) # E: Too many arguments for "f" of "A" reveal_type(a.y) # E: Revealed type is 'builtins.int' diff --git a/test-data/unit/check-dynamic-typing.test b/test-data/unit/check-dynamic-typing.test index 68a174e3cc81..22626cfffd88 100644 --- a/test-data/unit/check-dynamic-typing.test +++ b/test-data/unit/check-dynamic-typing.test @@ -485,7 +485,7 @@ class A: def __init__(self, a, b): pass [out] main:6: error: Too few arguments for "A" -main:7: error: Incompatible types in assignment (expression has type Type[A], variable has type Callable[[A], A]) +main:7: error: Incompatible types in assignment (expression has type "Type[A]", variable has type Callable[[A], A]) [case testUsingImplicitTypeObjectWithIs] diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 011580effb35..d6e7a65abfc4 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -325,7 +325,7 @@ main:17: error: Enum() with dict literal requires string literals main:18: error: Unexpected arguments to Enum() main:19: error: Unexpected arguments to Enum() main:20: error: Unexpected arguments to Enum() -main:22: error: Type[W] has no attribute "c" +main:22: error: "Type[W]" has no attribute "c" [case testFunctionalEnumFlag] from enum import Flag, IntFlag diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 1d840269da42..8ecdb19f4ec0 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1125,7 +1125,7 @@ b'%a' % 3 from typing import Any, Dict a = None # type: Any ds, do, di = None, None, None # type: Dict[str, int], Dict[object, int], Dict[int, int] -'%(a)' % 1 # E: Format requires a mapping (expression has type "int", expected type for mapping is Dict[Any, Any]) +'%(a)' % 1 # E: Format requires a mapping (expression has type "int", expected type for mapping is "Dict[Any, Any]") '%()d' % a '%()d' % ds '%()d' % do @@ -1298,7 +1298,7 @@ class B: pass [out] main:5: error: Key expression in dictionary comprehension has incompatible type "A"; expected type "B" main:5: error: Value expression in dictionary comprehension has incompatible type "B"; expected type "A" -main:6: error: Incompatible types in assignment (expression has type Dict[A, B], variable has type "A") +main:6: error: Incompatible types in assignment (expression has type "Dict[A, B]", variable has type "A") [case testDictionaryComprehensionWithNonDirectMapping] @@ -1384,7 +1384,7 @@ cast(A, f) def f() -> None: pass [out] -main:5: error: Unsupported left operand type for + (None) +main:5: error: Unsupported left operand type for + ("None") main:6: error: Unsupported left operand type for + (Callable[[], None]) main:7: error: Unsupported operand types for + ("A" and Callable[[], None]) @@ -1522,7 +1522,7 @@ d1 = dict(a=1, b=2) # type: Dict[str, int] d2 = dict(a=1, b='') # type: Dict[str, int] # E: Dict entry 1 has incompatible type "str": "str" d3 = dict(a=1) # type: Dict[int, int] # E: Dict entry 0 has incompatible type "str": "int" d4 = dict(a=1, b=1) -d4.xyz # E: Dict[str, int] has no attribute "xyz" +d4.xyz # E: "Dict[str, int]" has no attribute "xyz" d5 = dict(a=1, b='') # type: Dict[str, Any] [builtins fixtures/dict.pyi] @@ -1536,7 +1536,7 @@ dict(undefined) # E: Name 'undefined' is not defined [case testDictFromList] from typing import Dict d = dict([(1, 'x'), (2, 'y')]) -d() # E: Dict[int, str] not callable +d() # E: "Dict[int, str]" not callable d2 = dict([(1, 'x')]) # type: Dict[str, str] # E: List item 0 has incompatible type "Tuple[int, str]" [builtins fixtures/dict.pyi] @@ -1545,10 +1545,10 @@ from typing import Dict it = [('x', 1)] d = dict(it, x=1) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable d2 = dict(it, x='') # E: Cannot infer type argument 2 of "dict" -d2() # E: Dict[Any, Any] not callable +d2() # E: "Dict[Any, Any]" not callable d3 = dict(it, x='') # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type "str"; expected "int" [builtins fixtures/dict.pyi] @@ -1560,7 +1560,7 @@ dict(it, x='y') # E: Keyword argument only valid with "str" key type in call to [case testDictFromIterableAndKeywordArg3] d = dict([], x=1) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs] @@ -1569,20 +1569,20 @@ it = [('x', 1)] kw = {'x': 1} d = dict(it, **kw) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable kw2 = {'x': ''} d2 = dict(it, **kw2) # E: Cannot infer type argument 2 of "dict" -d2() # E: Dict[Any, Any] not callable +d2() # E: "Dict[Any, Any]" not callable -d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type **Dict[str, str]; expected "int" +d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type **"Dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs2] it = [(1, 'x')] kw = {'x': 'y'} d = dict(it, **kw) # E: Keyword argument only valid with "str" key type in call to "dict" -d() # E: Dict[int, str] not callable +d() # E: "Dict[int, str]" not callable [builtins fixtures/dict.pyi] [case testUserDefinedClassNamedDict] @@ -1602,10 +1602,10 @@ class D1(dict): pass # Implicit base class Dict[Any, Any] D1([(1, 2)], x=1) class D2(Dict[T, S], Generic[T, S]): pass da = D2([('x', 2)], x=1) -da() # E: D2[str, int] not callable +da() # E: "D2[str, int]" not callable D2([(1, 2)], x=1) # E: Keyword argument only valid with "str" key type in call to "dict" db = D2(x=1) -db() # E: D2[str, int] not callable +db() # E: "D2[str, int]" not callable [builtins fixtures/dict.pyi] [case testSpecialSignatureForSubclassOfDict2] @@ -1622,7 +1622,7 @@ S = TypeVar('S') class D(Dict[T, S], Generic[T, S]): def __init__(self, x: S, y: T) -> None: pass d = D(1, y='') -d() # E: D[str, int] not callable +d() # E: "D[str, int]" not callable [builtins fixtures/dict.pyi] [case testRevealType] @@ -1654,7 +1654,7 @@ None == None [builtins fixtures/ops.pyi] [case testLtNone] -None < None # E: Unsupported left operand type for < (None) +None < None # E: Unsupported left operand type for < ("None") [builtins fixtures/ops.pyi] [case testDictWithStarExpr] @@ -1669,6 +1669,6 @@ a = {'a': 1} b = {'z': 26, **a} c = {**b} d = {**a, **b, 'c': 3} -e = {1: 'a', **a} # E: Argument 1 to "update" of "dict" has incompatible type Dict[str, int]; expected Mapping[int, str] -f = {**b} # type: Dict[int, int] # E: List item 0 has incompatible type Dict[str, int] +e = {1: 'a', **a} # E: Argument 1 to "update" of "dict" has incompatible type "Dict[str, int]"; expected "Mapping[int, str]" +f = {**b} # type: Dict[int, int] # E: List item 0 has incompatible type "Dict[str, int]" [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 2b0e5549589a..b270ec8b854c 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -190,7 +190,7 @@ reveal_type(f() or no_return()) # E: Revealed type is 'builtins.int' # flags: --warn-no-return from mypy_extensions import NoReturn -x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn) +x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type "NoReturn") [builtins fixtures/dict.pyi] [case testNoReturnImportFromTyping] @@ -206,7 +206,7 @@ def no_return() -> NoReturn: pass def f() -> NoReturn: no_return() -x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn) +x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "NoReturn") [builtins fixtures/dict.pyi] [case testShowErrorContextFunction] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index e4a155a748ed..963c8caba5a3 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -254,7 +254,7 @@ class A: pass t = None # type: type a = None # type: A -a = A # E: Incompatible types in assignment (expression has type Type[A], variable has type "A") +a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") t = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type "type") t = A @@ -334,10 +334,10 @@ def f(x: C) -> C: pass from typing import Any, Callable, List def f(fields: List[Callable[[Any], Any]]): pass class C: pass -f([C]) # E: List item 0 has incompatible type +f([C]) # E: List item 0 has incompatible type "" class D: def __init__(self, a, b): pass -f([D]) # E: List item 0 has incompatible type +f([D]) # E: List item 0 has incompatible type "" [builtins fixtures/list.pyi] [case testSubtypingTypeTypeAsCallable] @@ -352,7 +352,7 @@ from typing import Callable, Type class A: pass x = None # type: Callable[..., A] y = None # type: Type[A] -y = x # E: Incompatible types in assignment (expression has type Callable[..., A], variable has type Type[A]) +y = x # E: Incompatible types in assignment (expression has type Callable[..., A], variable has type "Type[A]") -- Default argument values -- ----------------------- @@ -517,7 +517,7 @@ class A(Generic[t]): g = f a = None # type: A[B] a.g(B()) -a.g(a) # E: Argument 1 has incompatible type A[B]; expected "B" +a.g(a) # E: Argument 1 has incompatible type "A[B]"; expected "B" [case testInvalidMethodAsDataAttributeInGenericClass] from typing import Any, TypeVar, Generic, Callable @@ -1479,7 +1479,7 @@ L = Callable[[Arg(name='x', type=int)], int] # ok # I have commented out the following test because I don't know how to expect the "defined here" note part of the error. # M = Callable[[Arg(gnome='x', type=int)], int] E: Invalid type alias E: Unexpected keyword argument "gnome" for "Arg" N = Callable[[Arg(name=None, type=int)], int] # ok -O = Callable[[List[Arg(int)]], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type Type[List[Any]] is not generic and not indexable +O = Callable[[List[Arg(int)]], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type "Type[List[Any]]" is not generic and not indexable P = Callable[[mypy_extensions.VarArg(int)], int] # ok Q = Callable[[Arg(int, type=int)], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "type" R = Callable[[Arg(int, 'x', name='y')], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "name" @@ -1735,7 +1735,7 @@ f(x=1, y="hello", z=[]) from typing import Dict def f(x, **kwargs): # type: (...) -> None success_dict_type = kwargs # type: Dict[str, str] - failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type Dict[str, Any], variable has type Dict[int, str]) + failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[int, str]") f(1, thing_in_kwargs=["hey"]) [builtins fixtures/dict.pyi] [out] @@ -1744,7 +1744,7 @@ f(1, thing_in_kwargs=["hey"]) from typing import Tuple, Any def f(x, *args): # type: (...) -> None success_tuple_type = args # type: Tuple[Any, ...] - fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type Tuple[Any, ...], variable has type None) + fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "None") f(1, "hello") [builtins fixtures/tuple.pyi] [out] diff --git a/test-data/unit/check-generic-subtyping.test b/test-data/unit/check-generic-subtyping.test index 6cae196bbe80..9c5d242368a8 100644 --- a/test-data/unit/check-generic-subtyping.test +++ b/test-data/unit/check-generic-subtyping.test @@ -13,9 +13,9 @@ ac = None # type: A[C] ad = None # type: A[D] b = None # type: B -b = ad # E: Incompatible types in assignment (expression has type A[D], variable has type "B") -ad = b # E: Incompatible types in assignment (expression has type "B", variable has type A[D]) -b = ac # E: Incompatible types in assignment (expression has type A[C], variable has type "B") +b = ad # E: Incompatible types in assignment (expression has type "A[D]", variable has type "B") +ad = b # E: Incompatible types in assignment (expression has type "B", variable has type "A[D]") +b = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B") b = b ac = b @@ -32,10 +32,10 @@ a = None # type: A bc = None # type: B[C] bd = None # type: B[D] -bc = bd # E: Incompatible types in assignment (expression has type B[D], variable has type B[C]) -bd = bc # E: Incompatible types in assignment (expression has type B[C], variable has type B[D]) -bc = a # E: Incompatible types in assignment (expression has type "A", variable has type B[C]) -bd = a # E: Incompatible types in assignment (expression has type "A", variable has type B[D]) +bc = bd # E: Incompatible types in assignment (expression has type "B[D]", variable has type "B[C]") +bd = bc # E: Incompatible types in assignment (expression has type "B[C]", variable has type "B[D]") +bc = a # E: Incompatible types in assignment (expression has type "A", variable has type "B[C]") +bd = a # E: Incompatible types in assignment (expression has type "A", variable has type "B[D]") a = bc a = bd @@ -54,10 +54,10 @@ ad = None # type: A[D] bcc = None # type: B[C, C] bdc = None # type: B[D, C] -ad = bcc # E: Incompatible types in assignment (expression has type B[C, C], variable has type A[D]) -ad = bdc # E: Incompatible types in assignment (expression has type B[D, C], variable has type A[D]) -bcc = ac # E: Incompatible types in assignment (expression has type A[C], variable has type B[C, C]) -bdc = ac # E: Incompatible types in assignment (expression has type A[C], variable has type B[D, C]) +ad = bcc # E: Incompatible types in assignment (expression has type "B[C, C]", variable has type "A[D]") +ad = bdc # E: Incompatible types in assignment (expression has type "B[D, C]", variable has type "A[D]") +bcc = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B[C, C]") +bdc = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B[D, C]") bcc = bcc bdc = bdc @@ -82,8 +82,8 @@ cef = None # type: C[E, F] cff = None # type: C[F, F] cfe = None # type: C[F, E] -ae = cef # E: Incompatible types in assignment (expression has type C[E, F], variable has type A[A[E]]) -af = cfe # E: Incompatible types in assignment (expression has type C[F, E], variable has type A[A[F]]) +ae = cef # E: Incompatible types in assignment (expression has type "C[E, F]", variable has type "A[A[E]]") +af = cfe # E: Incompatible types in assignment (expression has type "C[F, E]", variable has type "A[A[F]]") ae = cfe af = cef @@ -280,7 +280,7 @@ a = None # type: A bc = None # type: B[C] bd = None # type: B[D] -a = bc # E: Incompatible types in assignment (expression has type B[C], variable has type "A") +a = bc # E: Incompatible types in assignment (expression has type "B[C]", variable has type "A") bc = a bd = a @@ -305,8 +305,8 @@ a = None # type: A c = None # type: C bc = None # type: B[C] -a.x = c # E: Incompatible types in assignment (expression has type "C", variable has type B[Any]) -a.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected B[Any] +a.x = c # E: Incompatible types in assignment (expression has type "C", variable has type "B[Any]") +a.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected "B[Any]" a.x = bc a.f(bc) [out] @@ -325,8 +325,8 @@ class B(Generic[T]): class A(B): def g(self) -> None: - self.x = c # E: Incompatible types in assignment (expression has type "C", variable has type B[Any]) - self.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected B[Any] + self.x = c # E: Incompatible types in assignment (expression has type "C", variable has type "B[Any]") + self.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected "B[Any]" self.x = bc self.f(bc) @@ -394,7 +394,7 @@ B(1) C(1) C('a') # E: Argument 1 to "C" has incompatible type "str"; expected "int" D(A(1)) -D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[] +D(1) # E: Argument 1 to "D" has incompatible type "int"; expected "A[]" [case testInheritedConstructor2] @@ -427,9 +427,9 @@ adc = None # type: A[D, C] ic = None # type: I[C] id = None # type: I[D] -ic = acd # E: Incompatible types in assignment (expression has type A[C, D], variable has type I[C]) -id = adc # E: Incompatible types in assignment (expression has type A[D, C], variable has type I[D]) -adc = ic # E: Incompatible types in assignment (expression has type I[C], variable has type A[D, C]) +ic = acd # E: Incompatible types in assignment (expression has type "A[C, D]", variable has type "I[C]") +id = adc # E: Incompatible types in assignment (expression has type "A[D, C]", variable has type "I[D]") +adc = ic # E: Incompatible types in assignment (expression has type "I[C]", variable has type "A[D, C]") ic = adc id = acd @@ -451,11 +451,11 @@ class I(Generic[S]): pass class B(I[C]): pass class A(B): pass -ie = a # E: Incompatible types in assignment (expression has type "A", variable has type I[E]) -a = ic # E: Incompatible types in assignment (expression has type I[C], variable has type "A") -a = id # E: Incompatible types in assignment (expression has type I[D], variable has type "A") +ie = a # E: Incompatible types in assignment (expression has type "A", variable has type "I[E]") +a = ic # E: Incompatible types in assignment (expression has type "I[C]", variable has type "A") +a = id # E: Incompatible types in assignment (expression has type "I[D]", variable has type "A") a = b # E: Incompatible types in assignment (expression has type "B", variable has type "A") -id = a # E: Incompatible types in assignment (expression has type "A", variable has type I[D]) +id = a # E: Incompatible types in assignment (expression has type "A", variable has type "I[D]") ic = a b = a @@ -486,8 +486,8 @@ a, i, j = None, None, None # type: (A[object], I[object], J[object]) ii = a jj = a jj = i -a = i # E: Incompatible types in assignment (expression has type I[object], variable has type A[object]) -a = j # E: Incompatible types in assignment (expression has type J[object], variable has type A[object]) +a = i # E: Incompatible types in assignment (expression has type "I[object]", variable has type "A[object]") +a = j # E: Incompatible types in assignment (expression has type "J[object]", variable has type "A[object]") class J(Generic[t]): pass class X(metaclass=ABCMeta): pass @@ -546,7 +546,7 @@ class A(B): class C: pass class D: pass [out] -main:7: error: Incompatible types in assignment (expression has type "A", variable has type I[D]) +main:7: error: Incompatible types in assignment (expression has type "A", variable has type "I[D]") [case testSubclassingGenericABCWithDeepHierarchy2] from typing import Any, TypeVar, Generic @@ -704,7 +704,7 @@ a = None # type: G[A] b = None # type: G[B] c = None # type: G[C] -b = a # E: Incompatible types in assignment (expression has type G[A], variable has type G[B]) +b = a # E: Incompatible types in assignment (expression has type "G[A]", variable has type "G[B]") b = c [builtins fixtures/bool.pyi] [out] @@ -723,7 +723,7 @@ b = None # type: G[B] c = None # type: G[C] b = a -b = c # E: Incompatible types in assignment (expression has type G[C], variable has type G[B]) +b = c # E: Incompatible types in assignment (expression has type "G[C]", variable has type "G[B]") [builtins fixtures/bool.pyi] [out] @@ -740,8 +740,8 @@ a = None # type: G[A] b = None # type: G[B] c = None # type: G[C] -b = a # E: Incompatible types in assignment (expression has type G[A], variable has type G[B]) -b = c # E: Incompatible types in assignment (expression has type G[C], variable has type G[B]) +b = a # E: Incompatible types in assignment (expression has type "G[A]", variable has type "G[B]") +b = c # E: Incompatible types in assignment (expression has type "G[C]", variable has type "G[B]") [builtins fixtures/bool.pyi] [out] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 33106feca98d..f4a94281f8cd 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -79,8 +79,8 @@ class A(Generic[T]): pass class B: pass class C(B): pass [out] -main:4: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) -main:5: error: Incompatible types in assignment (expression has type A[C], variable has type A[B]) +main:4: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") +main:5: error: Incompatible types in assignment (expression has type "A[C]", variable has type "A[B]") [case testGenericTypeCompatibilityWithAny] from typing import Any, TypeVar, Generic @@ -115,8 +115,8 @@ class A(Generic[T]): class B: pass class C: pass [out] -main:7: error: Incompatible types in assignment (expression has type A[C], variable has type A[B]) -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) +main:7: error: Incompatible types in assignment (expression has type "A[C]", variable has type "A[B]") +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") [case testMultipleGenericTypeParametersWithMemberVars] from typing import TypeVar, Generic @@ -183,9 +183,9 @@ class A(Generic[S, T]): class B: pass class C(B):pass [out] -main:8: error: Incompatible types in assignment (expression has type A[B, C], variable has type A[B, B]) -main:9: error: Incompatible types in assignment (expression has type A[C, B], variable has type A[B, B]) -main:10: error: Incompatible types in assignment (expression has type A[B, B], variable has type A[B, C]) +main:8: error: Incompatible types in assignment (expression has type "A[B, C]", variable has type "A[B, B]") +main:9: error: Incompatible types in assignment (expression has type "A[C, B]", variable has type "A[B, B]") +main:10: error: Incompatible types in assignment (expression has type "A[B, B]", variable has type "A[B, C]") -- Simple generic type bodies @@ -208,7 +208,7 @@ x = None # type: B class B: pass [out] main:7: error: Argument 1 to "f" of "A" has incompatible type "B"; expected "T" -main:8: error: Incompatible types in assignment (expression has type A[T], variable has type A[B]) +main:8: error: Incompatible types in assignment (expression has type "A[T]", variable has type "A[B]") [case testGenericTypeBodyWithMultipleVariables] from typing import TypeVar, Generic @@ -229,8 +229,8 @@ class B: pass [out] main:8: error: Incompatible types in assignment (expression has type "T", variable has type "S") main:9: error: Incompatible types in assignment (expression has type "S", variable has type "T") -main:10: error: Incompatible types in assignment (expression has type A[S, T], variable has type A[S, B]) -main:11: error: Incompatible types in assignment (expression has type A[S, T], variable has type A[T, T]) +main:10: error: Incompatible types in assignment (expression has type "A[S, T]", variable has type "A[S, B]") +main:11: error: Incompatible types in assignment (expression has type "A[S, T]", variable has type "A[T, T]") [case testCompatibilityOfNoneWithTypeVar] from typing import TypeVar, Generic @@ -284,9 +284,9 @@ class B: pass class C: pass [out] main:8: error: Incompatible types in assignment (expression has type "C", variable has type "B") -main:9: error: Unsupported operand types for + (A[B, C] and "C") +main:9: error: Unsupported operand types for + ("A[B, C]" and "C") main:10: error: Incompatible types in assignment (expression has type "B", variable has type "C") -main:11: error: Invalid index type "B" for A[B, C]; expected type "C" +main:11: error: Invalid index type "B" for "A[B, C]"; expected type "C" [case testOperatorAssignmentWithIndexLvalue1] from typing import TypeVar, Generic @@ -309,7 +309,7 @@ class C: def __add__(self, o: 'C') -> 'C': pass [out] main:7: error: Unsupported operand types for + ("C" and "B") -main:8: error: Invalid index type "C" for A[C]; expected type "B" +main:8: error: Invalid index type "C" for "A[C]"; expected type "B" [case testOperatorAssignmentWithIndexLvalue2] from typing import TypeVar, Generic @@ -330,9 +330,9 @@ class B: pass class C: def __add__(self, o: 'C') -> 'C': pass [out] -main:7: error: Invalid index type "B" for A[C]; expected type "C" -main:8: error: Invalid index type "C" for A[C]; expected type "B" -main:9: error: Invalid index type "B" for A[C]; expected type "C" +main:7: error: Invalid index type "B" for "A[C]"; expected type "C" +main:8: error: Invalid index type "C" for "A[C]"; expected type "B" +main:9: error: Invalid index type "B" for "A[C]"; expected type "C" -- Nested generic types @@ -364,8 +364,8 @@ class B: class C: pass [out] -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) -main:9: error: Incompatible types in assignment (expression has type A[A[B]], variable has type A[A[C]]) +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") +main:9: error: Incompatible types in assignment (expression has type "A[A[B]]", variable has type "A[A[C]]") -- Generic functions @@ -384,7 +384,7 @@ def f(s: S, t: T) -> p[T, A]: s = t # E: Incompatible types in assignment (expression has type "T", variable has type "S") p_s_a = None # type: p[S, A] if s: - return p_s_a # E: Incompatible return value type (got p[S, A], expected p[T, A]) + return p_s_a # E: Incompatible return value type (got "p[S, A]", expected "p[T, A]") b = t # type: T c = s # type: S p_t_a = None # type: p[T, A] @@ -402,10 +402,10 @@ class A(Generic[T]): s = t # E: Incompatible types in assignment (expression has type "T", variable has type "S") p_s_s = None # type: p[S, S] if s: - return p_s_s # E: Incompatible return value type (got p[S, S], expected p[S, T]) + return p_s_s # E: Incompatible return value type (got "p[S, S]", expected "p[S, T]") p_t_t = None # type: p[T, T] if t: - return p_t_t # E: Incompatible return value type (got p[T, T], expected p[S, T]) + return p_t_t # E: Incompatible return value type (got "p[T, T]", expected "p[S, T]") t = t s = s p_s_t = None # type: p[S, T] @@ -448,7 +448,7 @@ A[int, str, int]() # E: Type application has too many types (2 expected) a = None # type: A class A: pass a[A]() # E: Value of type "A" is not indexable -A[A]() # E: The type Type[A] is not generic and not indexable +A[A]() # E: The type "Type[A]" is not generic and not indexable [out] [case testTypeApplicationArgTypes] @@ -504,7 +504,7 @@ Alias[int]("a") # E: Argument 1 to "Node" has incompatible type "str"; expected [out] [case testTypeApplicationCrash] -type[int] # this was crashing, see #2302 (comment) # E: The type Type[type] is not generic and not indexable +type[int] # this was crashing, see #2302 (comment) # E: The type "Type[type]" is not generic and not indexable [out] @@ -564,7 +564,7 @@ def func(x: IntNode[T]) -> IntNode[T]: return x reveal_type(func) # E: Revealed type is 'def [T] (x: __main__.Node[builtins.int, T`-1]) -> __main__.Node[builtins.int, T`-1]' -func(1) # E: Argument 1 to "func" has incompatible type "int"; expected Node[int, ] +func(1) # E: Argument 1 to "func" has incompatible type "int"; expected "Node[int, ]" func(Node('x', 1)) # E: Argument 1 to "Node" has incompatible type "str"; expected "int" reveal_type(func(Node(1, 'x'))) # E: Revealed type is '__main__.Node[builtins.int, builtins.str*]' @@ -692,7 +692,7 @@ l.meth().append(1) reveal_type(l.meth()) # E: Revealed type is 'builtins.list*[builtins.int]' l.meth().append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "int" -ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type List[str]) +ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "List[str]") [builtins fixtures/list.pyi] @@ -714,7 +714,7 @@ def f_bad(x: T) -> D[T]: return D(1) # Error, see out L[int]().append(Node((1, 1))) -L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected Node[Tuple[int, int]] +L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "Node[Tuple[int, int]]" x = D((1, 1)) # type: D[int] y = D(5) # type: D[int] # E: Argument 1 to "D" has incompatible type "int"; expected "Tuple[int, int]" @@ -778,7 +778,7 @@ if not isinstance(s, str): z = None # type: TNode # Same as TNode[Any] z.x -z.foo() # E: Item Node[int] of "Union[Any, Node[int]]" has no attribute "foo" +z.foo() # E: Item "Node[int]" of "Union[Any, Node[int]]" has no attribute "foo" [builtins fixtures/isinstance.pyi] @@ -847,7 +847,7 @@ def fun2(v: Vec[T], scale: T) -> Vec[T]: return v reveal_type(fun1([(1, 1)])) # E: Revealed type is 'builtins.int*' -fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected List[Tuple[int, int]] +fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected "List[Tuple[int, int]]" fun1([(1, 'x')]) # E: Cannot infer type argument 1 of "fun1" reveal_type(fun2([(1, 1)], 1)) # E: Revealed type is 'builtins.list[Tuple[builtins.int*, builtins.int*]]' @@ -868,7 +868,7 @@ n.y = 'x' # E: Incompatible types in assignment (expression has type "str", vari def f(x: Node[T, T]) -> TupledNode[T]: return Node(x.x, (x.x, x.x)) -f(1) # E: Argument 1 to "f" has incompatible type "int"; expected Node[, ] +f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Node[, ]" f(Node(1, 'x')) # E: Cannot infer type argument 1 of "f" reveal_type(Node('x', 'x')) # E: Revealed type is 'a.Node[builtins.str*, builtins.str*]' @@ -1221,7 +1221,7 @@ Z = TypeVar('Z') class OO: pass a = None # type: A[object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object] -f(a) # E: Argument 1 to "f" has incompatible type A[...]; expected "OO" +f(a) # E: Argument 1 to "f" has incompatible type "A[...]"; expected "OO" def f(a: OO) -> None: pass @@ -1232,7 +1232,7 @@ from typing import TypeVar, Generic S = TypeVar('S') T = TypeVar('T') a = None # type: A[object, B] -f(a) # E: Argument 1 to "f" has incompatible type A[object, B]; expected "B" +f(a) # E: Argument 1 to "f" has incompatible type "A[object, B]"; expected "B" def f(a: 'B') -> None: pass class A(Generic[S, T]): pass @@ -1243,7 +1243,7 @@ from typing import Callable, TypeVar, Generic S = TypeVar('S') T = TypeVar('T') a = None # type: A[object, Callable[[], None]] -f(a) # E: Argument 1 to "f" has incompatible type A[object, Callable[[], None]]; expected "B" +f(a) # E: Argument 1 to "f" has incompatible type "A[object, Callable[[], None]]"; expected "B" def f(a: 'B') -> None: pass class A(Generic[S, T]): pass @@ -1504,7 +1504,7 @@ T = TypeVar('T') class C(Generic[T]): def __init__(self) -> None: pass x = C # type: Callable[[], C[int]] -y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type Type[C[Any]], variable has type Callable[[], int]) +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type Callable[[], int]) -- Special cases diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 3c81bd01d13a..5f2fd773a0c1 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -46,7 +46,7 @@ import b # type: ignore reveal_type(a.foo) # E: Revealed type is 'Any' reveal_type(b.foo) # E: Revealed type is 'builtins.int' a.bar() -b.bar() # E: Module has no attribute "bar" +b.bar() # E: "Module" has no attribute "bar" [file b.py] foo = 3 @@ -76,7 +76,7 @@ class B(A): import m m.x = object # type: ignore m.f() # type: ignore -m.y # E: Module has no attribute "y" +m.y # E: "Module" has no attribute "y" [file m.py] [builtins fixtures/module.pyi] @@ -194,7 +194,7 @@ foo(Child()) def bar(x: Base[str, str]) -> None: pass bar(Child()) [out] -main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected Base[str, str] +main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected "Base[str, str]" [case testTypeIgnoreLineNumberWithinFile] import m diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 23fafc24edf5..78da587098ec 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -325,7 +325,7 @@ const = 3 [stale mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod4" +tmp/mod1.py:3: error: "Module" has no attribute "mod4" [case testIncrementalLongBrokenCascade] import mod1 @@ -360,7 +360,7 @@ const = 3 [stale mod6] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod7" +tmp/mod1.py:3: error: "Module" has no attribute "mod7" [case testIncrementalNestedBrokenCascade] import mod1 @@ -386,7 +386,7 @@ const = 3 [stale mod2.mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod4" +tmp/mod1.py:3: error: "Module" has no attribute "mod4" [case testIncrementalNestedBrokenCascadeWithType1] import mod1, mod2.mod3.mod5 diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 9896c1118a5a..4a8e5b1b8dc5 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -13,7 +13,7 @@ b = None # type: B ao = f() ab = f() -b = f() # E: Incompatible types in assignment (expression has type A[], variable has type "B") +b = f() # E: Incompatible types in assignment (expression has type "A[]", variable has type "B") def f() -> 'A[T]': pass @@ -29,7 +29,7 @@ b = None # type: B ao = A() ab = A() -b = A() # E: Incompatible types in assignment (expression has type A[], variable has type "B") +b = A() # E: Incompatible types in assignment (expression has type "A[]", variable has type "B") class A(Generic[T]): pass class B: pass @@ -74,10 +74,10 @@ def g() -> None: b = None # type: B x = f(o) - ab = x # E: Incompatible types in assignment (expression has type A[object], variable has type A[B]) + ab = x # E: Incompatible types in assignment (expression has type "A[object]", variable has type "A[B]") ao = x y = f(b) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = y def f(a: T) -> 'A[T]': pass @@ -104,8 +104,8 @@ def g() -> None: ab = None # type: A[B] b = None # type: B x, y = f(b), f(b) - ao = x # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = x # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = x ab = y @@ -122,8 +122,8 @@ def h() -> None: ab = None # type: A[B] b = None # type: B x, y = g(f(b)) - ao = x # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = x # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = x ab = y @@ -161,8 +161,8 @@ class A(Generic[T]): pass class B: pass [builtins fixtures/tuple.pyi] [out] -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:9: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:9: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") [case testInferenceWithTypeVariableTwiceInReturnTypeAndMultipleVariables] from typing import TypeVar, Tuple, Generic @@ -190,10 +190,10 @@ class A(Generic[T]): pass class B: pass [builtins fixtures/tuple.pyi] [out] -main:9: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:10: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:11: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:12: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) +main:9: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:10: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:11: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:12: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") -- Multiple tvar instances in arguments @@ -309,7 +309,7 @@ ab = None # type: A[B] ac = None # type: A[C] ab.g(f(o)) # E: Argument 1 to "f" has incompatible type "object"; expected "B" -ac = f(b).g(f(c)) # E: Incompatible types in assignment (expression has type A[B], variable has type A[C]) +ac = f(b).g(f(c)) # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") ac = f(c).g(f(b)) # E: Argument 1 to "f" has incompatible type "B"; expected "C" ab = f(b).g(f(c)) @@ -334,7 +334,7 @@ aa = None # type: List[A] ao = None # type: List[object] a = None # type: A -a = [] # E: Incompatible types in assignment (expression has type List[], variable has type "A") +a = [] # E: Incompatible types in assignment (expression has type "List[]", variable has type "A") aa = [] ao = [] @@ -401,7 +401,7 @@ ab = None # type: List[B] b = None # type: B o = None # type: object -aao = [[o], ab] # E: List item 1 has incompatible type List[B] +aao = [[o], ab] # E: List item 1 has incompatible type "List[B]" aab = [[], [o]] # E: List item 0 has incompatible type "object" aao = [[None], [b], [], [o]] @@ -462,7 +462,7 @@ d = {A() : a_c, [case testInitializationWithInferredGenericType] from typing import TypeVar, Generic T = TypeVar('T') -c = f(A()) # type: C[A] # E: Argument 1 to "f" has incompatible type "A"; expected C[A] +c = f(A()) # type: C[A] # E: Argument 1 to "f" has incompatible type "A"; expected "C[A]" def f(x: T) -> T: pass class C(Generic[T]): pass @@ -503,7 +503,7 @@ from abc import abstractmethod, ABCMeta t = TypeVar('t') x = A() # type: I[int] a_object = A() # type: A[object] -y = a_object # type: I[int] # E: Incompatible types in assignment (expression has type A[object], variable has type I[int]) +y = a_object # type: I[int] # E: Incompatible types in assignment (expression has type "A[object]", variable has type "I[int]") class I(Generic[t]): @abstractmethod @@ -663,7 +663,7 @@ class B: pass m = map(g, [A()]) b = m # type: List[B] -a = m # type: List[A] # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = m # type: List[A] # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] @@ -677,8 +677,8 @@ a, b, c = None, None, None # type: (List[A], List[B], List[C]) a = a or [] a = [] or a b = b or [C()] -a = a or b # E: Incompatible types in assignment (expression has type "Union[List[A], List[B]]", variable has type List[A]) -b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type List[B]) +a = a or b # E: Incompatible types in assignment (expression has type "Union[List[A], List[B]]", variable has type "List[A]") +b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type "List[B]") class A: pass class B: pass @@ -732,7 +732,7 @@ from typing import List i = None # type: List[int] s = None # type: List[str] i = i = [] -i = s = [] # E: Incompatible types in assignment (expression has type List[str], variable has type List[int]) +i = s = [] # E: Incompatible types in assignment (expression has type "List[str]", variable has type "List[int]") [builtins fixtures/list.pyi] [case testContextForAttributeDeclaredInInit] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 42cd312c0531..76931ad3b254 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -69,7 +69,7 @@ class B: pass import typing def f() -> None: a = g() - None(a) # E: None not callable + None(a) # E: "None" not callable a.x() def g(): pass @@ -81,7 +81,7 @@ g = None # type: Any def f(a: Any) -> None: b = g - None(b) # E: None not callable + None(b) # E: "None" not callable a.x() [out] @@ -126,7 +126,7 @@ a_s = None # type: A[str] def f() -> None: a_int = A() # type: A[int] a = a_int - a = a_s # E: Incompatible types in assignment (expression has type A[str], variable has type A[int]) + a = a_s # E: Incompatible types in assignment (expression has type "A[str]", variable has type "A[int]") a = a_i [builtins fixtures/tuple.pyi] [out] @@ -480,11 +480,11 @@ ao = None # type: A[object] ab = None # type: A[B] ac = None # type: A[C] -ab = f(ao) # E: Argument 1 to "f" has incompatible type A[object]; expected A[B] -ao = f(ab) # E: Argument 1 to "f" has incompatible type A[B]; expected A[object] -ab = f(ac) # E: Argument 1 to "f" has incompatible type A[C]; expected A[B] -ab = g(ao) # E: Argument 1 to "g" has incompatible type A[object]; expected A[B] -ao = g(ab) # E: Argument 1 to "g" has incompatible type A[B]; expected A[object] +ab = f(ao) # E: Argument 1 to "f" has incompatible type "A[object]"; expected "A[B]" +ao = f(ab) # E: Argument 1 to "f" has incompatible type "A[B]"; expected "A[object]" +ab = f(ac) # E: Argument 1 to "f" has incompatible type "A[C]"; expected "A[B]" +ab = g(ao) # E: Argument 1 to "g" has incompatible type "A[object]"; expected "A[B]" +ao = g(ab) # E: Argument 1 to "g" has incompatible type "A[B]"; expected "A[object]" ab = f(ab) ac = f(ac) @@ -648,7 +648,7 @@ def mymap(f: Callable[[t], s], a: List[t]) -> List[s]: pass l = mymap(f, [b]) l = [A()] lb = [b] -l = lb # E: Incompatible types in assignment (expression has type List[bool], variable has type List[A]) +l = lb # E: Incompatible types in assignment (expression has type "List[bool]", variable has type "List[A]") [builtins fixtures/for.pyi] [case testGenericFunctionWithTypeTypeAsCallable] @@ -676,7 +676,7 @@ f(1, 1)() # E: "int" not callable def g(x: Union[T, List[T]]) -> List[T]: pass def h(x: List[str]) -> None: pass -g('a')() # E: List[str] not callable +g('a')() # E: "List[str]" not callable # The next line is a case where there are multiple ways to satisfy a constraint # involving a Union. Either T = List[str] or T = str would turn out to be valid, @@ -684,7 +684,7 @@ g('a')() # E: List[str] not callable # to backtrack later) and defaults to T = . The result is an # awkward error message. Either a better error message, or simply accepting the # call, would be preferable here. -g(['a']) # E: Argument 1 to "g" has incompatible type List[str]; expected List[] +g(['a']) # E: Argument 1 to "g" has incompatible type "List[str]"; expected "List[]" h(g(['a'])) @@ -693,7 +693,7 @@ a = [1] b = ['b'] i(a, a, b) i(b, a, b) -i(a, b, b) # E: Argument 1 to "i" has incompatible type List[int]; expected List[str] +i(a, b, b) # E: Argument 1 to "i" has incompatible type "List[int]"; expected "List[str]" [builtins fixtures/list.pyi] [case testCallableListJoinInference] @@ -778,7 +778,7 @@ from typing import TypeVar, Union, List T = TypeVar('T') def f() -> List[T]: pass d1 = f() # type: Union[List[int], str] -d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type List[], variable has type "Union[int, str]") +d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type "List[]", variable has type "Union[int, str]") def g(x: T) -> List[T]: pass d3 = g(1) # type: Union[List[int], List[str]] [builtins fixtures/list.pyi] @@ -840,7 +840,7 @@ def d_aa() -> Dict[A, A]: return {} a, b = None, None # type: (A, B) d = {a:b} d = d_ab() -d = d_aa() # E: Incompatible types in assignment (expression has type Dict[A, A], variable has type Dict[A, B]) +d = d_aa() # E: Incompatible types in assignment (expression has type "Dict[A, A]", variable has type "Dict[A, B]") [builtins fixtures/dict.pyi] [case testSetLiteral] @@ -851,7 +851,7 @@ def s_s() -> Set[str]: return set() s = {a} s = {x} s = s_i() -s = s_s() # E: Incompatible types in assignment (expression has type Set[str], variable has type Set[int]) +s = s_s() # E: Incompatible types in assignment (expression has type "Set[str]", variable has type "Set[int]") [builtins fixtures/set.pyi] [case testSetWithStarExpr] @@ -1154,7 +1154,7 @@ a = None # type: List[A] o = None # type: List[object] a2 = a or [] a = a2 -a2 = o # E: Incompatible types in assignment (expression has type List[object], variable has type List[A]) +a2 = o # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[A]") class A: pass [builtins fixtures/list.pyi] @@ -1194,7 +1194,7 @@ x2 = [B(), A()] x3 = [B(), B()] a = x1 a = x2 -a = x3 # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = x3 # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] [case testListWithDucktypeCompatibilityAndTransitivity] @@ -1210,7 +1210,7 @@ x2 = [C(), A()] x3 = [B(), C()] a = x1 a = x2 -a = x3 # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = x3 # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] @@ -1256,8 +1256,8 @@ a() a, b = [], [] a.append(1) b.append('') -a() # E: List[int] not callable -b() # E: List[str] not callable +a() # E: "List[int]" not callable +b() # E: "List[str]" not callable [builtins fixtures/list.pyi] [out] @@ -1371,14 +1371,14 @@ a.add('') # E: Argument 1 to "add" of "set" has incompatible type "str"; expect [case testInferDictInitializedToEmpty] a = {} a[1] = '' -a() # E: Dict[int, str] not callable +a() # E: "Dict[int, str]" not callable [builtins fixtures/dict.pyi] [out] [case testInferDictInitializedToEmptyUsingUpdate] a = {} a.update({'': 42}) -a() # E: Dict[str, int] not callable +a() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [out] @@ -1447,7 +1447,7 @@ def f() -> None: import typing def f() -> None: a = None - a.x() # E: None has no attribute "x" + a.x() # E: "None" has no attribute "x" [out] [case testGvarPartiallyInitializedToNone] @@ -1504,7 +1504,7 @@ x = None def f() -> None: x = None x = 1 -x() # E: None not callable +x() # E: "None" not callable [case testAttributePartiallyInitializedToNone] class A: @@ -1523,8 +1523,8 @@ class A: self.x = 1 self.x() [out] -main:6: error: Incompatible types in assignment (expression has type "int", variable has type None) -main:7: error: None not callable +main:6: error: Incompatible types in assignment (expression has type "int", variable has type "None") +main:7: error: "None" not callable [case testGlobalInitializedToNoneSetFromFunction] a = None @@ -1553,7 +1553,7 @@ class A: pass [builtins fixtures/for.pyi] [out] -main:5: error: None has no attribute "__iter__" +main:5: error: "None" has no attribute "__iter__" [case testPartialTypeErrorSpecialCase2] # This used to crash. @@ -1574,7 +1574,7 @@ class A: pass [builtins fixtures/for.pyi] [out] -main:4: error: None has no attribute "__iter__" +main:4: error: "None" has no attribute "__iter__" -- Multipass @@ -1680,7 +1680,7 @@ def g(d: Dict[str, int]) -> None: pass def f() -> None: x = {} x[1] = y - g(x) # E: Argument 1 to "g" has incompatible type Dict[int, str]; expected Dict[str, int] + g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, str]"; expected "Dict[str, int]" x[1] = 1 # E: Incompatible types in assignment (expression has type "int", target has type "str") x[1] = '' y = '' @@ -1694,7 +1694,7 @@ def f() -> None: x = {} y x[1] = 1 - g(x) # E: Argument 1 to "g" has incompatible type Dict[int, int]; expected Dict[str, int] + g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, int]"; expected "Dict[str, int]" y = '' [builtins fixtures/dict.pyi] [out] @@ -1713,7 +1713,7 @@ def f() -> None: y = o x = [] x.append(y) - x() # E: List[int] not callable + x() # E: "List[int]" not callable o = 1 [builtins fixtures/list.pyi] [out] @@ -1723,7 +1723,7 @@ def f() -> None: y = o x = {} x[''] = y - x() # E: Dict[str, int] not callable + x() # E: "Dict[str, int]" not callable o = 1 [builtins fixtures/dict.pyi] [out] @@ -1825,20 +1825,20 @@ a2.foo2() [case testUnificationEmptyListLeft] def f(): pass a = [] if f() else [0] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRight] def f(): pass a = [0] if f() else [] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListLeftInContext] from typing import List def f(): pass a = [] if f() else [0] # type: List[int] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRightInContext] @@ -1846,37 +1846,37 @@ a() # E: List[int] not callable from typing import List def f(): pass a = [0] if f() else [] # type: List[int] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptySetLeft] def f(): pass a = set() if f() else {0} -a() # E: Set[int] not callable +a() # E: "Set[int]" not callable [builtins fixtures/set.pyi] [case testUnificationEmptyDictLeft] def f(): pass a = {} if f() else {0: 0} -a() # E: Dict[int, int] not callable +a() # E: "Dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationEmptyDictRight] def f(): pass a = {0: 0} if f() else {} -a() # E: Dict[int, int] not callable +a() # E: "Dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListLeft] def f(): pass a = {0: []} if f() else {0: [0]} -a() # E: Dict[int, List[int]] not callable +a() # E: "Dict[int, List[int]]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListRight] def f(): pass a = {0: [0]} if f() else {0: []} -a() # E: Dict[int, List[int]] not callable +a() # E: "Dict[int, List[int]]" not callable [builtins fixtures/dict.pyi] [case testMisguidedSetItem] diff --git a/test-data/unit/check-isinstance.test b/test-data/unit/check-isinstance.test index 825a5557fc63..d9a27649e4af 100644 --- a/test-data/unit/check-isinstance.test +++ b/test-data/unit/check-isinstance.test @@ -679,7 +679,7 @@ while bool(): x + 'a' break x + [1] - x + 'a' # E: Unsupported operand types for + (List[int] and "str") + x + 'a' # E: Unsupported operand types for + ("List[int]" and "str") x + [1] # E: Unsupported operand types for + (likely involving Union) [builtins fixtures/isinstancelist.pyi] @@ -1486,7 +1486,7 @@ def test_issubclass(cls: Type[Goblin]) -> None: else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1511,7 +1511,7 @@ def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, Goblin): reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1525,8 +1525,8 @@ def test_issubclass(cls: Type[Mob]) -> None: g.job = 'Warrior' # E: Cannot assign to class variable "job" via instance else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' - cls.job # E: Type[Mob] has no attribute "job" - cls.level # E: Type[Mob] has no attribute "level" + cls.job # E: "Type[Mob]" has no attribute "job" + cls.level # E: "Type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" @@ -1570,7 +1570,7 @@ def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, (Goblin, GoblinAmbusher)): reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1584,8 +1584,8 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' - cls.job # E: Type[Mob] has no attribute "job" - cls.level # E: Type[Mob] has no attribute "level" + cls.job # E: "Type[Mob]" has no attribute "job" + cls.level # E: "Type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index de229c76e631..e8182b34ae8f 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -4,7 +4,7 @@ [case testTypeErrorInKeywordArgument] import typing def f(o: object) -> None: pass -f(o=None()) # E: None not callable +f(o=None()) # E: "None" not callable [case testSimpleKeywordArgument] import typing @@ -89,8 +89,8 @@ class A: pass [case testKeywordArgumentsWithDynamicallyTypedCallable] from typing import Any f = None # type: Any -f(x=f(), z=None()) # E: None not callable -f(f, zz=None()) # E: None not callable +f(x=f(), z=None()) # E: "None" not callable +f(f, zz=None()) # E: "None" not callable f(x=None) [case testKeywordArgumentWithFunctionObject] @@ -216,8 +216,8 @@ class A: pass from typing import Dict, Any def f( **kwargs: 'A') -> None: d1 = kwargs # type: Dict[str, A] - d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type Dict[str, A], variable has type Dict[A, Any]) - d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type Dict[str, A], variable has type Dict[Any, str]) + d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[A, Any]") + d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[Any, str]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -227,7 +227,7 @@ from typing import Dict, Any def f(**kwargs) -> None: d1 = kwargs # type: Dict[str, A] d2 = kwargs # type: Dict[str, str] - d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type Dict[str, Any], variable has type Dict[A, Any]) + d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[A, Any]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -252,8 +252,8 @@ d = None # type: Dict[str, A] f(**d) f(x=A(), **d) d2 = None # type: Dict[str, B] -f(**d2) # E: Argument 1 to "f" has incompatible type **Dict[str, B]; expected "A" -f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type **Dict[str, B]; expected "A" +f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, B]"; expected "A" +f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type **"Dict[str, B]"; expected "A" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -295,7 +295,7 @@ def f(a: 'A', b: 'B') -> None: pass d = None # type: Dict[str, Any] f(**d) d2 = None # type: Dict[str, A] -f(**d2) # E: Argument 1 to "f" has incompatible type **Dict[str, A]; expected "B" +f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, A]"; expected "B" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -344,12 +344,12 @@ s = ('',) f(*s) # E: Argument 1 to "f" has incompatible type *"Tuple[str]"; expected "int" a = {'': 0} -f(a) # E: Argument 1 to "f" has incompatible type Dict[str, int]; expected "int" +f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, int]"; expected "int" f(**a) # okay b = {'': ''} -f(b) # E: Argument 1 to "f" has incompatible type Dict[str, str]; expected "int" -f(**b) # E: Argument 1 to "f" has incompatible type **Dict[str, str]; expected "int" +f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, str]"; expected "int" +f(**b) # E: Argument 1 to "f" has incompatible type **"Dict[str, str]"; expected "int" c = {0: 0} f(**c) # E: Keywords must be strings diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 66050601d26f..10c6a22680d6 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -155,16 +155,16 @@ import m import typing class A: pass -m() # E: Module not callable -a = m # type: A # E: Incompatible types in assignment (expression has type Module, variable has type "A") -m + None # E: Unsupported left operand type for + (Module) +m() # E: "Module" not callable +a = m # type: A # E: Incompatible types in assignment (expression has type "Module", variable has type "A") +m + None # E: Unsupported left operand type for + ("Module") [file m.py] [builtins fixtures/module.pyi] [case testNameDefinedInDifferentModule] import m, n import typing -m.x # E: Module has no attribute "x" +m.x # E: "Module" has no attribute "x" [file m.py] y = object() [file n.py] @@ -201,7 +201,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModule2] import m, nonexistent @@ -213,7 +213,7 @@ x = 1 [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testTypeCheckWithUnknownModule3] @@ -226,7 +226,7 @@ x = 1 [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testTypeCheckWithUnknownModule4] @@ -236,7 +236,7 @@ None + '' main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) main:1: error: Cannot find module named 'another' -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModule5] import nonexistent as x @@ -244,7 +244,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModuleUsingFromImport] from nonexistent import x @@ -252,7 +252,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModuleUsingImportStar] from nonexistent import * @@ -260,7 +260,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testAccessingUnknownModule] import xyz @@ -330,7 +330,7 @@ import nonexistent [out] tmp/x.py:1: error: Cannot find module named 'nonexistent' tmp/x.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:3: error: Module has no attribute "z" +main:3: error: "Module" has no attribute "z" [case testUnknownModuleImportedWithinFunction] def f(): @@ -411,14 +411,14 @@ import typing __all__ = [1, 2, 3] [builtins fixtures/module_all.pyi] [out] -main:2: error: Type of __all__ must be Sequence[str], not List[int] +main:2: error: Type of __all__ must be "Sequence[str]", not "List[int]" [case testAllMustBeSequenceStr_python2] import typing __all__ = [1, 2, 3] [builtins_py2 fixtures/module_all_python2.pyi] [out] -main:2: error: Type of __all__ must be Sequence[unicode], not List[int] +main:2: error: Type of __all__ must be "Sequence[unicode]", not "List[int]" [case testAllUnicodeSequenceOK_python2] import typing @@ -648,7 +648,7 @@ def f(x: str) -> None: pass if object(): import m else: - m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Module) + m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Module") [file m.py] [builtins fixtures/module.pyi] [out] @@ -673,7 +673,7 @@ def f(x: str) -> None: pass None + 1 [file m/a.py] [out] -tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) +tmp/m/__init__.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule2] # cmd: mypy -m m.a @@ -681,7 +681,7 @@ tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) [file m/a.py] None + 1 [out] -tmp/m/a.py:1: error: Unsupported left operand type for + (None) +tmp/m/a.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule3] # cmd: mypy -m m @@ -689,7 +689,7 @@ tmp/m/a.py:1: error: Unsupported left operand type for + (None) None + 1 [file m/a.py] [out] -tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) +tmp/m/__init__.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule4] # cmd: mypy -m m @@ -704,7 +704,7 @@ None + '' # Not analyzed. [file m.py] None + 1 [out] -tmp/m.py:1: error: Unsupported left operand type for + (None) +tmp/m.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModuleWithImportCycle] # cmd: mypy -m m.a @@ -752,7 +752,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents] from a import b reveal_type(b.value) # E: Revealed type is 'builtins.str' -b.c.value # E: Module has no attribute "c" +b.c.value # E: "Module" has no attribute "c" a.value # E: Name 'a' is not defined [file a/__init__.py] @@ -853,7 +853,7 @@ bar = parent.unrelated.ShouldNotLoad() [builtins fixtures/module.pyi] [out] tmp/parent/child.py:8: error: Revealed type is 'parent.common.SomeClass' -tmp/parent/child.py:9: error: Module has no attribute "unrelated" +tmp/parent/child.py:9: error: "Module" has no attribute "unrelated" [case testSubmoduleMixingImportFromAndImport2] import parent.child @@ -915,7 +915,7 @@ class z: pass [out] main:2: error: Incompatible import of "x" (imported name has type "str", local name has type "int") main:2: error: Incompatible import of "y" (imported name has type Callable[[], str], local name has type Callable[[], int]) -main:2: error: Incompatible import of "z" (imported name has type Type[b.z], local name has type Type[a.z]) +main:2: error: Incompatible import of "z" (imported name has type "Type[b.z]", local name has type "Type[a.z]") -- Misc diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 81aa3f6957e6..9f803bbcc558 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -221,7 +221,7 @@ a = (1,) # E: Incompatible types in assignment (expression has type "Tuple[int] [case testNamedTupleMissingClassAttribute] import collections MyNamedTuple = collections.namedtuple('MyNamedTuple', ['spam', 'eggs']) -MyNamedTuple.x # E: Type[MyNamedTuple] has no attribute "x" +MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" [case testNamedTupleEmptyItems] @@ -286,7 +286,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) reveal_type(X._make([5, 'a'])) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' -X._make('a b') # E: Argument 1 to X._make has incompatible type "str"; expected Iterable[Any] +X._make('a b') # E: Argument 1 to X._make has incompatible type "str"; expected "Iterable[Any]" -- # FIX: not a proper class method -- x = None # type: X @@ -420,7 +420,7 @@ class C: A = NamedTuple('A', [('x', int)]) def g(self): A = NamedTuple('A', [('y', int)]) -C.A # E: Type[C] has no attribute "A" +C.A # E: "Type[C]" has no attribute "A" [case testNamedTupleInFunction] from typing import NamedTuple diff --git a/test-data/unit/check-newsyntax.test b/test-data/unit/check-newsyntax.test index 9f3f87853e63..f17b324cbca2 100644 --- a/test-data/unit/check-newsyntax.test +++ b/test-data/unit/check-newsyntax.test @@ -29,7 +29,7 @@ from typing import Dict, Any d: Dict[int, str] = {} d[42] = 'ab' d[42] = 42 # E: Incompatible types in assignment (expression has type "int", target has type "str") -d['ab'] = 'ab' # E: Invalid index type "str" for Dict[int, str]; expected type "int" +d['ab'] = 'ab' # E: Invalid index type "str" for "Dict[int, str]"; expected type "int" [builtins fixtures/dict.pyi] [out] @@ -61,29 +61,29 @@ TstInstance().a = 'ab' [case testNewSyntaxWithClassVars] # flags: --strict-optional --python-version 3.6 class CCC: - a: str = None # E: Incompatible types in assignment (expression has type None, variable has type "str") + a: str = None # E: Incompatible types in assignment (expression has type "None", variable has type "str") [out] [case testNewSyntaxWithStrictOptional] # flags: --strict-optional --python-version 3.6 strict: int -strict = None # E: Incompatible types in assignment (expression has type None, variable has type "int") -strict2: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") +strict = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") +strict2: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxWithStrictOptionalFunctions] # flags: --strict-optional --python-version 3.6 def f() -> None: x: int - x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxWithStrictOptionalClasses] # flags: --strict-optional --python-version 3.6 class C: def meth(self) -> None: - x: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") - self.x: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + x: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") + self.x: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxSpecialAssign] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 6ae6df914376..ed9226116c00 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -2,11 +2,11 @@ [case testImplicitNoneType] x = None -x() # E: None not callable +x() # E: "None" not callable [case testExplicitNoneType] x = None # type: None -x() # E: None not callable +x() # E: "None" not callable [case testNoneMemberOfOptional] from typing import Optional @@ -19,12 +19,12 @@ x = 0 # type: Optional[int] [case testNoneNotMemberOfType] x = None # type: int [out] -main:1: error: Incompatible types in assignment (expression has type None, variable has type "int") +main:1: error: Incompatible types in assignment (expression has type "None", variable has type "int") [case testTypeNotMemberOfNone] x = 0 # type: None [out] -main:1: error: Incompatible types in assignment (expression has type "int", variable has type None) +main:1: error: Incompatible types in assignment (expression has type "int", variable has type "None") [case testOptionalNotMemberOfType] from typing import Optional @@ -182,13 +182,13 @@ reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.None]' [case testInferOptionalListType] x = [None] -x.append(1) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected None +x.append(1) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "None" [builtins fixtures/list.pyi] [case testInferNonOptionalListType] x = [] x.append(1) -x() # E: List[int] not callable +x() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testInferOptionalDictKeyValueTypes] @@ -196,13 +196,13 @@ x = {None: None} x["bar"] = 1 [builtins fixtures/dict.pyi] [out] -main:2: error: Invalid index type "str" for Dict[None, None]; expected type None -main:2: error: Incompatible types in assignment (expression has type "int", target has type None) +main:2: error: Invalid index type "str" for "Dict[None, None]"; expected type "None" +main:2: error: Incompatible types in assignment (expression has type "int", target has type "None") [case testInferNonOptionalDictType] x = {} x["bar"] = 1 -x() # E: Dict[str, int] not callable +x() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testNoneClassVariable] @@ -217,7 +217,7 @@ from typing import Optional class C: x = None # type: int def __init__(self) -> None: - self.x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + self.x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testMultipleAssignmentNoneClassVariableInInit] @@ -225,8 +225,8 @@ from typing import Optional class C: x, y = None, None # type: int, str def __init__(self) -> None: - self.x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") - self.y = None # E: Incompatible types in assignment (expression has type None, variable has type "str") + self.x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") + self.y = None # E: Incompatible types in assignment (expression has type "None", variable has type "str") [out] [case testOverloadWithNone] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 69289fae18c1..4f359a3efefb 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -447,7 +447,7 @@ from foo import * from typing import overload t, a = None, None # type: (type, A) -a = A # E: Incompatible types in assignment (expression has type Type[A], variable has type "A") +a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") t = A class A: @@ -610,7 +610,7 @@ n = 1 m = 1 n = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") m = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -f(list_object) # E: Argument 1 to "f" has incompatible type List[object]; expected List[int] +f(list_object) # E: Argument 1 to "f" has incompatible type "List[object]"; expected "List[int]" [builtins fixtures/list.pyi] [case testOverlappingOverloadSignatures] @@ -901,7 +901,7 @@ def f(x: int, y: List[int] = None) -> int: pass def f(x: int, y: List[str] = None) -> int: pass f(y=[1], x=0)() # E: "int" not callable f(y=[''], x=0)() # E: "int" not callable -a = f(y=[['']], x=0) # E: List item 0 has incompatible type List[str] +a = f(y=[['']], x=0) # E: List item 0 has incompatible type "List[str]" a() # E: "int" not callable [builtins fixtures/list.pyi] @@ -1117,14 +1117,14 @@ def f(x: int, y: Tuple[str, ...]) -> None: pass @overload def f(x: int, y: str) -> None: pass f(1, ('2', '3')) -f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "Tuple[int, str]"; expected Tuple[str, ...] +f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "Tuple[int, str]"; expected "Tuple[str, ...]" f(1, ('2',)) f(1, '2') -f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "Tuple[int, int]"; expected Tuple[str, ...] +f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "Tuple[int, int]"; expected "Tuple[str, ...]" x = ('2', '3') # type: Tuple[str, ...] f(1, x) y = (2, 3) # type: Tuple[int, ...] -f(1, y) # E: Argument 2 to "f" has incompatible type Tuple[int, ...]; expected Tuple[str, ...] +f(1, y) # E: Argument 2 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[str, ...]" [builtins fixtures/tuple.pyi] [case testCallableSpecificOverload] diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index b3b899b21560..24022f4b15d8 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -34,7 +34,7 @@ class A: print >>A(), '' print >>None, '' print >>1, '' # E: "int" has no attribute "write" -print >>(None + ''), None # E: Unsupported left operand type for + (None) +print >>(None + ''), None # E: Unsupported left operand type for + ("None") [case testDivision] class A: @@ -291,7 +291,7 @@ class A(object): __metaclass__ = M y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] from typing import Any, Type diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 8c1f85b1d743..a8071d68b1e6 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -377,7 +377,7 @@ import typing assert None + None # Fail assert None [out] -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") -- Exception handling @@ -599,9 +599,9 @@ main:7: error: Incompatible redefinition (redefinition with type Callable[[], st [case testExceptWithoutType] import typing try: - -None # E: Unsupported operand type for unary - (None) + -None # E: Unsupported operand type for unary - ("None") except: - ~None # E: Unsupported operand type for ~ (None) + ~None # E: Unsupported operand type for ~ ("None") [builtins fixtures/exception.pyi] [case testRaiseWithoutArgument] @@ -1189,7 +1189,7 @@ def g() -> Iterator[List[int]]: yield [2, 3, 4] def f() -> Iterator[List[int]]: yield from g() - yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type List[int]) + yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type "List[int]") [builtins fixtures/for.pyi] [out] @@ -1429,7 +1429,7 @@ y = 1 from typing import List bs, cs = None, None # type: List[A], List[B] *bs, b = bs -*bs, c = cs # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +*bs, c = cs # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") *ns, c = cs nc = cs diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 08345706f0d9..ded930ae6d7e 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -91,7 +91,7 @@ from typing import Tuple t1 = None # type: Tuple[A, A] t2 = None # type: tuple -t1 = t2 # E: Incompatible types in assignment (expression has type Tuple[Any, ...], variable has type "Tuple[A, A]") +t1 = t2 # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "Tuple[A, A]") t2 = t1 class A: pass @@ -388,7 +388,7 @@ aa, bb, *cc = t # E: Need type annotation for variable from typing import List li, lo = None, None # type: List[int], List[object] a, b, *c = 1, 2 # type: int, int, List[int] -c = lo # E: Incompatible types in assignment (expression has type List[object], variable has type List[int]) +c = lo # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[int]") c = li [builtins fixtures/list.pyi] @@ -450,14 +450,14 @@ class A: pass [out] main:6: error: List item 0 has incompatible type "A" main:6: error: List item 1 has incompatible type "A" -main:9: error: Incompatible types in assignment (expression has type "A", variable has type List[A]) +main:9: error: Incompatible types in assignment (expression has type "A", variable has type "List[A]") [case testAssignmentToStarFromTupleInference] from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = A(), A() -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -469,7 +469,7 @@ from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = [A(), A()] -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -482,7 +482,7 @@ li = None # type: List[int] la = None # type: List[A] ta = None # type: Tuple[A, A, A] a, *l = ta -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -494,7 +494,7 @@ from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = la -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -579,7 +579,7 @@ class LongTypeName: def __add__(self, x: 'LongTypeName') -> 'LongTypeName': pass [builtins fixtures/tuple.pyi] [out] -main:3: error: Unsupported operand types for + ("LongTypeName" and tuple(length 50)) +main:3: error: Unsupported operand types for + ("LongTypeName" and "tuple(length 50)") -- Tuple methods @@ -750,7 +750,7 @@ tb = () # type: Tuple[B, ...] fa(ta) fa(tb) fb(tb) -fb(ta) # E: Argument 1 to "fb" has incompatible type Tuple[A, ...]; expected Tuple[B, ...] +fb(ta) # E: Argument 1 to "fb" has incompatible type "Tuple[A, ...]"; expected "Tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingFixedAndVariableLengthTuples] @@ -766,8 +766,8 @@ fa(aa) fa(ab) fa(bb) fb(bb) -fb(ab) # E: Argument 1 to "fb" has incompatible type "Tuple[A, B]"; expected Tuple[B, ...] -fb(aa) # E: Argument 1 to "fb" has incompatible type "Tuple[A, A]"; expected Tuple[B, ...] +fb(ab) # E: Argument 1 to "fb" has incompatible type "Tuple[A, B]"; expected "Tuple[B, ...]" +fb(aa) # E: Argument 1 to "fb" has incompatible type "Tuple[A, A]"; expected "Tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingTupleIsContainer] @@ -913,7 +913,7 @@ def f(a: Tuple) -> None: pass f(()) f((1,)) f(('', '')) -f(0) # E: Argument 1 to "f" has incompatible type "int"; expected Tuple[Any, ...] +f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[Any, ...]" [builtins fixtures/tuple.pyi] [case testTupleSingleton] diff --git a/test-data/unit/check-type-checks.test b/test-data/unit/check-type-checks.test index c4905a75ef78..dc3265238794 100644 --- a/test-data/unit/check-type-checks.test +++ b/test-data/unit/check-type-checks.test @@ -107,7 +107,7 @@ def f(x: object) -> None: if isinstance(x, C): x.f(1) x.f('') - x.g() # E: C[Any] has no attribute "g" + x.g() # E: "C[Any]" has no attribute "g" x.g() # E: "object" has no attribute "g" [builtins fixtures/isinstance.pyi] [out] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 4714ec77f3dc..16010e5b9d1a 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -283,7 +283,7 @@ from mypy_extensions import TypedDict from typing import Mapping Point = TypedDict('Point', {'x': int, 'y': int}) def as_mapping(p: Point) -> Mapping[str, str]: - return p # E: Incompatible return value type (got "Point", expected Mapping[str, str]) + return p # E: Incompatible return value type (got "Point", expected "Mapping[str, str]") [builtins fixtures/dict.pyi] [case testTypedDictAcceptsIntForFloatDuckTypes] @@ -344,9 +344,9 @@ from mypy_extensions import TypedDict from typing import Dict, MutableMapping Point = TypedDict('Point', {'x': int, 'y': int}) def as_dict(p: Point) -> Dict[str, int]: - return p # E: Incompatible return value type (got "Point", expected Dict[str, int]) + return p # E: Incompatible return value type (got "Point", expected "Dict[str, int]") def as_mutable_mapping(p: Point) -> MutableMapping[str, int]: - return p # E: Incompatible return value type (got "Point", expected MutableMapping[str, int]) + return p # E: Incompatible return value type (got "Point", expected "MutableMapping[str, int]") [builtins fixtures/dict.pyi] [case testCanConvertTypedDictToAny] @@ -639,7 +639,7 @@ class C: A = TypedDict('A', {'x': int}) def g(self): A = TypedDict('A', {'y': int}) -C.A # E: Type[C] has no attribute "A" +C.A # E: "Type[C]" has no attribute "A" [builtins fixtures/dict.pyi] [case testTypedDictInFunction] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 36df2235a209..8dc6d32a55c1 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -270,7 +270,7 @@ y = C(S()) x = y y = x c_int = C(1) # type: C[int] -y = c_int # E: Incompatible types in assignment (expression has type C[int], variable has type C[str]) +y = c_int # E: Incompatible types in assignment (expression has type "C[int]", variable has type "C[str]") [case testGenericTypeBodyWithTypevarValues] from typing import TypeVar, Generic diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 75e6f88c0c35..bbd538bc07ec 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -84,7 +84,7 @@ main:6: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" import typing MYPY = 0 if MYPY: - None + 1 # E: Unsupported left operand type for + (None) + None + 1 # E: Unsupported left operand type for + ("None") else: None + '' [builtins fixtures/bool.pyi] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 566841888693..802c6c8c8b86 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -10,8 +10,8 @@ from typing import Tuple def f( *b: 'B') -> None: ab = None # type: Tuple[B, ...] ac = None # type: Tuple[C, ...] - b = ac # E: Incompatible types in assignment (expression has type Tuple[C, ...], variable has type Tuple[B, ...]) - ac = b # E: Incompatible types in assignment (expression has type Tuple[B, ...], variable has type Tuple[C, ...]) + b = ac # E: Incompatible types in assignment (expression has type "Tuple[C, ...]", variable has type "Tuple[B, ...]") + ac = b # E: Incompatible types in assignment (expression has type "Tuple[B, ...]", variable has type "Tuple[C, ...]") b = ab ab = b @@ -108,7 +108,7 @@ it1 = None # type: Iterable[int] it2 = None # type: Iterable[str] def f(*x: int) -> None: pass f(*it1) -f(*it2) # E: Argument 1 to "f" has incompatible type *Iterable[str]; expected "int" +f(*it2) # E: Argument 1 to "f" has incompatible type *"Iterable[str]"; expected "int" [builtins fixtures/for.pyi] [case testCallVarargsFunctionWithIterableAndPositional] @@ -208,7 +208,7 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:7: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" +main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" [case testCallingWithTupleVarArgs] @@ -277,13 +277,13 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:3: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" -main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" +main:3: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" main:5: error: Argument 1 to "f" has incompatible type "B"; expected "A" main:6: error: Argument 2 to "f" has incompatible type "A"; expected "B" -main:7: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:7: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 1 to "g" has incompatible type *List[B]; expected "A" +main:9: error: Argument 1 to "g" has incompatible type *"List[B]"; expected "A" [case testCallingVarArgsFunctionWithTupleVarArgs] @@ -340,7 +340,7 @@ from typing import List aa = None # type: List[A] ab = None # type: List[B] -g(*aa) # E: Argument 1 to "g" has incompatible type *List[A]; expected "B" +g(*aa) # E: Argument 1 to "g" has incompatible type *"List[A]"; expected "B" f(*aa) f(*ab) g(*ab) @@ -377,8 +377,8 @@ class B: pass [builtins fixtures/list.pyi] [out] main:3: error: Too few arguments for "f" -main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" -main:5: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" +main:5: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:6: error: Argument 1 to "f" has incompatible type *"Tuple[A, A, B]"; expected "B" [case testVarArgsAfterKeywordArgInCall1-skip] @@ -491,11 +491,11 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:6: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" -main:7: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" +main:6: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" -main:10: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:9: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" +main:10: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:11: error: List or tuple expected as variable arguments main:12: error: List or tuple expected as variable arguments @@ -533,8 +533,8 @@ a, aa = G().f(*[a]) # Fail aa, a = G().f(*[a]) # Fail ab, aa = G().f(*[a]) # Fail -ao, ao = G().f(*[a]) # E: Incompatible types in assignment (expression has type List[], variable has type List[object]) -aa, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type List[], variable has type List[A]) +ao, ao = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[]", variable has type "List[object]") +aa, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") class G(Generic[T]): def f(self, *a: S) -> Tuple[List[S], List[T]]: @@ -544,11 +544,11 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:9: error: Incompatible types in assignment (expression has type List[A], variable has type "A") -main:9: error: Incompatible types in assignment (expression has type List[], variable has type List[A]) -main:10: error: Incompatible types in assignment (expression has type List[], variable has type "A") -main:11: error: Incompatible types in assignment (expression has type List[], variable has type List[A]) -main:11: error: Argument 1 to "f" of "G" has incompatible type *List[A]; expected "B" +main:9: error: Incompatible types in assignment (expression has type "List[A]", variable has type "A") +main:9: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") +main:10: error: Incompatible types in assignment (expression has type "List[]", variable has type "A") +main:11: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") +main:11: error: Argument 1 to "f" of "G" has incompatible type *"List[A]"; expected "B" -- Comment signatures From 466a832ab0dc9cdbf01a5a6e9ab90cc1f30cac90 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 15:57:10 -0700 Subject: [PATCH 02/25] No quotes around Module --- mypy/messages.py | 3 +++ test-data/unit/check-ignore.test | 4 ++-- test-data/unit/check-incremental.test | 6 +++--- test-data/unit/check-modules.test | 16 ++++++++-------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index ad158d4edc9f..209b2ebf7726 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -241,6 +241,9 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: None -> None callable type -> "" (empty string) """ + ret = self._format_simple(typ, verbosity) + if ret == "Module": + return ret return '"{}"'.format(self._format_simple(typ, verbosity)) def _format_simple(self, typ: Type, verbosity: int = 0) -> str: diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 5f2fd773a0c1..ad183ac1fe2b 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -46,7 +46,7 @@ import b # type: ignore reveal_type(a.foo) # E: Revealed type is 'Any' reveal_type(b.foo) # E: Revealed type is 'builtins.int' a.bar() -b.bar() # E: "Module" has no attribute "bar" +b.bar() # E: Module has no attribute "bar" [file b.py] foo = 3 @@ -76,7 +76,7 @@ class B(A): import m m.x = object # type: ignore m.f() # type: ignore -m.y # E: "Module" has no attribute "y" +m.y # E: Module has no attribute "y" [file m.py] [builtins fixtures/module.pyi] diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 78da587098ec..23fafc24edf5 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -325,7 +325,7 @@ const = 3 [stale mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod4" +tmp/mod1.py:3: error: Module has no attribute "mod4" [case testIncrementalLongBrokenCascade] import mod1 @@ -360,7 +360,7 @@ const = 3 [stale mod6] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod7" +tmp/mod1.py:3: error: Module has no attribute "mod7" [case testIncrementalNestedBrokenCascade] import mod1 @@ -386,7 +386,7 @@ const = 3 [stale mod2.mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod4" +tmp/mod1.py:3: error: Module has no attribute "mod4" [case testIncrementalNestedBrokenCascadeWithType1] import mod1, mod2.mod3.mod5 diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 10c6a22680d6..423994ad981b 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -155,16 +155,16 @@ import m import typing class A: pass -m() # E: "Module" not callable -a = m # type: A # E: Incompatible types in assignment (expression has type "Module", variable has type "A") -m + None # E: Unsupported left operand type for + ("Module") +m() # E: Module not callable +a = m # type: A # E: Incompatible types in assignment (expression has type Module, variable has type "A") +m + None # E: Unsupported left operand type for + (Module) [file m.py] [builtins fixtures/module.pyi] [case testNameDefinedInDifferentModule] import m, n import typing -m.x # E: "Module" has no attribute "x" +m.x # E: Module has no attribute "x" [file m.py] y = object() [file n.py] @@ -330,7 +330,7 @@ import nonexistent [out] tmp/x.py:1: error: Cannot find module named 'nonexistent' tmp/x.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:3: error: "Module" has no attribute "z" +main:3: error: Module has no attribute "z" [case testUnknownModuleImportedWithinFunction] def f(): @@ -648,7 +648,7 @@ def f(x: str) -> None: pass if object(): import m else: - m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Module") + m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Module) [file m.py] [builtins fixtures/module.pyi] [out] @@ -752,7 +752,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents] from a import b reveal_type(b.value) # E: Revealed type is 'builtins.str' -b.c.value # E: "Module" has no attribute "c" +b.c.value # E: Module has no attribute "c" a.value # E: Name 'a' is not defined [file a/__init__.py] @@ -853,7 +853,7 @@ bar = parent.unrelated.ShouldNotLoad() [builtins fixtures/module.pyi] [out] tmp/parent/child.py:8: error: Revealed type is 'parent.common.SomeClass' -tmp/parent/child.py:9: error: "Module" has no attribute "unrelated" +tmp/parent/child.py:9: error: Module has no attribute "unrelated" [case testSubmoduleMixingImportFromAndImport2] import parent.child From dc7c243e05e0cb79efdcccec7517f7fc5c0043b8 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 16:53:16 -0700 Subject: [PATCH 03/25] And even more tests that need to be updated --- test-data/unit/pythoneval-asyncio.test | 8 ++++---- test-data/unit/pythoneval.test | 28 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 6d1690339ff7..114cd4b9cb66 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -339,7 +339,7 @@ loop.run_until_complete(future) print(future.result()) loop.close() [out] -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type Future[str]; expected Future[int] +_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorUsingDifferentFutureTypeAndSetFutureDifferentInternalType] from typing import Generator, Any @@ -359,7 +359,7 @@ print(future.result()) loop.close() [out] _program.py:8: error: Argument 1 to "set_result" of "Future" has incompatible type "str"; expected "int" -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type Future[str]; expected Future[int] +_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorSettingCallbackWithDifferentFutureType] import typing @@ -422,7 +422,7 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got Future[Future[int]], expected Future[Future[Future[int]]]) +_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[Future[Future[int]]]") [case testErrorOneLessFutureInReturnType] import typing @@ -456,7 +456,7 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got Future[Future[int]], expected Future[int]) +_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[int]") [case testErrorAssignmentDifferentType] import typing diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 92b9906f9b53..704ccffcf65d 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -391,7 +391,7 @@ txt(sys.stdout) bin(sys.stdout) [out] _program.py:5: error: Argument 1 to "write" of "IO" has incompatible type "bytes"; expected "str" -_program.py:10: error: Argument 1 to "bin" has incompatible type "TextIO"; expected IO[bytes] +_program.py:10: error: Argument 1 to "bin" has incompatible type "TextIO"; expected "IO[bytes]" [case testBuiltinOpen] f = open('x') @@ -399,7 +399,7 @@ f.write('x') f.write(b'x') f.foobar() [out] -_program.py:4: error: IO[Any] has no attribute "foobar" +_program.py:4: error: "IO[Any]" has no attribute "foobar" [case testGenericPatterns] from typing import Pattern @@ -577,7 +577,7 @@ print(tuple(a)) import typing [1] + iter([2, 3]) [out] -_program.py:2: error: Unsupported operand types for + (List[int] and Iterator[int]) +_program.py:2: error: Unsupported operand types for + ("List[int]" and "Iterator[int]") [case testInferHeterogeneousListOfIterables] from typing import Sequence @@ -766,7 +766,7 @@ x = range(3) a = list(map(str, x)) a + 1 [out] -_program.py:4: error: Unsupported operand types for + (List[str] and "int") +_program.py:4: error: Unsupported operand types for + ("List[str]" and "int") [case testNamedTuple] import typing @@ -968,7 +968,7 @@ def f(*x: int) -> None: x.append(1) f(1) [out] -_program.py:3: error: Tuple[int, ...] has no attribute "append" +_program.py:3: error: "Tuple[int, ...]" has no attribute "append" [case testExit] print('a') @@ -1049,14 +1049,14 @@ n = 4 t = ('',) * n t + 1 [out] -_program.py:3: error: Unsupported operand types for + (Tuple[str, ...] and "int") +_program.py:3: error: Unsupported operand types for + ("Tuple[str, ...]" and "int") [case testMultiplyTupleByIntegerReverse] n = 4 t = n * ('',) t + 1 [out] -_program.py:3: error: Unsupported operand types for + (Tuple[str, ...] and "int") +_program.py:3: error: Unsupported operand types for + ("Tuple[str, ...]" and "int") [case testDictWithKeywordArgs] from typing import Dict, Any, List @@ -1068,7 +1068,7 @@ d4 = dict(a=1, b='') # type: Dict[str, Any] result = dict(x=[], y=[]) # type: Dict[str, List[str]] [out] _program.py:3: error: Dict entry 1 has incompatible type "str": "str" -_program.py:5: error: Dict[str, int] has no attribute "xyz" +_program.py:5: error: "Dict[str, int]" has no attribute "xyz" [case testDefaultDict] import typing as t @@ -1096,11 +1096,11 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]): MyDDict(dict)['0'] MyDDict(dict)[0] [out] -_program.py:6: error: Argument 1 to "defaultdict" has incompatible type Type[List[Any]]; expected Callable[[], str] -_program.py:9: error: Invalid index type "str" for defaultdict[int, str]; expected type "int" +_program.py:6: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected Callable[[], str] +_program.py:9: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int" _program.py:9: error: Incompatible types in assignment (expression has type "int", target has type "str") -_program.py:19: error: Dict entry 0 has incompatible type "str": List[] -_program.py:23: error: Invalid index type "str" for MyDDict[Dict[_KT, _VT]]; expected type "int" +_program.py:19: error: Dict entry 0 has incompatible type "str": "List[]" +_program.py:23: error: Invalid index type "str" for "MyDDict[Dict[_KT, _VT]]"; expected type "int" [case testNoSubcriptionOfStdlibCollections] import collections @@ -1122,7 +1122,7 @@ def f(d: collections.defaultdict[int, str]) -> None: _program.py:5: error: "defaultdict" is not subscriptable _program.py:6: error: "Counter" is not subscriptable _program.py:9: error: "defaultdict" is not subscriptable -_program.py:12: error: Invalid index type "int" for defaultdict[str, int]; expected type "str" +_program.py:12: error: Invalid index type "int" for "defaultdict[str, int]"; expected type "str" _program.py:14: error: "defaultdict" is not subscriptable, use "typing.DefaultDict" instead [case testCollectionsAliases] @@ -1150,7 +1150,7 @@ reveal_type(o6) [out] _testCollectionsAliases.py:5: error: Revealed type is 'collections.Counter[builtins.int]' -_testCollectionsAliases.py:6: error: Invalid index type "str" for Counter[int]; expected type "int" +_testCollectionsAliases.py:6: error: Invalid index type "str" for "Counter[int]"; expected type "int" _testCollectionsAliases.py:9: error: Revealed type is 'collections.ChainMap[builtins.int, builtins.str]' _testCollectionsAliases.py:12: error: Revealed type is 'collections.deque[builtins.int]' _testCollectionsAliases.py:15: error: Revealed type is 'collections.Counter[builtins.int*]' From df586333597daa985c84c14ee6ae3e0ef41df741 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 21:40:53 -0700 Subject: [PATCH 04/25] incorrect indentation --- mypy/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index 209b2ebf7726..423ff0a65f29 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -243,7 +243,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: """ ret = self._format_simple(typ, verbosity) if ret == "Module": - return ret + return ret return '"{}"'.format(self._format_simple(typ, verbosity)) def _format_simple(self, typ: Type, verbosity: int = 0) -> str: From ba55b1af4fa9f3c20e8dcee3a496f7f33597da93 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 14:28:03 -0700 Subject: [PATCH 05/25] Consistent quote wrapping around MessageBuilder.format as per issue #3409 --- mypy/messages.py | 25 ++++--- test-data/unit/check-async-await.test | 40 +++++----- test-data/unit/check-class-namedtuple.test | 6 +- test-data/unit/check-classes.test | 52 ++++++------- test-data/unit/check-dynamic-typing.test | 2 +- test-data/unit/check-enum.test | 2 +- test-data/unit/check-expressions.test | 36 ++++----- test-data/unit/check-flags.test | 4 +- test-data/unit/check-functions.test | 16 ++-- test-data/unit/check-generic-subtyping.test | 66 ++++++++--------- test-data/unit/check-generics.test | 66 ++++++++--------- test-data/unit/check-ignore.test | 6 +- test-data/unit/check-incremental.test | 6 +- test-data/unit/check-inference-context.test | 46 ++++++------ test-data/unit/check-inference.test | 82 ++++++++++----------- test-data/unit/check-isinstance.test | 16 ++-- test-data/unit/check-kwargs.test | 24 +++--- test-data/unit/check-modules.test | 44 +++++------ test-data/unit/check-namedtuple.test | 6 +- test-data/unit/check-newsyntax.test | 14 ++-- test-data/unit/check-optional.test | 24 +++--- test-data/unit/check-overloading.test | 12 +-- test-data/unit/check-python2.test | 4 +- test-data/unit/check-statements.test | 10 +-- test-data/unit/check-tuples.test | 24 +++--- test-data/unit/check-type-checks.test | 2 +- test-data/unit/check-typeddict.test | 8 +- test-data/unit/check-typevar-values.test | 2 +- test-data/unit/check-unreachable-code.test | 2 +- test-data/unit/check-varargs.test | 44 +++++------ 30 files changed, 347 insertions(+), 344 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 8dbf1dbeff95..461f1800b4a2 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -184,7 +184,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: Mostly behave like format_simple below, but never return an empty string. """ s = self.format_simple(typ, verbosity) - if s != '': + if s != '' and s != '""': # If format_simple returns a non-trivial result, use that. return s elif isinstance(typ, FunctionLike): @@ -242,6 +242,9 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: None -> None callable type -> "" (empty string) """ + return '"{}"'.format(self._format_simple(typ, verbosity)) + + def _format_simple(self, typ: Type, verbosity: int = 0) -> str: if isinstance(typ, Instance): itype = typ # Get the short name of the type. @@ -257,7 +260,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: # No type arguments. Place the type name in quotes to avoid # potential for confusion: otherwise, the type name could be # interpreted as a normal word. - return '"{}"'.format(base_str) + return base_str elif itype.type.fullname() == 'builtins.tuple': item_type_str = strip_quotes(self.format(itype.args[0])) return 'Tuple[{}, ...]'.format(item_type_str) @@ -281,15 +284,15 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: return '{}[...]'.format(base_str) elif isinstance(typ, TypeVarType): # This is similar to non-generic instance types. - return '"{}"'.format(typ.name) + return typ.name elif isinstance(typ, TupleType): # Prefer the name of the fallback class (if not tuple), as it's more informative. if typ.fallback.type.fullname() != 'builtins.tuple': - return self.format_simple(typ.fallback) + return self._format_simple(typ.fallback) items = [] for t in typ.items: items.append(strip_quotes(self.format(t))) - s = '"Tuple[{}]"'.format(', '.join(items)) + s = 'Tuple[{}]'.format(', '.join(items)) if len(s) < 400: return s else: @@ -297,11 +300,11 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, TypedDictType): # If the TypedDictType is named, return the name if typ.fallback.type.fullname() != 'typing.Mapping': - return self.format_simple(typ.fallback) + return self._format_simple(typ.fallback) items = [] for (item_name, item_type) in typ.items.items(): items.append('{}={}'.format(item_name, strip_quotes(self.format(item_type)))) - s = '"TypedDict({})"'.format(', '.join(items)) + s = 'TypedDict({})'.format(', '.join(items)) return s elif isinstance(typ, UnionType): # Only print Unions as Optionals if the Optional wouldn't have to contain another Union @@ -309,12 +312,12 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: sum(isinstance(t, NoneTyp) for t in typ.items) == 1) if print_as_optional: rest = [t for t in typ.items if not isinstance(t, NoneTyp)] - return '"Optional[{}]"'.format(strip_quotes(self.format(rest[0]))) + return 'Optional[{}]'.format(strip_quotes(self.format(rest[0]))) else: items = [] for t in typ.items: items.append(strip_quotes(self.format(t))) - s = '"Union[{}]"'.format(', '.join(items)) + s = 'Union[{}]'.format(', '.join(items)) if len(s) < 400: return s else: @@ -322,7 +325,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, NoneTyp): return 'None' elif isinstance(typ, AnyType): - return '"Any"' + return 'Any' elif isinstance(typ, DeletedType): return '' elif isinstance(typ, UninhabitedType): @@ -332,7 +335,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: return '' elif isinstance(typ, TypeType): return 'Type[{}]'.format( - strip_quotes(self.format_simple(typ.item, verbosity))) + strip_quotes(self._format_simple(typ.item, verbosity))) elif typ is None: raise RuntimeError('Type is None') else: diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 672bf2b408b8..7d9f7bde2a13 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -84,7 +84,7 @@ async def f() -> int: x = await g() return x [out] -main:7: error: Incompatible types in await (actual type Generator[int, None, str], expected type Awaitable[Any]) +main:7: error: Incompatible types in await (actual type "Generator[int, None, str]", expected type "Awaitable[Any]") [case testAwaitIteratorError] @@ -95,7 +95,7 @@ async def f() -> int: x = await g() return x [out] -main:6: error: Incompatible types in await (actual type Iterator[Any], expected type Awaitable[Any]) +main:6: error: Incompatible types in await (actual type "Iterator[Any]", expected type "Awaitable[Any]") [case testAwaitArgumentError] @@ -106,7 +106,7 @@ async def f() -> int: return x [builtins fixtures/async_await.pyi] [out] -main:5: error: Incompatible types in await (actual type "int", expected type Awaitable[Any]) +main:5: error: Incompatible types in await (actual type "int", expected type "Awaitable[Any]") [case testAwaitResultError] @@ -150,7 +150,7 @@ async def f() -> None: [builtins fixtures/async_await.pyi] [out] main:4: error: AsyncIterable expected -main:4: error: List[int] has no attribute "__aiter__" +main:4: error: "List[int]" has no attribute "__aiter__" [case testAsyncForTypeComments] @@ -232,13 +232,13 @@ async def wrong_iterable(obj: Iterable[int]): [out] main:18: error: AsyncIterable expected -main:18: error: Iterable[int] has no attribute "__aiter__"; maybe "__iter__"? +main:18: error: "Iterable[int]" has no attribute "__aiter__"; maybe "__iter__"? main:19: error: Iterable expected -main:19: error: asyncify[int] has no attribute "__iter__"; maybe "__aiter__"? +main:19: error: "asyncify[int]" has no attribute "__iter__"; maybe "__aiter__"? main:20: error: AsyncIterable expected -main:20: error: Iterable[int] has no attribute "__aiter__"; maybe "__iter__"? +main:20: error: "Iterable[int]" has no attribute "__aiter__"; maybe "__iter__"? main:21: error: Iterable expected -main:21: error: asyncify[int] has no attribute "__iter__"; maybe "__aiter__"? +main:21: error: "asyncify[int]" has no attribute "__iter__"; maybe "__aiter__"? [builtins fixtures/async_await.pyi] [case testAsyncWith] @@ -271,7 +271,7 @@ class C: def __aenter__(self) -> int: pass async def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: Incompatible types in "async with" for __aenter__ (actual type "int", expected type Awaitable[Any]) + async with C() as x: # E: Incompatible types in "async with" for __aenter__ (actual type "int", expected type "Awaitable[Any]") pass [builtins fixtures/async_await.pyi] [out] @@ -282,7 +282,7 @@ class C: def __aenter__(self) -> None: pass async def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: None has no attribute "__await__" + async with C() as x: # E: "None" has no attribute "__await__" pass [builtins fixtures/async_await.pyi] [out] @@ -293,7 +293,7 @@ class C: async def __aenter__(self) -> int: pass def __aexit__(self, x, y, z) -> int: pass async def f() -> None: - async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type Awaitable[Any]) + async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type "Awaitable[Any]") pass [builtins fixtures/async_await.pyi] [out] @@ -304,7 +304,7 @@ class C: async def __aenter__(self) -> int: pass def __aexit__(self, x, y, z) -> None: pass async def f() -> None: - async with C() as x: # E: None has no attribute "__await__" + async with C() as x: # E: "None" has no attribute "__await__" pass [builtins fixtures/async_await.pyi] [out] @@ -362,7 +362,7 @@ def g() -> Generator[Any, None, str]: return x [builtins fixtures/async_await.pyi] [out] -main:6: error: "yield from" can't be applied to Awaitable[str] +main:6: error: "yield from" can't be applied to "Awaitable[str]" [case testAwaitableSubclass] @@ -523,7 +523,7 @@ def h() -> None: [out] main:9: error: Iterable expected -main:9: error: AsyncGenerator[int, None] has no attribute "__iter__"; maybe "__aiter__"? +main:9: error: "AsyncGenerator[int, None]" has no attribute "__iter__"; maybe "__aiter__"? [case testAsyncGeneratorNoYieldFrom] # flags: --fast-parser --python-version 3.6 @@ -607,19 +607,19 @@ def plain_host_generator() -> Generator[str, None, None]: yield 'a' x = 0 x = yield from plain_generator() - x = yield from plain_coroutine() # E: "yield from" can't be applied to Awaitable[int] + x = yield from plain_coroutine() # E: "yield from" can't be applied to "Awaitable[int]" x = yield from decorated_generator() - x = yield from decorated_coroutine() # E: "yield from" can't be applied to AwaitableGenerator[Any, Any, int, Awaitable[int]] + x = yield from decorated_coroutine() # E: "yield from" can't be applied to "AwaitableGenerator[Any, Any, int, Awaitable[int]]" x = yield from other_iterator() x = yield from other_coroutine() # E: "yield from" can't be applied to "Aw" async def plain_host_coroutine() -> None: x = 0 - x = await plain_generator() # E: Incompatible types in await (actual type Generator[str, None, int], expected type Awaitable[Any]) + x = await plain_generator() # E: Incompatible types in await (actual type "Generator[str, None, int]", expected type "Awaitable[Any]") x = await plain_coroutine() x = await decorated_generator() x = await decorated_coroutine() - x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type Awaitable[Any]) + x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type "Awaitable[Any]") x = await other_coroutine() @coroutine @@ -636,11 +636,11 @@ def decorated_host_generator() -> Generator[str, None, None]: @coroutine async def decorated_host_coroutine() -> None: x = 0 - x = await plain_generator() # E: Incompatible types in await (actual type Generator[str, None, int], expected type Awaitable[Any]) + x = await plain_generator() # E: Incompatible types in await (actual type "Generator[str, None, int]", expected type "Awaitable[Any]") x = await plain_coroutine() x = await decorated_generator() x = await decorated_coroutine() - x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type Awaitable[Any]) + x = await other_iterator() # E: Incompatible types in await (actual type "It", expected type "Awaitable[Any]") x = await other_coroutine() [builtins fixtures/async_await.pyi] diff --git a/test-data/unit/check-class-namedtuple.test b/test-data/unit/check-class-namedtuple.test index 7a81adb0a672..7ae6c1f936bf 100644 --- a/test-data/unit/check-class-namedtuple.test +++ b/test-data/unit/check-class-namedtuple.test @@ -221,7 +221,7 @@ class MyNamedTuple(NamedTuple): a: int b: str -MyNamedTuple.x # E: Type[MyNamedTuple] has no attribute "x" +MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" [case testNewNamedTupleEmptyItems] # flags: --python-version 3.6 @@ -439,13 +439,13 @@ class HasNone(NamedTuple): y: Optional[int] = None reveal_type(HasNone(1)) # E: Revealed type is 'Tuple[builtins.int, Union[builtins.int, builtins.None], fallback=__main__.HasNone]' -HasNone(None) # E: Argument 1 to "HasNone" has incompatible type None; expected "int" +HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int" HasNone(1, y=None) HasNone(1, y=2) class CannotBeNone(NamedTuple): x: int - y: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + y: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 0b6bb6873d62..14034770803d 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -514,7 +514,7 @@ b = A.x # type: B # E: Incompatible types in assignment (expression has type "A" [case testAccessingUndefinedAttributeViaClass] import typing class A: pass -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAccessingUndefinedAttributeViaClassWithOverloadedInit] from foo import * @@ -525,7 +525,7 @@ class A: def __init__(self): pass @overload def __init__(self, x): pass -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAccessMethodOfClassWithOverloadedInit] from foo import * @@ -812,7 +812,7 @@ class C: cls(1) # E: Too many arguments for "C" cls.bar() cls.bar(1) # E: Too many arguments for "bar" of "C" - cls.bozo() # E: Type[C] has no attribute "bozo" + cls.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [out] @@ -823,7 +823,7 @@ class C: def foo(cls) -> None: pass C.foo() C.foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: Type[C] has no attribute "bozo" +C.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodCalledOnInstance] @@ -833,7 +833,7 @@ class C: def foo(cls) -> None: pass C().foo() C().foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: Type[C] has no attribute "bozo" +C.bozo() # E: "Type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodMayCallAbstractMethod] @@ -1278,7 +1278,7 @@ class D: def __get__(self, inst: Any, own: str) -> Any: pass class A: f = D() -A().f # E: Argument 2 to "__get__" of "D" has incompatible type Type[A]; expected "str" +A().f # E: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "str" [case testDescriptorGetSetDifferentTypes] from typing import Any @@ -1722,7 +1722,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type Type[C]; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testClassWith__new__AndCompatibilityWithType2] @@ -1733,7 +1733,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type Type[C]; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testGenericClassWith__new__] @@ -1813,7 +1813,7 @@ class B: [case testClassVsInstanceDisambiguation] class A: pass def f(x: A) -> None: pass -f(A) # E: Argument 1 to "f" has incompatible type Type[A]; expected "A" +f(A) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "A" [out] -- TODO @@ -2020,7 +2020,7 @@ class User: pass def new_user(user_class: Type[User]): return user_class() def foo(arg: Type[int]): - new_user(arg) # E: Argument 1 to "new_user" has incompatible type Type[int]; expected Type[User] + new_user(arg) # E: Argument 1 to "new_user" has incompatible type "Type[int]"; expected "Type[User]" [out] [case testTypeUsingTypeCUnionOverload] @@ -2059,7 +2059,7 @@ def foo(arg: Type[Any]): # Member access is ok and types as Any reveal_type(x) # E: Revealed type is 'Any' # But Type[Any] is distinct from Any - y: int = arg # E: Incompatible types in assignment (expression has type Type[Any], variable has type "int") + y: int = arg # E: Incompatible types in assignment (expression has type "Type[Any]", variable has type "int") [out] [case testTypeUsingTypeCTypeAnyMemberFallback] @@ -2100,7 +2100,7 @@ def process(cls: Type[User]): obj = cls() reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' cls.mro() # Defined in class type - cls.error # E: Type[User] has no attribute "error" + cls.error # E: "Type[User]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2114,11 +2114,11 @@ class User: class ProUser(User): pass class BasicUser(User): pass def process(cls: Type[Union[BasicUser, ProUser]]): - cls.foo() # E: Type[Union[BasicUser, ProUser]] has no attribute "foo" + cls.foo() # E: "Type[Union[BasicUser, ProUser]]" has no attribute "foo" obj = cls() - cls.bar(obj) # E: Type[Union[BasicUser, ProUser]] has no attribute "bar" + cls.bar(obj) # E: "Type[Union[BasicUser, ProUser]]" has no attribute "bar" cls.mro() # Defined in class type - cls.error # E: Type[Union[BasicUser, ProUser]] has no attribute "error" + cls.error # E: "Type[Union[BasicUser, ProUser]]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2134,7 +2134,7 @@ def process(cls: Type[U]): obj = cls() reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' cls.mro() # Defined in class type - cls.error # E: Type[U] has no attribute "error" + cls.error # E: "Type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2149,11 +2149,11 @@ class ProUser(User): pass class BasicUser(User): pass U = TypeVar('U', bound=Union[ProUser, BasicUser]) def process(cls: Type[U]): - cls.foo() # E: Type[U] has no attribute "foo" + cls.foo() # E: "Type[U]" has no attribute "foo" obj = cls() - cls.bar(obj) # E: Type[U] has no attribute "bar" + cls.bar(obj) # E: "Type[U]" has no attribute "bar" cls.mro() # Defined in class type - cls.error # E: Type[U] has no attribute "error" + cls.error # E: "Type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -2621,7 +2621,7 @@ int.__eq__(3, 4) [builtins fixtures/args.pyi] [out] main:33: error: Too few arguments for "__eq__" of "int" -main:33: error: Unsupported operand types for == ("int" and Type[int]) +main:33: error: Unsupported operand types for == ("int" and "Type[int]") [case testMroSetAfterError] class C(str, str): @@ -2986,7 +2986,7 @@ class M: class A(metaclass=M): pass # E: Metaclasses not inheriting from 'type' are not supported -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testMetaclassTypeReveal] from typing import Type @@ -3057,7 +3057,7 @@ class Concrete(metaclass=Meta): pass reveal_type(Concrete + X()) # E: Revealed type is 'builtins.str' -Concrete + "hello" # E: Unsupported operand types for + (Type[Concrete] and "str") +Concrete + "hello" # E: Unsupported operand types for + ("Type[Concrete]" and "str") [case testMetaclassGetitem] class M(type): @@ -3085,7 +3085,7 @@ from missing import M class A(metaclass=M): y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyMetaclass] from typing import Any @@ -3093,7 +3093,7 @@ M = None # type: Any class A(metaclass=M): y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testInvalidVariableAsMetaclass] from typing import Any @@ -3104,7 +3104,7 @@ class A(metaclass=M): # E: Invalid metaclass 'M' class B(metaclass=MM): # E: Invalid metaclass 'MM' y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] from typing import Any, Type @@ -3119,7 +3119,7 @@ class A(metaclass=MM): def h(a: Type[A], b: Type[object]) -> None: h(a, a) - h(b, a) # E: Argument 1 to "h" has incompatible type Type[object]; expected Type[A] + h(b, a) # E: Argument 1 to "h" has incompatible type "Type[object]"; expected "Type[A]" a.f(1) # E: Too many arguments for "f" of "A" reveal_type(a.y) # E: Revealed type is 'builtins.int' diff --git a/test-data/unit/check-dynamic-typing.test b/test-data/unit/check-dynamic-typing.test index 68a174e3cc81..22626cfffd88 100644 --- a/test-data/unit/check-dynamic-typing.test +++ b/test-data/unit/check-dynamic-typing.test @@ -485,7 +485,7 @@ class A: def __init__(self, a, b): pass [out] main:6: error: Too few arguments for "A" -main:7: error: Incompatible types in assignment (expression has type Type[A], variable has type Callable[[A], A]) +main:7: error: Incompatible types in assignment (expression has type "Type[A]", variable has type Callable[[A], A]) [case testUsingImplicitTypeObjectWithIs] diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 011580effb35..d6e7a65abfc4 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -325,7 +325,7 @@ main:17: error: Enum() with dict literal requires string literals main:18: error: Unexpected arguments to Enum() main:19: error: Unexpected arguments to Enum() main:20: error: Unexpected arguments to Enum() -main:22: error: Type[W] has no attribute "c" +main:22: error: "Type[W]" has no attribute "c" [case testFunctionalEnumFlag] from enum import Flag, IntFlag diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index ae1498acdadd..6f27f4f29699 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1135,7 +1135,7 @@ b'%a' % 3 from typing import Any, Dict a = None # type: Any ds, do, di = None, None, None # type: Dict[str, int], Dict[object, int], Dict[int, int] -'%(a)' % 1 # E: Format requires a mapping (expression has type "int", expected type for mapping is Dict[Any, Any]) +'%(a)' % 1 # E: Format requires a mapping (expression has type "int", expected type for mapping is "Dict[Any, Any]") '%()d' % a '%()d' % ds '%()d' % do @@ -1308,7 +1308,7 @@ class B: pass [out] main:5: error: Key expression in dictionary comprehension has incompatible type "A"; expected type "B" main:5: error: Value expression in dictionary comprehension has incompatible type "B"; expected type "A" -main:6: error: Incompatible types in assignment (expression has type Dict[A, B], variable has type "A") +main:6: error: Incompatible types in assignment (expression has type "Dict[A, B]", variable has type "A") [case testDictionaryComprehensionWithNonDirectMapping] @@ -1394,7 +1394,7 @@ cast(A, f) def f() -> None: pass [out] -main:5: error: Unsupported left operand type for + (None) +main:5: error: Unsupported left operand type for + ("None") main:6: error: Unsupported left operand type for + (Callable[[], None]) main:7: error: Unsupported operand types for + ("A" and Callable[[], None]) @@ -1532,7 +1532,7 @@ d1 = dict(a=1, b=2) # type: Dict[str, int] d2 = dict(a=1, b='') # type: Dict[str, int] # E: Dict entry 1 has incompatible type "str": "str" d3 = dict(a=1) # type: Dict[int, int] # E: Dict entry 0 has incompatible type "str": "int" d4 = dict(a=1, b=1) -d4.xyz # E: Dict[str, int] has no attribute "xyz" +d4.xyz # E: "Dict[str, int]" has no attribute "xyz" d5 = dict(a=1, b='') # type: Dict[str, Any] [builtins fixtures/dict.pyi] @@ -1546,7 +1546,7 @@ dict(undefined) # E: Name 'undefined' is not defined [case testDictFromList] from typing import Dict d = dict([(1, 'x'), (2, 'y')]) -d() # E: Dict[int, str] not callable +d() # E: "Dict[int, str]" not callable d2 = dict([(1, 'x')]) # type: Dict[str, str] # E: List item 0 has incompatible type "Tuple[int, str]" [builtins fixtures/dict.pyi] @@ -1555,10 +1555,10 @@ from typing import Dict it = [('x', 1)] d = dict(it, x=1) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable d2 = dict(it, x='') # E: Cannot infer type argument 2 of "dict" -d2() # E: Dict[Any, Any] not callable +d2() # E: "Dict[Any, Any]" not callable d3 = dict(it, x='') # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type "str"; expected "int" [builtins fixtures/dict.pyi] @@ -1570,7 +1570,7 @@ dict(it, x='y') # E: Keyword argument only valid with "str" key type in call to [case testDictFromIterableAndKeywordArg3] d = dict([], x=1) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs] @@ -1579,20 +1579,20 @@ it = [('x', 1)] kw = {'x': 1} d = dict(it, **kw) -d() # E: Dict[str, int] not callable +d() # E: "Dict[str, int]" not callable kw2 = {'x': ''} d2 = dict(it, **kw2) # E: Cannot infer type argument 2 of "dict" -d2() # E: Dict[Any, Any] not callable +d2() # E: "Dict[Any, Any]" not callable -d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type **Dict[str, str]; expected "int" +d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type **"Dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs2] it = [(1, 'x')] kw = {'x': 'y'} d = dict(it, **kw) # E: Keyword argument only valid with "str" key type in call to "dict" -d() # E: Dict[int, str] not callable +d() # E: "Dict[int, str]" not callable [builtins fixtures/dict.pyi] [case testUserDefinedClassNamedDict] @@ -1612,10 +1612,10 @@ class D1(dict): pass # Implicit base class Dict[Any, Any] D1([(1, 2)], x=1) class D2(Dict[T, S], Generic[T, S]): pass da = D2([('x', 2)], x=1) -da() # E: D2[str, int] not callable +da() # E: "D2[str, int]" not callable D2([(1, 2)], x=1) # E: Keyword argument only valid with "str" key type in call to "dict" db = D2(x=1) -db() # E: D2[str, int] not callable +db() # E: "D2[str, int]" not callable [builtins fixtures/dict.pyi] [case testSpecialSignatureForSubclassOfDict2] @@ -1632,7 +1632,7 @@ S = TypeVar('S') class D(Dict[T, S], Generic[T, S]): def __init__(self, x: S, y: T) -> None: pass d = D(1, y='') -d() # E: D[str, int] not callable +d() # E: "D[str, int]" not callable [builtins fixtures/dict.pyi] [case testRevealType] @@ -1664,7 +1664,7 @@ None == None [builtins fixtures/ops.pyi] [case testLtNone] -None < None # E: Unsupported left operand type for < (None) +None < None # E: Unsupported left operand type for < ("None") [builtins fixtures/ops.pyi] [case testDictWithStarExpr] @@ -1679,6 +1679,6 @@ a = {'a': 1} b = {'z': 26, **a} c = {**b} d = {**a, **b, 'c': 3} -e = {1: 'a', **a} # E: Argument 1 to "update" of "dict" has incompatible type Dict[str, int]; expected Mapping[int, str] -f = {**b} # type: Dict[int, int] # E: List item 0 has incompatible type Dict[str, int] +e = {1: 'a', **a} # E: Argument 1 to "update" of "dict" has incompatible type "Dict[str, int]"; expected "Mapping[int, str]" +f = {**b} # type: Dict[int, int] # E: List item 0 has incompatible type "Dict[str, int]" [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 2b0e5549589a..b270ec8b854c 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -190,7 +190,7 @@ reveal_type(f() or no_return()) # E: Revealed type is 'builtins.int' # flags: --warn-no-return from mypy_extensions import NoReturn -x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn) +x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type "NoReturn") [builtins fixtures/dict.pyi] [case testNoReturnImportFromTyping] @@ -206,7 +206,7 @@ def no_return() -> NoReturn: pass def f() -> NoReturn: no_return() -x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn) +x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "NoReturn") [builtins fixtures/dict.pyi] [case testShowErrorContextFunction] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 343b4b79cf9f..3bd2de532384 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -254,7 +254,7 @@ class A: pass t = None # type: type a = None # type: A -a = A # E: Incompatible types in assignment (expression has type Type[A], variable has type "A") +a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") t = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type "type") t = A @@ -334,10 +334,10 @@ def f(x: C) -> C: pass from typing import Any, Callable, List def f(fields: List[Callable[[Any], Any]]): pass class C: pass -f([C]) # E: List item 0 has incompatible type +f([C]) # E: List item 0 has incompatible type "" class D: def __init__(self, a, b): pass -f([D]) # E: List item 0 has incompatible type +f([D]) # E: List item 0 has incompatible type "" [builtins fixtures/list.pyi] [case testSubtypingTypeTypeAsCallable] @@ -352,7 +352,7 @@ from typing import Callable, Type class A: pass x = None # type: Callable[..., A] y = None # type: Type[A] -y = x # E: Incompatible types in assignment (expression has type Callable[..., A], variable has type Type[A]) +y = x # E: Incompatible types in assignment (expression has type Callable[..., A], variable has type "Type[A]") -- Default argument values -- ----------------------- @@ -517,7 +517,7 @@ class A(Generic[t]): g = f a = None # type: A[B] a.g(B()) -a.g(a) # E: Argument 1 has incompatible type A[B]; expected "B" +a.g(a) # E: Argument 1 has incompatible type "A[B]"; expected "B" [case testInvalidMethodAsDataAttributeInGenericClass] from typing import Any, TypeVar, Generic, Callable @@ -1479,7 +1479,7 @@ L = Callable[[Arg(name='x', type=int)], int] # ok # I have commented out the following test because I don't know how to expect the "defined here" note part of the error. # M = Callable[[Arg(gnome='x', type=int)], int] E: Invalid type alias E: Unexpected keyword argument "gnome" for "Arg" N = Callable[[Arg(name=None, type=int)], int] # ok -O = Callable[[List[Arg(int)]], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type Type[List[Any]] is not generic and not indexable +O = Callable[[List[Arg(int)]], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type "Type[List[Any]]" is not generic and not indexable P = Callable[[mypy_extensions.VarArg(int)], int] # ok Q = Callable[[Arg(int, type=int)], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "type" R = Callable[[Arg(int, 'x', name='y')], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "name" @@ -1735,7 +1735,7 @@ f(x=1, y="hello", z=[]) from typing import Dict def f(x, **kwargs): # type: (...) -> None success_dict_type = kwargs # type: Dict[str, str] - failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type Dict[str, Any], variable has type Dict[int, str]) + failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[int, str]") f(1, thing_in_kwargs=["hey"]) [builtins fixtures/dict.pyi] [out] @@ -1744,7 +1744,7 @@ f(1, thing_in_kwargs=["hey"]) from typing import Tuple, Any def f(x, *args): # type: (...) -> None success_tuple_type = args # type: Tuple[Any, ...] - fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type Tuple[Any, ...], variable has type None) + fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "None") f(1, "hello") [builtins fixtures/tuple.pyi] [out] diff --git a/test-data/unit/check-generic-subtyping.test b/test-data/unit/check-generic-subtyping.test index 6cae196bbe80..9c5d242368a8 100644 --- a/test-data/unit/check-generic-subtyping.test +++ b/test-data/unit/check-generic-subtyping.test @@ -13,9 +13,9 @@ ac = None # type: A[C] ad = None # type: A[D] b = None # type: B -b = ad # E: Incompatible types in assignment (expression has type A[D], variable has type "B") -ad = b # E: Incompatible types in assignment (expression has type "B", variable has type A[D]) -b = ac # E: Incompatible types in assignment (expression has type A[C], variable has type "B") +b = ad # E: Incompatible types in assignment (expression has type "A[D]", variable has type "B") +ad = b # E: Incompatible types in assignment (expression has type "B", variable has type "A[D]") +b = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B") b = b ac = b @@ -32,10 +32,10 @@ a = None # type: A bc = None # type: B[C] bd = None # type: B[D] -bc = bd # E: Incompatible types in assignment (expression has type B[D], variable has type B[C]) -bd = bc # E: Incompatible types in assignment (expression has type B[C], variable has type B[D]) -bc = a # E: Incompatible types in assignment (expression has type "A", variable has type B[C]) -bd = a # E: Incompatible types in assignment (expression has type "A", variable has type B[D]) +bc = bd # E: Incompatible types in assignment (expression has type "B[D]", variable has type "B[C]") +bd = bc # E: Incompatible types in assignment (expression has type "B[C]", variable has type "B[D]") +bc = a # E: Incompatible types in assignment (expression has type "A", variable has type "B[C]") +bd = a # E: Incompatible types in assignment (expression has type "A", variable has type "B[D]") a = bc a = bd @@ -54,10 +54,10 @@ ad = None # type: A[D] bcc = None # type: B[C, C] bdc = None # type: B[D, C] -ad = bcc # E: Incompatible types in assignment (expression has type B[C, C], variable has type A[D]) -ad = bdc # E: Incompatible types in assignment (expression has type B[D, C], variable has type A[D]) -bcc = ac # E: Incompatible types in assignment (expression has type A[C], variable has type B[C, C]) -bdc = ac # E: Incompatible types in assignment (expression has type A[C], variable has type B[D, C]) +ad = bcc # E: Incompatible types in assignment (expression has type "B[C, C]", variable has type "A[D]") +ad = bdc # E: Incompatible types in assignment (expression has type "B[D, C]", variable has type "A[D]") +bcc = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B[C, C]") +bdc = ac # E: Incompatible types in assignment (expression has type "A[C]", variable has type "B[D, C]") bcc = bcc bdc = bdc @@ -82,8 +82,8 @@ cef = None # type: C[E, F] cff = None # type: C[F, F] cfe = None # type: C[F, E] -ae = cef # E: Incompatible types in assignment (expression has type C[E, F], variable has type A[A[E]]) -af = cfe # E: Incompatible types in assignment (expression has type C[F, E], variable has type A[A[F]]) +ae = cef # E: Incompatible types in assignment (expression has type "C[E, F]", variable has type "A[A[E]]") +af = cfe # E: Incompatible types in assignment (expression has type "C[F, E]", variable has type "A[A[F]]") ae = cfe af = cef @@ -280,7 +280,7 @@ a = None # type: A bc = None # type: B[C] bd = None # type: B[D] -a = bc # E: Incompatible types in assignment (expression has type B[C], variable has type "A") +a = bc # E: Incompatible types in assignment (expression has type "B[C]", variable has type "A") bc = a bd = a @@ -305,8 +305,8 @@ a = None # type: A c = None # type: C bc = None # type: B[C] -a.x = c # E: Incompatible types in assignment (expression has type "C", variable has type B[Any]) -a.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected B[Any] +a.x = c # E: Incompatible types in assignment (expression has type "C", variable has type "B[Any]") +a.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected "B[Any]" a.x = bc a.f(bc) [out] @@ -325,8 +325,8 @@ class B(Generic[T]): class A(B): def g(self) -> None: - self.x = c # E: Incompatible types in assignment (expression has type "C", variable has type B[Any]) - self.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected B[Any] + self.x = c # E: Incompatible types in assignment (expression has type "C", variable has type "B[Any]") + self.f(c) # E: Argument 1 to "f" of "B" has incompatible type "C"; expected "B[Any]" self.x = bc self.f(bc) @@ -394,7 +394,7 @@ B(1) C(1) C('a') # E: Argument 1 to "C" has incompatible type "str"; expected "int" D(A(1)) -D(1) # E: Argument 1 to "D" has incompatible type "int"; expected A[] +D(1) # E: Argument 1 to "D" has incompatible type "int"; expected "A[]" [case testInheritedConstructor2] @@ -427,9 +427,9 @@ adc = None # type: A[D, C] ic = None # type: I[C] id = None # type: I[D] -ic = acd # E: Incompatible types in assignment (expression has type A[C, D], variable has type I[C]) -id = adc # E: Incompatible types in assignment (expression has type A[D, C], variable has type I[D]) -adc = ic # E: Incompatible types in assignment (expression has type I[C], variable has type A[D, C]) +ic = acd # E: Incompatible types in assignment (expression has type "A[C, D]", variable has type "I[C]") +id = adc # E: Incompatible types in assignment (expression has type "A[D, C]", variable has type "I[D]") +adc = ic # E: Incompatible types in assignment (expression has type "I[C]", variable has type "A[D, C]") ic = adc id = acd @@ -451,11 +451,11 @@ class I(Generic[S]): pass class B(I[C]): pass class A(B): pass -ie = a # E: Incompatible types in assignment (expression has type "A", variable has type I[E]) -a = ic # E: Incompatible types in assignment (expression has type I[C], variable has type "A") -a = id # E: Incompatible types in assignment (expression has type I[D], variable has type "A") +ie = a # E: Incompatible types in assignment (expression has type "A", variable has type "I[E]") +a = ic # E: Incompatible types in assignment (expression has type "I[C]", variable has type "A") +a = id # E: Incompatible types in assignment (expression has type "I[D]", variable has type "A") a = b # E: Incompatible types in assignment (expression has type "B", variable has type "A") -id = a # E: Incompatible types in assignment (expression has type "A", variable has type I[D]) +id = a # E: Incompatible types in assignment (expression has type "A", variable has type "I[D]") ic = a b = a @@ -486,8 +486,8 @@ a, i, j = None, None, None # type: (A[object], I[object], J[object]) ii = a jj = a jj = i -a = i # E: Incompatible types in assignment (expression has type I[object], variable has type A[object]) -a = j # E: Incompatible types in assignment (expression has type J[object], variable has type A[object]) +a = i # E: Incompatible types in assignment (expression has type "I[object]", variable has type "A[object]") +a = j # E: Incompatible types in assignment (expression has type "J[object]", variable has type "A[object]") class J(Generic[t]): pass class X(metaclass=ABCMeta): pass @@ -546,7 +546,7 @@ class A(B): class C: pass class D: pass [out] -main:7: error: Incompatible types in assignment (expression has type "A", variable has type I[D]) +main:7: error: Incompatible types in assignment (expression has type "A", variable has type "I[D]") [case testSubclassingGenericABCWithDeepHierarchy2] from typing import Any, TypeVar, Generic @@ -704,7 +704,7 @@ a = None # type: G[A] b = None # type: G[B] c = None # type: G[C] -b = a # E: Incompatible types in assignment (expression has type G[A], variable has type G[B]) +b = a # E: Incompatible types in assignment (expression has type "G[A]", variable has type "G[B]") b = c [builtins fixtures/bool.pyi] [out] @@ -723,7 +723,7 @@ b = None # type: G[B] c = None # type: G[C] b = a -b = c # E: Incompatible types in assignment (expression has type G[C], variable has type G[B]) +b = c # E: Incompatible types in assignment (expression has type "G[C]", variable has type "G[B]") [builtins fixtures/bool.pyi] [out] @@ -740,8 +740,8 @@ a = None # type: G[A] b = None # type: G[B] c = None # type: G[C] -b = a # E: Incompatible types in assignment (expression has type G[A], variable has type G[B]) -b = c # E: Incompatible types in assignment (expression has type G[C], variable has type G[B]) +b = a # E: Incompatible types in assignment (expression has type "G[A]", variable has type "G[B]") +b = c # E: Incompatible types in assignment (expression has type "G[C]", variable has type "G[B]") [builtins fixtures/bool.pyi] [out] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 33106feca98d..f4a94281f8cd 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -79,8 +79,8 @@ class A(Generic[T]): pass class B: pass class C(B): pass [out] -main:4: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) -main:5: error: Incompatible types in assignment (expression has type A[C], variable has type A[B]) +main:4: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") +main:5: error: Incompatible types in assignment (expression has type "A[C]", variable has type "A[B]") [case testGenericTypeCompatibilityWithAny] from typing import Any, TypeVar, Generic @@ -115,8 +115,8 @@ class A(Generic[T]): class B: pass class C: pass [out] -main:7: error: Incompatible types in assignment (expression has type A[C], variable has type A[B]) -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) +main:7: error: Incompatible types in assignment (expression has type "A[C]", variable has type "A[B]") +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") [case testMultipleGenericTypeParametersWithMemberVars] from typing import TypeVar, Generic @@ -183,9 +183,9 @@ class A(Generic[S, T]): class B: pass class C(B):pass [out] -main:8: error: Incompatible types in assignment (expression has type A[B, C], variable has type A[B, B]) -main:9: error: Incompatible types in assignment (expression has type A[C, B], variable has type A[B, B]) -main:10: error: Incompatible types in assignment (expression has type A[B, B], variable has type A[B, C]) +main:8: error: Incompatible types in assignment (expression has type "A[B, C]", variable has type "A[B, B]") +main:9: error: Incompatible types in assignment (expression has type "A[C, B]", variable has type "A[B, B]") +main:10: error: Incompatible types in assignment (expression has type "A[B, B]", variable has type "A[B, C]") -- Simple generic type bodies @@ -208,7 +208,7 @@ x = None # type: B class B: pass [out] main:7: error: Argument 1 to "f" of "A" has incompatible type "B"; expected "T" -main:8: error: Incompatible types in assignment (expression has type A[T], variable has type A[B]) +main:8: error: Incompatible types in assignment (expression has type "A[T]", variable has type "A[B]") [case testGenericTypeBodyWithMultipleVariables] from typing import TypeVar, Generic @@ -229,8 +229,8 @@ class B: pass [out] main:8: error: Incompatible types in assignment (expression has type "T", variable has type "S") main:9: error: Incompatible types in assignment (expression has type "S", variable has type "T") -main:10: error: Incompatible types in assignment (expression has type A[S, T], variable has type A[S, B]) -main:11: error: Incompatible types in assignment (expression has type A[S, T], variable has type A[T, T]) +main:10: error: Incompatible types in assignment (expression has type "A[S, T]", variable has type "A[S, B]") +main:11: error: Incompatible types in assignment (expression has type "A[S, T]", variable has type "A[T, T]") [case testCompatibilityOfNoneWithTypeVar] from typing import TypeVar, Generic @@ -284,9 +284,9 @@ class B: pass class C: pass [out] main:8: error: Incompatible types in assignment (expression has type "C", variable has type "B") -main:9: error: Unsupported operand types for + (A[B, C] and "C") +main:9: error: Unsupported operand types for + ("A[B, C]" and "C") main:10: error: Incompatible types in assignment (expression has type "B", variable has type "C") -main:11: error: Invalid index type "B" for A[B, C]; expected type "C" +main:11: error: Invalid index type "B" for "A[B, C]"; expected type "C" [case testOperatorAssignmentWithIndexLvalue1] from typing import TypeVar, Generic @@ -309,7 +309,7 @@ class C: def __add__(self, o: 'C') -> 'C': pass [out] main:7: error: Unsupported operand types for + ("C" and "B") -main:8: error: Invalid index type "C" for A[C]; expected type "B" +main:8: error: Invalid index type "C" for "A[C]"; expected type "B" [case testOperatorAssignmentWithIndexLvalue2] from typing import TypeVar, Generic @@ -330,9 +330,9 @@ class B: pass class C: def __add__(self, o: 'C') -> 'C': pass [out] -main:7: error: Invalid index type "B" for A[C]; expected type "C" -main:8: error: Invalid index type "C" for A[C]; expected type "B" -main:9: error: Invalid index type "B" for A[C]; expected type "C" +main:7: error: Invalid index type "B" for "A[C]"; expected type "C" +main:8: error: Invalid index type "C" for "A[C]"; expected type "B" +main:9: error: Invalid index type "B" for "A[C]"; expected type "C" -- Nested generic types @@ -364,8 +364,8 @@ class B: class C: pass [out] -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[C]) -main:9: error: Incompatible types in assignment (expression has type A[A[B]], variable has type A[A[C]]) +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") +main:9: error: Incompatible types in assignment (expression has type "A[A[B]]", variable has type "A[A[C]]") -- Generic functions @@ -384,7 +384,7 @@ def f(s: S, t: T) -> p[T, A]: s = t # E: Incompatible types in assignment (expression has type "T", variable has type "S") p_s_a = None # type: p[S, A] if s: - return p_s_a # E: Incompatible return value type (got p[S, A], expected p[T, A]) + return p_s_a # E: Incompatible return value type (got "p[S, A]", expected "p[T, A]") b = t # type: T c = s # type: S p_t_a = None # type: p[T, A] @@ -402,10 +402,10 @@ class A(Generic[T]): s = t # E: Incompatible types in assignment (expression has type "T", variable has type "S") p_s_s = None # type: p[S, S] if s: - return p_s_s # E: Incompatible return value type (got p[S, S], expected p[S, T]) + return p_s_s # E: Incompatible return value type (got "p[S, S]", expected "p[S, T]") p_t_t = None # type: p[T, T] if t: - return p_t_t # E: Incompatible return value type (got p[T, T], expected p[S, T]) + return p_t_t # E: Incompatible return value type (got "p[T, T]", expected "p[S, T]") t = t s = s p_s_t = None # type: p[S, T] @@ -448,7 +448,7 @@ A[int, str, int]() # E: Type application has too many types (2 expected) a = None # type: A class A: pass a[A]() # E: Value of type "A" is not indexable -A[A]() # E: The type Type[A] is not generic and not indexable +A[A]() # E: The type "Type[A]" is not generic and not indexable [out] [case testTypeApplicationArgTypes] @@ -504,7 +504,7 @@ Alias[int]("a") # E: Argument 1 to "Node" has incompatible type "str"; expected [out] [case testTypeApplicationCrash] -type[int] # this was crashing, see #2302 (comment) # E: The type Type[type] is not generic and not indexable +type[int] # this was crashing, see #2302 (comment) # E: The type "Type[type]" is not generic and not indexable [out] @@ -564,7 +564,7 @@ def func(x: IntNode[T]) -> IntNode[T]: return x reveal_type(func) # E: Revealed type is 'def [T] (x: __main__.Node[builtins.int, T`-1]) -> __main__.Node[builtins.int, T`-1]' -func(1) # E: Argument 1 to "func" has incompatible type "int"; expected Node[int, ] +func(1) # E: Argument 1 to "func" has incompatible type "int"; expected "Node[int, ]" func(Node('x', 1)) # E: Argument 1 to "Node" has incompatible type "str"; expected "int" reveal_type(func(Node(1, 'x'))) # E: Revealed type is '__main__.Node[builtins.int, builtins.str*]' @@ -692,7 +692,7 @@ l.meth().append(1) reveal_type(l.meth()) # E: Revealed type is 'builtins.list*[builtins.int]' l.meth().append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "int" -ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type List[str]) +ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "List[str]") [builtins fixtures/list.pyi] @@ -714,7 +714,7 @@ def f_bad(x: T) -> D[T]: return D(1) # Error, see out L[int]().append(Node((1, 1))) -L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected Node[Tuple[int, int]] +L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "Node[Tuple[int, int]]" x = D((1, 1)) # type: D[int] y = D(5) # type: D[int] # E: Argument 1 to "D" has incompatible type "int"; expected "Tuple[int, int]" @@ -778,7 +778,7 @@ if not isinstance(s, str): z = None # type: TNode # Same as TNode[Any] z.x -z.foo() # E: Item Node[int] of "Union[Any, Node[int]]" has no attribute "foo" +z.foo() # E: Item "Node[int]" of "Union[Any, Node[int]]" has no attribute "foo" [builtins fixtures/isinstance.pyi] @@ -847,7 +847,7 @@ def fun2(v: Vec[T], scale: T) -> Vec[T]: return v reveal_type(fun1([(1, 1)])) # E: Revealed type is 'builtins.int*' -fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected List[Tuple[int, int]] +fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected "List[Tuple[int, int]]" fun1([(1, 'x')]) # E: Cannot infer type argument 1 of "fun1" reveal_type(fun2([(1, 1)], 1)) # E: Revealed type is 'builtins.list[Tuple[builtins.int*, builtins.int*]]' @@ -868,7 +868,7 @@ n.y = 'x' # E: Incompatible types in assignment (expression has type "str", vari def f(x: Node[T, T]) -> TupledNode[T]: return Node(x.x, (x.x, x.x)) -f(1) # E: Argument 1 to "f" has incompatible type "int"; expected Node[, ] +f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Node[, ]" f(Node(1, 'x')) # E: Cannot infer type argument 1 of "f" reveal_type(Node('x', 'x')) # E: Revealed type is 'a.Node[builtins.str*, builtins.str*]' @@ -1221,7 +1221,7 @@ Z = TypeVar('Z') class OO: pass a = None # type: A[object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object] -f(a) # E: Argument 1 to "f" has incompatible type A[...]; expected "OO" +f(a) # E: Argument 1 to "f" has incompatible type "A[...]"; expected "OO" def f(a: OO) -> None: pass @@ -1232,7 +1232,7 @@ from typing import TypeVar, Generic S = TypeVar('S') T = TypeVar('T') a = None # type: A[object, B] -f(a) # E: Argument 1 to "f" has incompatible type A[object, B]; expected "B" +f(a) # E: Argument 1 to "f" has incompatible type "A[object, B]"; expected "B" def f(a: 'B') -> None: pass class A(Generic[S, T]): pass @@ -1243,7 +1243,7 @@ from typing import Callable, TypeVar, Generic S = TypeVar('S') T = TypeVar('T') a = None # type: A[object, Callable[[], None]] -f(a) # E: Argument 1 to "f" has incompatible type A[object, Callable[[], None]]; expected "B" +f(a) # E: Argument 1 to "f" has incompatible type "A[object, Callable[[], None]]"; expected "B" def f(a: 'B') -> None: pass class A(Generic[S, T]): pass @@ -1504,7 +1504,7 @@ T = TypeVar('T') class C(Generic[T]): def __init__(self) -> None: pass x = C # type: Callable[[], C[int]] -y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type Type[C[Any]], variable has type Callable[[], int]) +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type Callable[[], int]) -- Special cases diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 3c81bd01d13a..5f2fd773a0c1 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -46,7 +46,7 @@ import b # type: ignore reveal_type(a.foo) # E: Revealed type is 'Any' reveal_type(b.foo) # E: Revealed type is 'builtins.int' a.bar() -b.bar() # E: Module has no attribute "bar" +b.bar() # E: "Module" has no attribute "bar" [file b.py] foo = 3 @@ -76,7 +76,7 @@ class B(A): import m m.x = object # type: ignore m.f() # type: ignore -m.y # E: Module has no attribute "y" +m.y # E: "Module" has no attribute "y" [file m.py] [builtins fixtures/module.pyi] @@ -194,7 +194,7 @@ foo(Child()) def bar(x: Base[str, str]) -> None: pass bar(Child()) [out] -main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected Base[str, str] +main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected "Base[str, str]" [case testTypeIgnoreLineNumberWithinFile] import m diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 23fafc24edf5..78da587098ec 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -325,7 +325,7 @@ const = 3 [stale mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod4" +tmp/mod1.py:3: error: "Module" has no attribute "mod4" [case testIncrementalLongBrokenCascade] import mod1 @@ -360,7 +360,7 @@ const = 3 [stale mod6] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod7" +tmp/mod1.py:3: error: "Module" has no attribute "mod7" [case testIncrementalNestedBrokenCascade] import mod1 @@ -386,7 +386,7 @@ const = 3 [stale mod2.mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: Module has no attribute "mod4" +tmp/mod1.py:3: error: "Module" has no attribute "mod4" [case testIncrementalNestedBrokenCascadeWithType1] import mod1, mod2.mod3.mod5 diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 9896c1118a5a..4a8e5b1b8dc5 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -13,7 +13,7 @@ b = None # type: B ao = f() ab = f() -b = f() # E: Incompatible types in assignment (expression has type A[], variable has type "B") +b = f() # E: Incompatible types in assignment (expression has type "A[]", variable has type "B") def f() -> 'A[T]': pass @@ -29,7 +29,7 @@ b = None # type: B ao = A() ab = A() -b = A() # E: Incompatible types in assignment (expression has type A[], variable has type "B") +b = A() # E: Incompatible types in assignment (expression has type "A[]", variable has type "B") class A(Generic[T]): pass class B: pass @@ -74,10 +74,10 @@ def g() -> None: b = None # type: B x = f(o) - ab = x # E: Incompatible types in assignment (expression has type A[object], variable has type A[B]) + ab = x # E: Incompatible types in assignment (expression has type "A[object]", variable has type "A[B]") ao = x y = f(b) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = y def f(a: T) -> 'A[T]': pass @@ -104,8 +104,8 @@ def g() -> None: ab = None # type: A[B] b = None # type: B x, y = f(b), f(b) - ao = x # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = x # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = x ab = y @@ -122,8 +122,8 @@ def h() -> None: ab = None # type: A[B] b = None # type: B x, y = g(f(b)) - ao = x # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) - ao = y # E: Incompatible types in assignment (expression has type A[B], variable has type A[object]) + ao = x # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") + ao = y # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") ab = x ab = y @@ -161,8 +161,8 @@ class A(Generic[T]): pass class B: pass [builtins fixtures/tuple.pyi] [out] -main:8: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:9: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) +main:8: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:9: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") [case testInferenceWithTypeVariableTwiceInReturnTypeAndMultipleVariables] from typing import TypeVar, Tuple, Generic @@ -190,10 +190,10 @@ class A(Generic[T]): pass class B: pass [builtins fixtures/tuple.pyi] [out] -main:9: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:10: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:11: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) -main:12: error: Incompatible types in assignment (expression has type A[B], variable has type A[object]) +main:9: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:10: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:11: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") +main:12: error: Incompatible types in assignment (expression has type "A[B]", variable has type "A[object]") -- Multiple tvar instances in arguments @@ -309,7 +309,7 @@ ab = None # type: A[B] ac = None # type: A[C] ab.g(f(o)) # E: Argument 1 to "f" has incompatible type "object"; expected "B" -ac = f(b).g(f(c)) # E: Incompatible types in assignment (expression has type A[B], variable has type A[C]) +ac = f(b).g(f(c)) # E: Incompatible types in assignment (expression has type "A[B]", variable has type "A[C]") ac = f(c).g(f(b)) # E: Argument 1 to "f" has incompatible type "B"; expected "C" ab = f(b).g(f(c)) @@ -334,7 +334,7 @@ aa = None # type: List[A] ao = None # type: List[object] a = None # type: A -a = [] # E: Incompatible types in assignment (expression has type List[], variable has type "A") +a = [] # E: Incompatible types in assignment (expression has type "List[]", variable has type "A") aa = [] ao = [] @@ -401,7 +401,7 @@ ab = None # type: List[B] b = None # type: B o = None # type: object -aao = [[o], ab] # E: List item 1 has incompatible type List[B] +aao = [[o], ab] # E: List item 1 has incompatible type "List[B]" aab = [[], [o]] # E: List item 0 has incompatible type "object" aao = [[None], [b], [], [o]] @@ -462,7 +462,7 @@ d = {A() : a_c, [case testInitializationWithInferredGenericType] from typing import TypeVar, Generic T = TypeVar('T') -c = f(A()) # type: C[A] # E: Argument 1 to "f" has incompatible type "A"; expected C[A] +c = f(A()) # type: C[A] # E: Argument 1 to "f" has incompatible type "A"; expected "C[A]" def f(x: T) -> T: pass class C(Generic[T]): pass @@ -503,7 +503,7 @@ from abc import abstractmethod, ABCMeta t = TypeVar('t') x = A() # type: I[int] a_object = A() # type: A[object] -y = a_object # type: I[int] # E: Incompatible types in assignment (expression has type A[object], variable has type I[int]) +y = a_object # type: I[int] # E: Incompatible types in assignment (expression has type "A[object]", variable has type "I[int]") class I(Generic[t]): @abstractmethod @@ -663,7 +663,7 @@ class B: pass m = map(g, [A()]) b = m # type: List[B] -a = m # type: List[A] # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = m # type: List[A] # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] @@ -677,8 +677,8 @@ a, b, c = None, None, None # type: (List[A], List[B], List[C]) a = a or [] a = [] or a b = b or [C()] -a = a or b # E: Incompatible types in assignment (expression has type "Union[List[A], List[B]]", variable has type List[A]) -b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type List[B]) +a = a or b # E: Incompatible types in assignment (expression has type "Union[List[A], List[B]]", variable has type "List[A]") +b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type "List[B]") class A: pass class B: pass @@ -732,7 +732,7 @@ from typing import List i = None # type: List[int] s = None # type: List[str] i = i = [] -i = s = [] # E: Incompatible types in assignment (expression has type List[str], variable has type List[int]) +i = s = [] # E: Incompatible types in assignment (expression has type "List[str]", variable has type "List[int]") [builtins fixtures/list.pyi] [case testContextForAttributeDeclaredInInit] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 42cd312c0531..76931ad3b254 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -69,7 +69,7 @@ class B: pass import typing def f() -> None: a = g() - None(a) # E: None not callable + None(a) # E: "None" not callable a.x() def g(): pass @@ -81,7 +81,7 @@ g = None # type: Any def f(a: Any) -> None: b = g - None(b) # E: None not callable + None(b) # E: "None" not callable a.x() [out] @@ -126,7 +126,7 @@ a_s = None # type: A[str] def f() -> None: a_int = A() # type: A[int] a = a_int - a = a_s # E: Incompatible types in assignment (expression has type A[str], variable has type A[int]) + a = a_s # E: Incompatible types in assignment (expression has type "A[str]", variable has type "A[int]") a = a_i [builtins fixtures/tuple.pyi] [out] @@ -480,11 +480,11 @@ ao = None # type: A[object] ab = None # type: A[B] ac = None # type: A[C] -ab = f(ao) # E: Argument 1 to "f" has incompatible type A[object]; expected A[B] -ao = f(ab) # E: Argument 1 to "f" has incompatible type A[B]; expected A[object] -ab = f(ac) # E: Argument 1 to "f" has incompatible type A[C]; expected A[B] -ab = g(ao) # E: Argument 1 to "g" has incompatible type A[object]; expected A[B] -ao = g(ab) # E: Argument 1 to "g" has incompatible type A[B]; expected A[object] +ab = f(ao) # E: Argument 1 to "f" has incompatible type "A[object]"; expected "A[B]" +ao = f(ab) # E: Argument 1 to "f" has incompatible type "A[B]"; expected "A[object]" +ab = f(ac) # E: Argument 1 to "f" has incompatible type "A[C]"; expected "A[B]" +ab = g(ao) # E: Argument 1 to "g" has incompatible type "A[object]"; expected "A[B]" +ao = g(ab) # E: Argument 1 to "g" has incompatible type "A[B]"; expected "A[object]" ab = f(ab) ac = f(ac) @@ -648,7 +648,7 @@ def mymap(f: Callable[[t], s], a: List[t]) -> List[s]: pass l = mymap(f, [b]) l = [A()] lb = [b] -l = lb # E: Incompatible types in assignment (expression has type List[bool], variable has type List[A]) +l = lb # E: Incompatible types in assignment (expression has type "List[bool]", variable has type "List[A]") [builtins fixtures/for.pyi] [case testGenericFunctionWithTypeTypeAsCallable] @@ -676,7 +676,7 @@ f(1, 1)() # E: "int" not callable def g(x: Union[T, List[T]]) -> List[T]: pass def h(x: List[str]) -> None: pass -g('a')() # E: List[str] not callable +g('a')() # E: "List[str]" not callable # The next line is a case where there are multiple ways to satisfy a constraint # involving a Union. Either T = List[str] or T = str would turn out to be valid, @@ -684,7 +684,7 @@ g('a')() # E: List[str] not callable # to backtrack later) and defaults to T = . The result is an # awkward error message. Either a better error message, or simply accepting the # call, would be preferable here. -g(['a']) # E: Argument 1 to "g" has incompatible type List[str]; expected List[] +g(['a']) # E: Argument 1 to "g" has incompatible type "List[str]"; expected "List[]" h(g(['a'])) @@ -693,7 +693,7 @@ a = [1] b = ['b'] i(a, a, b) i(b, a, b) -i(a, b, b) # E: Argument 1 to "i" has incompatible type List[int]; expected List[str] +i(a, b, b) # E: Argument 1 to "i" has incompatible type "List[int]"; expected "List[str]" [builtins fixtures/list.pyi] [case testCallableListJoinInference] @@ -778,7 +778,7 @@ from typing import TypeVar, Union, List T = TypeVar('T') def f() -> List[T]: pass d1 = f() # type: Union[List[int], str] -d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type List[], variable has type "Union[int, str]") +d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type "List[]", variable has type "Union[int, str]") def g(x: T) -> List[T]: pass d3 = g(1) # type: Union[List[int], List[str]] [builtins fixtures/list.pyi] @@ -840,7 +840,7 @@ def d_aa() -> Dict[A, A]: return {} a, b = None, None # type: (A, B) d = {a:b} d = d_ab() -d = d_aa() # E: Incompatible types in assignment (expression has type Dict[A, A], variable has type Dict[A, B]) +d = d_aa() # E: Incompatible types in assignment (expression has type "Dict[A, A]", variable has type "Dict[A, B]") [builtins fixtures/dict.pyi] [case testSetLiteral] @@ -851,7 +851,7 @@ def s_s() -> Set[str]: return set() s = {a} s = {x} s = s_i() -s = s_s() # E: Incompatible types in assignment (expression has type Set[str], variable has type Set[int]) +s = s_s() # E: Incompatible types in assignment (expression has type "Set[str]", variable has type "Set[int]") [builtins fixtures/set.pyi] [case testSetWithStarExpr] @@ -1154,7 +1154,7 @@ a = None # type: List[A] o = None # type: List[object] a2 = a or [] a = a2 -a2 = o # E: Incompatible types in assignment (expression has type List[object], variable has type List[A]) +a2 = o # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[A]") class A: pass [builtins fixtures/list.pyi] @@ -1194,7 +1194,7 @@ x2 = [B(), A()] x3 = [B(), B()] a = x1 a = x2 -a = x3 # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = x3 # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] [case testListWithDucktypeCompatibilityAndTransitivity] @@ -1210,7 +1210,7 @@ x2 = [C(), A()] x3 = [B(), C()] a = x1 a = x2 -a = x3 # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +a = x3 # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") [builtins fixtures/list.pyi] @@ -1256,8 +1256,8 @@ a() a, b = [], [] a.append(1) b.append('') -a() # E: List[int] not callable -b() # E: List[str] not callable +a() # E: "List[int]" not callable +b() # E: "List[str]" not callable [builtins fixtures/list.pyi] [out] @@ -1371,14 +1371,14 @@ a.add('') # E: Argument 1 to "add" of "set" has incompatible type "str"; expect [case testInferDictInitializedToEmpty] a = {} a[1] = '' -a() # E: Dict[int, str] not callable +a() # E: "Dict[int, str]" not callable [builtins fixtures/dict.pyi] [out] [case testInferDictInitializedToEmptyUsingUpdate] a = {} a.update({'': 42}) -a() # E: Dict[str, int] not callable +a() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [out] @@ -1447,7 +1447,7 @@ def f() -> None: import typing def f() -> None: a = None - a.x() # E: None has no attribute "x" + a.x() # E: "None" has no attribute "x" [out] [case testGvarPartiallyInitializedToNone] @@ -1504,7 +1504,7 @@ x = None def f() -> None: x = None x = 1 -x() # E: None not callable +x() # E: "None" not callable [case testAttributePartiallyInitializedToNone] class A: @@ -1523,8 +1523,8 @@ class A: self.x = 1 self.x() [out] -main:6: error: Incompatible types in assignment (expression has type "int", variable has type None) -main:7: error: None not callable +main:6: error: Incompatible types in assignment (expression has type "int", variable has type "None") +main:7: error: "None" not callable [case testGlobalInitializedToNoneSetFromFunction] a = None @@ -1553,7 +1553,7 @@ class A: pass [builtins fixtures/for.pyi] [out] -main:5: error: None has no attribute "__iter__" +main:5: error: "None" has no attribute "__iter__" [case testPartialTypeErrorSpecialCase2] # This used to crash. @@ -1574,7 +1574,7 @@ class A: pass [builtins fixtures/for.pyi] [out] -main:4: error: None has no attribute "__iter__" +main:4: error: "None" has no attribute "__iter__" -- Multipass @@ -1680,7 +1680,7 @@ def g(d: Dict[str, int]) -> None: pass def f() -> None: x = {} x[1] = y - g(x) # E: Argument 1 to "g" has incompatible type Dict[int, str]; expected Dict[str, int] + g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, str]"; expected "Dict[str, int]" x[1] = 1 # E: Incompatible types in assignment (expression has type "int", target has type "str") x[1] = '' y = '' @@ -1694,7 +1694,7 @@ def f() -> None: x = {} y x[1] = 1 - g(x) # E: Argument 1 to "g" has incompatible type Dict[int, int]; expected Dict[str, int] + g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, int]"; expected "Dict[str, int]" y = '' [builtins fixtures/dict.pyi] [out] @@ -1713,7 +1713,7 @@ def f() -> None: y = o x = [] x.append(y) - x() # E: List[int] not callable + x() # E: "List[int]" not callable o = 1 [builtins fixtures/list.pyi] [out] @@ -1723,7 +1723,7 @@ def f() -> None: y = o x = {} x[''] = y - x() # E: Dict[str, int] not callable + x() # E: "Dict[str, int]" not callable o = 1 [builtins fixtures/dict.pyi] [out] @@ -1825,20 +1825,20 @@ a2.foo2() [case testUnificationEmptyListLeft] def f(): pass a = [] if f() else [0] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRight] def f(): pass a = [0] if f() else [] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListLeftInContext] from typing import List def f(): pass a = [] if f() else [0] # type: List[int] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRightInContext] @@ -1846,37 +1846,37 @@ a() # E: List[int] not callable from typing import List def f(): pass a = [0] if f() else [] # type: List[int] -a() # E: List[int] not callable +a() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptySetLeft] def f(): pass a = set() if f() else {0} -a() # E: Set[int] not callable +a() # E: "Set[int]" not callable [builtins fixtures/set.pyi] [case testUnificationEmptyDictLeft] def f(): pass a = {} if f() else {0: 0} -a() # E: Dict[int, int] not callable +a() # E: "Dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationEmptyDictRight] def f(): pass a = {0: 0} if f() else {} -a() # E: Dict[int, int] not callable +a() # E: "Dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListLeft] def f(): pass a = {0: []} if f() else {0: [0]} -a() # E: Dict[int, List[int]] not callable +a() # E: "Dict[int, List[int]]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListRight] def f(): pass a = {0: [0]} if f() else {0: []} -a() # E: Dict[int, List[int]] not callable +a() # E: "Dict[int, List[int]]" not callable [builtins fixtures/dict.pyi] [case testMisguidedSetItem] diff --git a/test-data/unit/check-isinstance.test b/test-data/unit/check-isinstance.test index 825a5557fc63..d9a27649e4af 100644 --- a/test-data/unit/check-isinstance.test +++ b/test-data/unit/check-isinstance.test @@ -679,7 +679,7 @@ while bool(): x + 'a' break x + [1] - x + 'a' # E: Unsupported operand types for + (List[int] and "str") + x + 'a' # E: Unsupported operand types for + ("List[int]" and "str") x + [1] # E: Unsupported operand types for + (likely involving Union) [builtins fixtures/isinstancelist.pyi] @@ -1486,7 +1486,7 @@ def test_issubclass(cls: Type[Goblin]) -> None: else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1511,7 +1511,7 @@ def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, Goblin): reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1525,8 +1525,8 @@ def test_issubclass(cls: Type[Mob]) -> None: g.job = 'Warrior' # E: Cannot assign to class variable "job" via instance else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' - cls.job # E: Type[Mob] has no attribute "job" - cls.level # E: Type[Mob] has no attribute "level" + cls.job # E: "Type[Mob]" has no attribute "job" + cls.level # E: "Type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" @@ -1570,7 +1570,7 @@ def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, (Goblin, GoblinAmbusher)): reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' cls.level - cls.job # E: Type[Goblin] has no attribute "job" + cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1584,8 +1584,8 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' - cls.job # E: Type[Mob] has no attribute "job" - cls.level # E: Type[Mob] has no attribute "level" + cls.job # E: "Type[Mob]" has no attribute "job" + cls.level # E: "Type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index de229c76e631..e8182b34ae8f 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -4,7 +4,7 @@ [case testTypeErrorInKeywordArgument] import typing def f(o: object) -> None: pass -f(o=None()) # E: None not callable +f(o=None()) # E: "None" not callable [case testSimpleKeywordArgument] import typing @@ -89,8 +89,8 @@ class A: pass [case testKeywordArgumentsWithDynamicallyTypedCallable] from typing import Any f = None # type: Any -f(x=f(), z=None()) # E: None not callable -f(f, zz=None()) # E: None not callable +f(x=f(), z=None()) # E: "None" not callable +f(f, zz=None()) # E: "None" not callable f(x=None) [case testKeywordArgumentWithFunctionObject] @@ -216,8 +216,8 @@ class A: pass from typing import Dict, Any def f( **kwargs: 'A') -> None: d1 = kwargs # type: Dict[str, A] - d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type Dict[str, A], variable has type Dict[A, Any]) - d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type Dict[str, A], variable has type Dict[Any, str]) + d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[A, Any]") + d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[Any, str]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -227,7 +227,7 @@ from typing import Dict, Any def f(**kwargs) -> None: d1 = kwargs # type: Dict[str, A] d2 = kwargs # type: Dict[str, str] - d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type Dict[str, Any], variable has type Dict[A, Any]) + d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[A, Any]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -252,8 +252,8 @@ d = None # type: Dict[str, A] f(**d) f(x=A(), **d) d2 = None # type: Dict[str, B] -f(**d2) # E: Argument 1 to "f" has incompatible type **Dict[str, B]; expected "A" -f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type **Dict[str, B]; expected "A" +f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, B]"; expected "A" +f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type **"Dict[str, B]"; expected "A" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -295,7 +295,7 @@ def f(a: 'A', b: 'B') -> None: pass d = None # type: Dict[str, Any] f(**d) d2 = None # type: Dict[str, A] -f(**d2) # E: Argument 1 to "f" has incompatible type **Dict[str, A]; expected "B" +f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, A]"; expected "B" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -344,12 +344,12 @@ s = ('',) f(*s) # E: Argument 1 to "f" has incompatible type *"Tuple[str]"; expected "int" a = {'': 0} -f(a) # E: Argument 1 to "f" has incompatible type Dict[str, int]; expected "int" +f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, int]"; expected "int" f(**a) # okay b = {'': ''} -f(b) # E: Argument 1 to "f" has incompatible type Dict[str, str]; expected "int" -f(**b) # E: Argument 1 to "f" has incompatible type **Dict[str, str]; expected "int" +f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, str]"; expected "int" +f(**b) # E: Argument 1 to "f" has incompatible type **"Dict[str, str]"; expected "int" c = {0: 0} f(**c) # E: Keywords must be strings diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 66050601d26f..10c6a22680d6 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -155,16 +155,16 @@ import m import typing class A: pass -m() # E: Module not callable -a = m # type: A # E: Incompatible types in assignment (expression has type Module, variable has type "A") -m + None # E: Unsupported left operand type for + (Module) +m() # E: "Module" not callable +a = m # type: A # E: Incompatible types in assignment (expression has type "Module", variable has type "A") +m + None # E: Unsupported left operand type for + ("Module") [file m.py] [builtins fixtures/module.pyi] [case testNameDefinedInDifferentModule] import m, n import typing -m.x # E: Module has no attribute "x" +m.x # E: "Module" has no attribute "x" [file m.py] y = object() [file n.py] @@ -201,7 +201,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModule2] import m, nonexistent @@ -213,7 +213,7 @@ x = 1 [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testTypeCheckWithUnknownModule3] @@ -226,7 +226,7 @@ x = 1 [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testTypeCheckWithUnknownModule4] @@ -236,7 +236,7 @@ None + '' main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) main:1: error: Cannot find module named 'another' -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModule5] import nonexistent as x @@ -244,7 +244,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModuleUsingFromImport] from nonexistent import x @@ -252,7 +252,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testTypeCheckWithUnknownModuleUsingImportStar] from nonexistent import * @@ -260,7 +260,7 @@ None + '' [out] main:1: error: Cannot find module named 'nonexistent' main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") [case testAccessingUnknownModule] import xyz @@ -330,7 +330,7 @@ import nonexistent [out] tmp/x.py:1: error: Cannot find module named 'nonexistent' tmp/x.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:3: error: Module has no attribute "z" +main:3: error: "Module" has no attribute "z" [case testUnknownModuleImportedWithinFunction] def f(): @@ -411,14 +411,14 @@ import typing __all__ = [1, 2, 3] [builtins fixtures/module_all.pyi] [out] -main:2: error: Type of __all__ must be Sequence[str], not List[int] +main:2: error: Type of __all__ must be "Sequence[str]", not "List[int]" [case testAllMustBeSequenceStr_python2] import typing __all__ = [1, 2, 3] [builtins_py2 fixtures/module_all_python2.pyi] [out] -main:2: error: Type of __all__ must be Sequence[unicode], not List[int] +main:2: error: Type of __all__ must be "Sequence[unicode]", not "List[int]" [case testAllUnicodeSequenceOK_python2] import typing @@ -648,7 +648,7 @@ def f(x: str) -> None: pass if object(): import m else: - m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Module) + m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Module") [file m.py] [builtins fixtures/module.pyi] [out] @@ -673,7 +673,7 @@ def f(x: str) -> None: pass None + 1 [file m/a.py] [out] -tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) +tmp/m/__init__.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule2] # cmd: mypy -m m.a @@ -681,7 +681,7 @@ tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) [file m/a.py] None + 1 [out] -tmp/m/a.py:1: error: Unsupported left operand type for + (None) +tmp/m/a.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule3] # cmd: mypy -m m @@ -689,7 +689,7 @@ tmp/m/a.py:1: error: Unsupported left operand type for + (None) None + 1 [file m/a.py] [out] -tmp/m/__init__.py:1: error: Unsupported left operand type for + (None) +tmp/m/__init__.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModule4] # cmd: mypy -m m @@ -704,7 +704,7 @@ None + '' # Not analyzed. [file m.py] None + 1 [out] -tmp/m.py:1: error: Unsupported left operand type for + (None) +tmp/m.py:1: error: Unsupported left operand type for + ("None") [case testTypeCheckNamedModuleWithImportCycle] # cmd: mypy -m m.a @@ -752,7 +752,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents] from a import b reveal_type(b.value) # E: Revealed type is 'builtins.str' -b.c.value # E: Module has no attribute "c" +b.c.value # E: "Module" has no attribute "c" a.value # E: Name 'a' is not defined [file a/__init__.py] @@ -853,7 +853,7 @@ bar = parent.unrelated.ShouldNotLoad() [builtins fixtures/module.pyi] [out] tmp/parent/child.py:8: error: Revealed type is 'parent.common.SomeClass' -tmp/parent/child.py:9: error: Module has no attribute "unrelated" +tmp/parent/child.py:9: error: "Module" has no attribute "unrelated" [case testSubmoduleMixingImportFromAndImport2] import parent.child @@ -915,7 +915,7 @@ class z: pass [out] main:2: error: Incompatible import of "x" (imported name has type "str", local name has type "int") main:2: error: Incompatible import of "y" (imported name has type Callable[[], str], local name has type Callable[[], int]) -main:2: error: Incompatible import of "z" (imported name has type Type[b.z], local name has type Type[a.z]) +main:2: error: Incompatible import of "z" (imported name has type "Type[b.z]", local name has type "Type[a.z]") -- Misc diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 81aa3f6957e6..9f803bbcc558 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -221,7 +221,7 @@ a = (1,) # E: Incompatible types in assignment (expression has type "Tuple[int] [case testNamedTupleMissingClassAttribute] import collections MyNamedTuple = collections.namedtuple('MyNamedTuple', ['spam', 'eggs']) -MyNamedTuple.x # E: Type[MyNamedTuple] has no attribute "x" +MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" [case testNamedTupleEmptyItems] @@ -286,7 +286,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) reveal_type(X._make([5, 'a'])) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' -X._make('a b') # E: Argument 1 to X._make has incompatible type "str"; expected Iterable[Any] +X._make('a b') # E: Argument 1 to X._make has incompatible type "str"; expected "Iterable[Any]" -- # FIX: not a proper class method -- x = None # type: X @@ -420,7 +420,7 @@ class C: A = NamedTuple('A', [('x', int)]) def g(self): A = NamedTuple('A', [('y', int)]) -C.A # E: Type[C] has no attribute "A" +C.A # E: "Type[C]" has no attribute "A" [case testNamedTupleInFunction] from typing import NamedTuple diff --git a/test-data/unit/check-newsyntax.test b/test-data/unit/check-newsyntax.test index 9f3f87853e63..f17b324cbca2 100644 --- a/test-data/unit/check-newsyntax.test +++ b/test-data/unit/check-newsyntax.test @@ -29,7 +29,7 @@ from typing import Dict, Any d: Dict[int, str] = {} d[42] = 'ab' d[42] = 42 # E: Incompatible types in assignment (expression has type "int", target has type "str") -d['ab'] = 'ab' # E: Invalid index type "str" for Dict[int, str]; expected type "int" +d['ab'] = 'ab' # E: Invalid index type "str" for "Dict[int, str]"; expected type "int" [builtins fixtures/dict.pyi] [out] @@ -61,29 +61,29 @@ TstInstance().a = 'ab' [case testNewSyntaxWithClassVars] # flags: --strict-optional --python-version 3.6 class CCC: - a: str = None # E: Incompatible types in assignment (expression has type None, variable has type "str") + a: str = None # E: Incompatible types in assignment (expression has type "None", variable has type "str") [out] [case testNewSyntaxWithStrictOptional] # flags: --strict-optional --python-version 3.6 strict: int -strict = None # E: Incompatible types in assignment (expression has type None, variable has type "int") -strict2: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") +strict = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") +strict2: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxWithStrictOptionalFunctions] # flags: --strict-optional --python-version 3.6 def f() -> None: x: int - x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxWithStrictOptionalClasses] # flags: --strict-optional --python-version 3.6 class C: def meth(self) -> None: - x: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") - self.x: int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + x: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") + self.x: int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testNewSyntaxSpecialAssign] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 3cde2f99a1fb..3b3f688f1801 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -2,11 +2,11 @@ [case testImplicitNoneType] x = None -x() # E: None not callable +x() # E: "None" not callable [case testExplicitNoneType] x = None # type: None -x() # E: None not callable +x() # E: "None" not callable [case testNoneMemberOfOptional] from typing import Optional @@ -19,12 +19,12 @@ x = 0 # type: Optional[int] [case testNoneNotMemberOfType] x = None # type: int [out] -main:1: error: Incompatible types in assignment (expression has type None, variable has type "int") +main:1: error: Incompatible types in assignment (expression has type "None", variable has type "int") [case testTypeNotMemberOfNone] x = 0 # type: None [out] -main:1: error: Incompatible types in assignment (expression has type "int", variable has type None) +main:1: error: Incompatible types in assignment (expression has type "int", variable has type "None") [case testOptionalNotMemberOfType] from typing import Optional @@ -180,13 +180,13 @@ reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.None]' [case testInferOptionalListType] x = [None] -x.append(1) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected None +x.append(1) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "None" [builtins fixtures/list.pyi] [case testInferNonOptionalListType] x = [] x.append(1) -x() # E: List[int] not callable +x() # E: "List[int]" not callable [builtins fixtures/list.pyi] [case testInferOptionalDictKeyValueTypes] @@ -194,13 +194,13 @@ x = {None: None} x["bar"] = 1 [builtins fixtures/dict.pyi] [out] -main:2: error: Invalid index type "str" for Dict[None, None]; expected type None -main:2: error: Incompatible types in assignment (expression has type "int", target has type None) +main:2: error: Invalid index type "str" for "Dict[None, None]"; expected type "None" +main:2: error: Incompatible types in assignment (expression has type "int", target has type "None") [case testInferNonOptionalDictType] x = {} x["bar"] = 1 -x() # E: Dict[str, int] not callable +x() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testNoneClassVariable] @@ -215,7 +215,7 @@ from typing import Optional class C: x = None # type: int def __init__(self) -> None: - self.x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") + self.x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [out] [case testMultipleAssignmentNoneClassVariableInInit] @@ -223,8 +223,8 @@ from typing import Optional class C: x, y = None, None # type: int, str def __init__(self) -> None: - self.x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") - self.y = None # E: Incompatible types in assignment (expression has type None, variable has type "str") + self.x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") + self.y = None # E: Incompatible types in assignment (expression has type "None", variable has type "str") [out] [case testOverloadWithNone] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 69289fae18c1..4f359a3efefb 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -447,7 +447,7 @@ from foo import * from typing import overload t, a = None, None # type: (type, A) -a = A # E: Incompatible types in assignment (expression has type Type[A], variable has type "A") +a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") t = A class A: @@ -610,7 +610,7 @@ n = 1 m = 1 n = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") m = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -f(list_object) # E: Argument 1 to "f" has incompatible type List[object]; expected List[int] +f(list_object) # E: Argument 1 to "f" has incompatible type "List[object]"; expected "List[int]" [builtins fixtures/list.pyi] [case testOverlappingOverloadSignatures] @@ -901,7 +901,7 @@ def f(x: int, y: List[int] = None) -> int: pass def f(x: int, y: List[str] = None) -> int: pass f(y=[1], x=0)() # E: "int" not callable f(y=[''], x=0)() # E: "int" not callable -a = f(y=[['']], x=0) # E: List item 0 has incompatible type List[str] +a = f(y=[['']], x=0) # E: List item 0 has incompatible type "List[str]" a() # E: "int" not callable [builtins fixtures/list.pyi] @@ -1117,14 +1117,14 @@ def f(x: int, y: Tuple[str, ...]) -> None: pass @overload def f(x: int, y: str) -> None: pass f(1, ('2', '3')) -f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "Tuple[int, str]"; expected Tuple[str, ...] +f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "Tuple[int, str]"; expected "Tuple[str, ...]" f(1, ('2',)) f(1, '2') -f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "Tuple[int, int]"; expected Tuple[str, ...] +f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "Tuple[int, int]"; expected "Tuple[str, ...]" x = ('2', '3') # type: Tuple[str, ...] f(1, x) y = (2, 3) # type: Tuple[int, ...] -f(1, y) # E: Argument 2 to "f" has incompatible type Tuple[int, ...]; expected Tuple[str, ...] +f(1, y) # E: Argument 2 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[str, ...]" [builtins fixtures/tuple.pyi] [case testCallableSpecificOverload] diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index b3b899b21560..24022f4b15d8 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -34,7 +34,7 @@ class A: print >>A(), '' print >>None, '' print >>1, '' # E: "int" has no attribute "write" -print >>(None + ''), None # E: Unsupported left operand type for + (None) +print >>(None + ''), None # E: Unsupported left operand type for + ("None") [case testDivision] class A: @@ -291,7 +291,7 @@ class A(object): __metaclass__ = M y = 0 reveal_type(A.y) # E: Revealed type is 'builtins.int' -A.x # E: Type[A] has no attribute "x" +A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] from typing import Any, Type diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 8c1f85b1d743..a8071d68b1e6 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -377,7 +377,7 @@ import typing assert None + None # Fail assert None [out] -main:2: error: Unsupported left operand type for + (None) +main:2: error: Unsupported left operand type for + ("None") -- Exception handling @@ -599,9 +599,9 @@ main:7: error: Incompatible redefinition (redefinition with type Callable[[], st [case testExceptWithoutType] import typing try: - -None # E: Unsupported operand type for unary - (None) + -None # E: Unsupported operand type for unary - ("None") except: - ~None # E: Unsupported operand type for ~ (None) + ~None # E: Unsupported operand type for ~ ("None") [builtins fixtures/exception.pyi] [case testRaiseWithoutArgument] @@ -1189,7 +1189,7 @@ def g() -> Iterator[List[int]]: yield [2, 3, 4] def f() -> Iterator[List[int]]: yield from g() - yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type List[int]) + yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type "List[int]") [builtins fixtures/for.pyi] [out] @@ -1429,7 +1429,7 @@ y = 1 from typing import List bs, cs = None, None # type: List[A], List[B] *bs, b = bs -*bs, c = cs # E: Incompatible types in assignment (expression has type List[B], variable has type List[A]) +*bs, c = cs # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") *ns, c = cs nc = cs diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 08345706f0d9..ded930ae6d7e 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -91,7 +91,7 @@ from typing import Tuple t1 = None # type: Tuple[A, A] t2 = None # type: tuple -t1 = t2 # E: Incompatible types in assignment (expression has type Tuple[Any, ...], variable has type "Tuple[A, A]") +t1 = t2 # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "Tuple[A, A]") t2 = t1 class A: pass @@ -388,7 +388,7 @@ aa, bb, *cc = t # E: Need type annotation for variable from typing import List li, lo = None, None # type: List[int], List[object] a, b, *c = 1, 2 # type: int, int, List[int] -c = lo # E: Incompatible types in assignment (expression has type List[object], variable has type List[int]) +c = lo # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[int]") c = li [builtins fixtures/list.pyi] @@ -450,14 +450,14 @@ class A: pass [out] main:6: error: List item 0 has incompatible type "A" main:6: error: List item 1 has incompatible type "A" -main:9: error: Incompatible types in assignment (expression has type "A", variable has type List[A]) +main:9: error: Incompatible types in assignment (expression has type "A", variable has type "List[A]") [case testAssignmentToStarFromTupleInference] from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = A(), A() -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -469,7 +469,7 @@ from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = [A(), A()] -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -482,7 +482,7 @@ li = None # type: List[int] la = None # type: List[A] ta = None # type: Tuple[A, A, A] a, *l = ta -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -494,7 +494,7 @@ from typing import List li = None # type: List[int] la = None # type: List[A] a, *l = la -l = li # E: Incompatible types in assignment (expression has type List[int], variable has type List[A]) +l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") l = la class A: pass @@ -579,7 +579,7 @@ class LongTypeName: def __add__(self, x: 'LongTypeName') -> 'LongTypeName': pass [builtins fixtures/tuple.pyi] [out] -main:3: error: Unsupported operand types for + ("LongTypeName" and tuple(length 50)) +main:3: error: Unsupported operand types for + ("LongTypeName" and "tuple(length 50)") -- Tuple methods @@ -750,7 +750,7 @@ tb = () # type: Tuple[B, ...] fa(ta) fa(tb) fb(tb) -fb(ta) # E: Argument 1 to "fb" has incompatible type Tuple[A, ...]; expected Tuple[B, ...] +fb(ta) # E: Argument 1 to "fb" has incompatible type "Tuple[A, ...]"; expected "Tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingFixedAndVariableLengthTuples] @@ -766,8 +766,8 @@ fa(aa) fa(ab) fa(bb) fb(bb) -fb(ab) # E: Argument 1 to "fb" has incompatible type "Tuple[A, B]"; expected Tuple[B, ...] -fb(aa) # E: Argument 1 to "fb" has incompatible type "Tuple[A, A]"; expected Tuple[B, ...] +fb(ab) # E: Argument 1 to "fb" has incompatible type "Tuple[A, B]"; expected "Tuple[B, ...]" +fb(aa) # E: Argument 1 to "fb" has incompatible type "Tuple[A, A]"; expected "Tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingTupleIsContainer] @@ -913,7 +913,7 @@ def f(a: Tuple) -> None: pass f(()) f((1,)) f(('', '')) -f(0) # E: Argument 1 to "f" has incompatible type "int"; expected Tuple[Any, ...] +f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[Any, ...]" [builtins fixtures/tuple.pyi] [case testTupleSingleton] diff --git a/test-data/unit/check-type-checks.test b/test-data/unit/check-type-checks.test index c4905a75ef78..dc3265238794 100644 --- a/test-data/unit/check-type-checks.test +++ b/test-data/unit/check-type-checks.test @@ -107,7 +107,7 @@ def f(x: object) -> None: if isinstance(x, C): x.f(1) x.f('') - x.g() # E: C[Any] has no attribute "g" + x.g() # E: "C[Any]" has no attribute "g" x.g() # E: "object" has no attribute "g" [builtins fixtures/isinstance.pyi] [out] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 4714ec77f3dc..16010e5b9d1a 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -283,7 +283,7 @@ from mypy_extensions import TypedDict from typing import Mapping Point = TypedDict('Point', {'x': int, 'y': int}) def as_mapping(p: Point) -> Mapping[str, str]: - return p # E: Incompatible return value type (got "Point", expected Mapping[str, str]) + return p # E: Incompatible return value type (got "Point", expected "Mapping[str, str]") [builtins fixtures/dict.pyi] [case testTypedDictAcceptsIntForFloatDuckTypes] @@ -344,9 +344,9 @@ from mypy_extensions import TypedDict from typing import Dict, MutableMapping Point = TypedDict('Point', {'x': int, 'y': int}) def as_dict(p: Point) -> Dict[str, int]: - return p # E: Incompatible return value type (got "Point", expected Dict[str, int]) + return p # E: Incompatible return value type (got "Point", expected "Dict[str, int]") def as_mutable_mapping(p: Point) -> MutableMapping[str, int]: - return p # E: Incompatible return value type (got "Point", expected MutableMapping[str, int]) + return p # E: Incompatible return value type (got "Point", expected "MutableMapping[str, int]") [builtins fixtures/dict.pyi] [case testCanConvertTypedDictToAny] @@ -639,7 +639,7 @@ class C: A = TypedDict('A', {'x': int}) def g(self): A = TypedDict('A', {'y': int}) -C.A # E: Type[C] has no attribute "A" +C.A # E: "Type[C]" has no attribute "A" [builtins fixtures/dict.pyi] [case testTypedDictInFunction] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 36df2235a209..8dc6d32a55c1 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -270,7 +270,7 @@ y = C(S()) x = y y = x c_int = C(1) # type: C[int] -y = c_int # E: Incompatible types in assignment (expression has type C[int], variable has type C[str]) +y = c_int # E: Incompatible types in assignment (expression has type "C[int]", variable has type "C[str]") [case testGenericTypeBodyWithTypevarValues] from typing import TypeVar, Generic diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 75e6f88c0c35..bbd538bc07ec 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -84,7 +84,7 @@ main:6: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" import typing MYPY = 0 if MYPY: - None + 1 # E: Unsupported left operand type for + (None) + None + 1 # E: Unsupported left operand type for + ("None") else: None + '' [builtins fixtures/bool.pyi] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 566841888693..802c6c8c8b86 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -10,8 +10,8 @@ from typing import Tuple def f( *b: 'B') -> None: ab = None # type: Tuple[B, ...] ac = None # type: Tuple[C, ...] - b = ac # E: Incompatible types in assignment (expression has type Tuple[C, ...], variable has type Tuple[B, ...]) - ac = b # E: Incompatible types in assignment (expression has type Tuple[B, ...], variable has type Tuple[C, ...]) + b = ac # E: Incompatible types in assignment (expression has type "Tuple[C, ...]", variable has type "Tuple[B, ...]") + ac = b # E: Incompatible types in assignment (expression has type "Tuple[B, ...]", variable has type "Tuple[C, ...]") b = ab ab = b @@ -108,7 +108,7 @@ it1 = None # type: Iterable[int] it2 = None # type: Iterable[str] def f(*x: int) -> None: pass f(*it1) -f(*it2) # E: Argument 1 to "f" has incompatible type *Iterable[str]; expected "int" +f(*it2) # E: Argument 1 to "f" has incompatible type *"Iterable[str]"; expected "int" [builtins fixtures/for.pyi] [case testCallVarargsFunctionWithIterableAndPositional] @@ -208,7 +208,7 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:7: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" +main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" [case testCallingWithTupleVarArgs] @@ -277,13 +277,13 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:3: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" -main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" +main:3: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" main:5: error: Argument 1 to "f" has incompatible type "B"; expected "A" main:6: error: Argument 2 to "f" has incompatible type "A"; expected "B" -main:7: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:7: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 1 to "g" has incompatible type *List[B]; expected "A" +main:9: error: Argument 1 to "g" has incompatible type *"List[B]"; expected "A" [case testCallingVarArgsFunctionWithTupleVarArgs] @@ -340,7 +340,7 @@ from typing import List aa = None # type: List[A] ab = None # type: List[B] -g(*aa) # E: Argument 1 to "g" has incompatible type *List[A]; expected "B" +g(*aa) # E: Argument 1 to "g" has incompatible type *"List[A]"; expected "B" f(*aa) f(*ab) g(*ab) @@ -377,8 +377,8 @@ class B: pass [builtins fixtures/list.pyi] [out] main:3: error: Too few arguments for "f" -main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" -main:5: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" +main:5: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:6: error: Argument 1 to "f" has incompatible type *"Tuple[A, A, B]"; expected "B" [case testVarArgsAfterKeywordArgInCall1-skip] @@ -491,11 +491,11 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:6: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" -main:7: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" +main:6: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" -main:10: error: Argument 3 to "f" has incompatible type *List[A]; expected "B" +main:9: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" +main:10: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" main:11: error: List or tuple expected as variable arguments main:12: error: List or tuple expected as variable arguments @@ -533,8 +533,8 @@ a, aa = G().f(*[a]) # Fail aa, a = G().f(*[a]) # Fail ab, aa = G().f(*[a]) # Fail -ao, ao = G().f(*[a]) # E: Incompatible types in assignment (expression has type List[], variable has type List[object]) -aa, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type List[], variable has type List[A]) +ao, ao = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[]", variable has type "List[object]") +aa, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") class G(Generic[T]): def f(self, *a: S) -> Tuple[List[S], List[T]]: @@ -544,11 +544,11 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:9: error: Incompatible types in assignment (expression has type List[A], variable has type "A") -main:9: error: Incompatible types in assignment (expression has type List[], variable has type List[A]) -main:10: error: Incompatible types in assignment (expression has type List[], variable has type "A") -main:11: error: Incompatible types in assignment (expression has type List[], variable has type List[A]) -main:11: error: Argument 1 to "f" of "G" has incompatible type *List[A]; expected "B" +main:9: error: Incompatible types in assignment (expression has type "List[A]", variable has type "A") +main:9: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") +main:10: error: Incompatible types in assignment (expression has type "List[]", variable has type "A") +main:11: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") +main:11: error: Argument 1 to "f" of "G" has incompatible type *"List[A]"; expected "B" -- Comment signatures From e134f8fd1fbb064cc8e3004d70db52940c03a613 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 15:57:10 -0700 Subject: [PATCH 06/25] No quotes around Module --- mypy/messages.py | 3 +++ test-data/unit/check-ignore.test | 4 ++-- test-data/unit/check-incremental.test | 6 +++--- test-data/unit/check-modules.test | 16 ++++++++-------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 461f1800b4a2..e5cec939882b 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -242,6 +242,9 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: None -> None callable type -> "" (empty string) """ + ret = self._format_simple(typ, verbosity) + if ret == "Module": + return ret return '"{}"'.format(self._format_simple(typ, verbosity)) def _format_simple(self, typ: Type, verbosity: int = 0) -> str: diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 5f2fd773a0c1..ad183ac1fe2b 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -46,7 +46,7 @@ import b # type: ignore reveal_type(a.foo) # E: Revealed type is 'Any' reveal_type(b.foo) # E: Revealed type is 'builtins.int' a.bar() -b.bar() # E: "Module" has no attribute "bar" +b.bar() # E: Module has no attribute "bar" [file b.py] foo = 3 @@ -76,7 +76,7 @@ class B(A): import m m.x = object # type: ignore m.f() # type: ignore -m.y # E: "Module" has no attribute "y" +m.y # E: Module has no attribute "y" [file m.py] [builtins fixtures/module.pyi] diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 78da587098ec..23fafc24edf5 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -325,7 +325,7 @@ const = 3 [stale mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod4" +tmp/mod1.py:3: error: Module has no attribute "mod4" [case testIncrementalLongBrokenCascade] import mod1 @@ -360,7 +360,7 @@ const = 3 [stale mod6] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod7" +tmp/mod1.py:3: error: Module has no attribute "mod7" [case testIncrementalNestedBrokenCascade] import mod1 @@ -386,7 +386,7 @@ const = 3 [stale mod2.mod3] [builtins fixtures/module.pyi] [out2] -tmp/mod1.py:3: error: "Module" has no attribute "mod4" +tmp/mod1.py:3: error: Module has no attribute "mod4" [case testIncrementalNestedBrokenCascadeWithType1] import mod1, mod2.mod3.mod5 diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 10c6a22680d6..423994ad981b 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -155,16 +155,16 @@ import m import typing class A: pass -m() # E: "Module" not callable -a = m # type: A # E: Incompatible types in assignment (expression has type "Module", variable has type "A") -m + None # E: Unsupported left operand type for + ("Module") +m() # E: Module not callable +a = m # type: A # E: Incompatible types in assignment (expression has type Module, variable has type "A") +m + None # E: Unsupported left operand type for + (Module) [file m.py] [builtins fixtures/module.pyi] [case testNameDefinedInDifferentModule] import m, n import typing -m.x # E: "Module" has no attribute "x" +m.x # E: Module has no attribute "x" [file m.py] y = object() [file n.py] @@ -330,7 +330,7 @@ import nonexistent [out] tmp/x.py:1: error: Cannot find module named 'nonexistent' tmp/x.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) -main:3: error: "Module" has no attribute "z" +main:3: error: Module has no attribute "z" [case testUnknownModuleImportedWithinFunction] def f(): @@ -648,7 +648,7 @@ def f(x: str) -> None: pass if object(): import m else: - m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Module") + m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Module) [file m.py] [builtins fixtures/module.pyi] [out] @@ -752,7 +752,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents] from a import b reveal_type(b.value) # E: Revealed type is 'builtins.str' -b.c.value # E: "Module" has no attribute "c" +b.c.value # E: Module has no attribute "c" a.value # E: Name 'a' is not defined [file a/__init__.py] @@ -853,7 +853,7 @@ bar = parent.unrelated.ShouldNotLoad() [builtins fixtures/module.pyi] [out] tmp/parent/child.py:8: error: Revealed type is 'parent.common.SomeClass' -tmp/parent/child.py:9: error: "Module" has no attribute "unrelated" +tmp/parent/child.py:9: error: Module has no attribute "unrelated" [case testSubmoduleMixingImportFromAndImport2] import parent.child From 60231def498f1c2cecbc71a5fb041fd283626a47 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 16:53:16 -0700 Subject: [PATCH 07/25] And even more tests that need to be updated --- test-data/unit/check-functions.test | 24 ++++++++++----------- test-data/unit/check-optional.test | 4 ++-- test-data/unit/pythoneval-asyncio.test | 8 +++---- test-data/unit/pythoneval.test | 30 +++++++++++++++----------- typeshed | 2 +- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 3bd2de532384..be43f47b3689 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2072,23 +2072,23 @@ def fn( from typing import Union, Dict, List def f() -> List[Union[str, int]]: x = ['a'] - return x # E: Incompatible return value type (got List[str], expected List[Union[str, int]]) \ -# N: Perhaps you need a type annotation for "x"? Suggestion: List[Union[str, int]] + return x # E: Incompatible return value type (got "List[str]", expected "List[Union[str, int]]") \ +# N: Perhaps you need a type annotation for "x"? Suggestion: "List[Union[str, int]]" def g() -> Dict[str, Union[str, int]]: x = {'a': 'a'} - return x # E: Incompatible return value type (got Dict[str, str], expected Dict[str, Union[str, int]]) \ -# N: Perhaps you need a type annotation for "x"? Suggestion: Dict[str, Union[str, int]] + return x # E: Incompatible return value type (got "Dict[str, str]", expected "Dict[str, Union[str, int]]") \ +# N: Perhaps you need a type annotation for "x"? Suggestion: "Dict[str, Union[str, int]]" def h() -> Dict[Union[str, int], str]: x = {'a': 'a'} - return x # E: Incompatible return value type (got Dict[str, str], expected Dict[Union[str, int], str]) \ -# N: Perhaps you need a type annotation for "x"? Suggestion: Dict[Union[str, int], str] + return x # E: Incompatible return value type (got "Dict[str, str]", expected "Dict[Union[str, int], str]") \ +# N: Perhaps you need a type annotation for "x"? Suggestion: "Dict[Union[str, int], str]" def i() -> List[Union[int, float]]: x: List[int] = [1] - return x # E: Incompatible return value type (got List[int], expected List[Union[int, float]]) \ -# N: Perhaps you need a type annotation for "x"? Suggestion: List[Union[int, float]] + return x # E: Incompatible return value type (got "List[int]", expected "List[Union[int, float]]") \ +# N: Perhaps you need a type annotation for "x"? Suggestion: "List[Union[int, float]]" [builtins fixtures/dict.pyi] @@ -2096,11 +2096,11 @@ def i() -> List[Union[int, float]]: from typing import Union, List def f() -> List[Union[int, float]]: x = ['a'] - return x # E: Incompatible return value type (got List[str], expected List[Union[int, float]]) + return x # E: Incompatible return value type (got "List[str]", expected "List[Union[int, float]]") def g() -> List[Union[str, int]]: x = ('a', 2) - return x # E: Incompatible return value type (got "Tuple[str, int]", expected List[Union[str, int]]) + return x # E: Incompatible return value type (got "Tuple[str, int]", expected "List[Union[str, int]]") [builtins fixtures/list.pyi] @@ -2108,7 +2108,7 @@ def g() -> List[Union[str, int]]: from typing import Union, Dict, List def f() -> Dict[str, Union[str, int]]: x = {'a': 'a', 'b': 2} - return x # E: Incompatible return value type (got Dict[str, object], expected Dict[str, Union[str, int]]) + return x # E: Incompatible return value type (got "Dict[str, object]", expected "Dict[str, Union[str, int]]") def g() -> Dict[str, Union[str, int]]: x: Dict[str, Union[str, int]] = {'a': 'a', 'b': 2} @@ -2116,7 +2116,7 @@ def g() -> Dict[str, Union[str, int]]: def h() -> List[Union[str, int]]: x = ['a', 2] - return x # E: Incompatible return value type (got List[object], expected List[Union[str, int]]) + return x # E: Incompatible return value type (got "List[object]", expected "List[Union[str, int]]") def i() -> List[Union[str, int]]: x: List[Union[str, int]] = ['a', 2] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 3b3f688f1801..c7920962a825 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -127,7 +127,7 @@ f(None) [case testNoInferOptionalFromDefaultNone] # flags: --no-implicit-optional -def f(x: int = None) -> None: # E: Incompatible types in assignment (expression has type None, variable has type "int") +def f(x: int = None) -> None: # E: Incompatible types in assignment (expression has type "None", variable has type "int") pass [out] @@ -140,7 +140,7 @@ f(None) [case testNoInferOptionalFromDefaultNoneComment] # flags: --no-implicit-optional -def f(x=None): # E: Incompatible types in assignment (expression has type None, variable has type "int") +def f(x=None): # E: Incompatible types in assignment (expression has type "None", variable has type "int") # type: (int) -> None pass [out] diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 6d1690339ff7..114cd4b9cb66 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -339,7 +339,7 @@ loop.run_until_complete(future) print(future.result()) loop.close() [out] -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type Future[str]; expected Future[int] +_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorUsingDifferentFutureTypeAndSetFutureDifferentInternalType] from typing import Generator, Any @@ -359,7 +359,7 @@ print(future.result()) loop.close() [out] _program.py:8: error: Argument 1 to "set_result" of "Future" has incompatible type "str"; expected "int" -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type Future[str]; expected Future[int] +_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorSettingCallbackWithDifferentFutureType] import typing @@ -422,7 +422,7 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got Future[Future[int]], expected Future[Future[Future[int]]]) +_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[Future[Future[int]]]") [case testErrorOneLessFutureInReturnType] import typing @@ -456,7 +456,7 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got Future[Future[int]], expected Future[int]) +_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[int]") [case testErrorAssignmentDifferentType] import typing diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index be05dafe20c8..ac2461906758 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -391,7 +391,7 @@ txt(sys.stdout) bin(sys.stdout) [out] _program.py:5: error: Argument 1 to "write" of "IO" has incompatible type "bytes"; expected "str" -_program.py:10: error: Argument 1 to "bin" has incompatible type "TextIO"; expected IO[bytes] +_program.py:10: error: Argument 1 to "bin" has incompatible type "TextIO"; expected "IO[bytes]" [case testBuiltinOpen] f = open('x') @@ -399,6 +399,7 @@ f.write('x') f.write(b'x') f.foobar() [out] +<<<<<<< e134f8fd1fbb064cc8e3004d70db52940c03a613 _program.py:3: error: Argument 1 to "write" of "IO" has incompatible type "bytes"; expected "str" _program.py:4: error: IO[str] has no attribute "foobar" @@ -426,6 +427,9 @@ _testOpenReturnTypeInferenceSpecialCases.py:1: error: Too few arguments for "ope _testOpenReturnTypeInferenceSpecialCases.py:2: error: Revealed type is 'typing.IO[builtins.bytes]' _testOpenReturnTypeInferenceSpecialCases.py:3: error: Revealed type is 'typing.IO[builtins.bytes]' _testOpenReturnTypeInferenceSpecialCases.py:5: error: Revealed type is 'typing.IO[Any]' +======= +_program.py:4: error: "IO[Any]" has no attribute "foobar" +>>>>>>> And even more tests that need to be updated [case testGenericPatterns] from typing import Pattern @@ -603,7 +607,7 @@ print(tuple(a)) import typing [1] + iter([2, 3]) [out] -_program.py:2: error: Unsupported operand types for + (List[int] and Iterator[int]) +_program.py:2: error: Unsupported operand types for + ("List[int]" and "Iterator[int]") [case testInferHeterogeneousListOfIterables] from typing import Sequence @@ -792,7 +796,7 @@ x = range(3) a = list(map(str, x)) a + 1 [out] -_program.py:4: error: Unsupported operand types for + (List[str] and "int") +_program.py:4: error: Unsupported operand types for + ("List[str]" and "int") [case testNamedTuple] import typing @@ -994,7 +998,7 @@ def f(*x: int) -> None: x.append(1) f(1) [out] -_program.py:3: error: Tuple[int, ...] has no attribute "append" +_program.py:3: error: "Tuple[int, ...]" has no attribute "append" [case testExit] print('a') @@ -1075,14 +1079,14 @@ n = 4 t = ('',) * n t + 1 [out] -_program.py:3: error: Unsupported operand types for + (Tuple[str, ...] and "int") +_program.py:3: error: Unsupported operand types for + ("Tuple[str, ...]" and "int") [case testMultiplyTupleByIntegerReverse] n = 4 t = n * ('',) t + 1 [out] -_program.py:3: error: Unsupported operand types for + (Tuple[str, ...] and "int") +_program.py:3: error: Unsupported operand types for + ("Tuple[str, ...]" and "int") [case testDictWithKeywordArgs] from typing import Dict, Any, List @@ -1094,7 +1098,7 @@ d4 = dict(a=1, b='') # type: Dict[str, Any] result = dict(x=[], y=[]) # type: Dict[str, List[str]] [out] _program.py:3: error: Dict entry 1 has incompatible type "str": "str" -_program.py:5: error: Dict[str, int] has no attribute "xyz" +_program.py:5: error: "Dict[str, int]" has no attribute "xyz" [case testDefaultDict] import typing as t @@ -1122,11 +1126,11 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]): MyDDict(dict)['0'] MyDDict(dict)[0] [out] -_program.py:6: error: Argument 1 to "defaultdict" has incompatible type Type[List[Any]]; expected Callable[[], str] -_program.py:9: error: Invalid index type "str" for defaultdict[int, str]; expected type "int" +_program.py:6: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected Callable[[], str] +_program.py:9: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int" _program.py:9: error: Incompatible types in assignment (expression has type "int", target has type "str") -_program.py:19: error: Dict entry 0 has incompatible type "str": List[] -_program.py:23: error: Invalid index type "str" for MyDDict[Dict[_KT, _VT]]; expected type "int" +_program.py:19: error: Dict entry 0 has incompatible type "str": "List[]" +_program.py:23: error: Invalid index type "str" for "MyDDict[Dict[_KT, _VT]]"; expected type "int" [case testNoSubcriptionOfStdlibCollections] import collections @@ -1148,7 +1152,7 @@ def f(d: collections.defaultdict[int, str]) -> None: _program.py:5: error: "defaultdict" is not subscriptable _program.py:6: error: "Counter" is not subscriptable _program.py:9: error: "defaultdict" is not subscriptable -_program.py:12: error: Invalid index type "int" for defaultdict[str, int]; expected type "str" +_program.py:12: error: Invalid index type "int" for "defaultdict[str, int]"; expected type "str" _program.py:14: error: "defaultdict" is not subscriptable, use "typing.DefaultDict" instead [case testCollectionsAliases] @@ -1176,7 +1180,7 @@ reveal_type(o6) [out] _testCollectionsAliases.py:5: error: Revealed type is 'collections.Counter[builtins.int]' -_testCollectionsAliases.py:6: error: Invalid index type "str" for Counter[int]; expected type "int" +_testCollectionsAliases.py:6: error: Invalid index type "str" for "Counter[int]"; expected type "int" _testCollectionsAliases.py:9: error: Revealed type is 'collections.ChainMap[builtins.int, builtins.str]' _testCollectionsAliases.py:12: error: Revealed type is 'collections.deque[builtins.int]' _testCollectionsAliases.py:15: error: Revealed type is 'collections.Counter[builtins.int*]' diff --git a/typeshed b/typeshed index c1b7fc70203c..c2e6a6f670f5 160000 --- a/typeshed +++ b/typeshed @@ -1 +1 @@ -Subproject commit c1b7fc70203c4b92577f1f4765e0fdb654a8886c +Subproject commit c2e6a6f670f5d75c07eb31cf2509db302825b76d From 735778e85b94335306b654e774f79ffcc97d6a37 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 23 May 2017 21:40:53 -0700 Subject: [PATCH 08/25] incorrect indentation --- mypy/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index e5cec939882b..1ac7428a4ea9 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -244,7 +244,7 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: """ ret = self._format_simple(typ, verbosity) if ret == "Module": - return ret + return ret return '"{}"'.format(self._format_simple(typ, verbosity)) def _format_simple(self, typ: Type, verbosity: int = 0) -> str: From 5922be3fb1e4f23e206bd3dc0f2ee2acc85f2250 Mon Sep 17 00:00:00 2001 From: Brian Weber Date: Tue, 30 May 2017 11:41:38 -0700 Subject: [PATCH 09/25] update tests & merge conflicts --- test-data/unit/pythoneval.test | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index ac2461906758..efbe9eb7b831 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -399,9 +399,8 @@ f.write('x') f.write(b'x') f.foobar() [out] -<<<<<<< e134f8fd1fbb064cc8e3004d70db52940c03a613 _program.py:3: error: Argument 1 to "write" of "IO" has incompatible type "bytes"; expected "str" -_program.py:4: error: IO[str] has no attribute "foobar" +_program.py:4: error: "IO[str]" has no attribute "foobar" [case testOpenReturnTypeInference] reveal_type(open('x')) @@ -427,9 +426,6 @@ _testOpenReturnTypeInferenceSpecialCases.py:1: error: Too few arguments for "ope _testOpenReturnTypeInferenceSpecialCases.py:2: error: Revealed type is 'typing.IO[builtins.bytes]' _testOpenReturnTypeInferenceSpecialCases.py:3: error: Revealed type is 'typing.IO[builtins.bytes]' _testOpenReturnTypeInferenceSpecialCases.py:5: error: Revealed type is 'typing.IO[Any]' -======= -_program.py:4: error: "IO[Any]" has no attribute "foobar" ->>>>>>> And even more tests that need to be updated [case testGenericPatterns] from typing import Pattern From 048dae1410cd46468280d8b7588d14e58699460e Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 24 Aug 2017 12:10:56 -0400 Subject: [PATCH 10/25] Fix trivial quoting mismatches --- test-data/unit/check-abstract.test | 4 +- test-data/unit/check-classes.test | 16 +++---- test-data/unit/check-custom-plugin.test | 2 +- test-data/unit/check-flags.test | 32 +++++++------- test-data/unit/check-generics.test | 2 +- test-data/unit/check-optional.test | 8 ++-- test-data/unit/check-protocols.test | 58 ++++++++++++------------- test-data/unit/check-typeddict.test | 16 +++---- test-data/unit/check-varargs.test | 16 +++---- 9 files changed, 77 insertions(+), 77 deletions(-) diff --git a/test-data/unit/check-abstract.test b/test-data/unit/check-abstract.test index cd8cbe43b595..af078612818b 100644 --- a/test-data/unit/check-abstract.test +++ b/test-data/unit/check-abstract.test @@ -174,8 +174,8 @@ def f(cls: Type[A]) -> A: def g() -> A: return A() # E: Cannot instantiate abstract class 'A' with abstract attribute 'm' -f(A) # E: Only concrete class can be given where 'Type[A]' is expected -f(B) # E: Only concrete class can be given where 'Type[A]' is expected +f(A) # E: Only concrete class can be given where "Type[A]" is expected +f(B) # E: Only concrete class can be given where "Type[A]" is expected f(C) # OK x: Type[B] f(x) # OK diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 49f8c94dd7e4..5dc432bcdb24 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -3292,14 +3292,14 @@ reveal_type(A.g4) # E: Revealed type is 'def () -> def () -> __main__.A' class B(metaclass=M): def foo(self): pass -B.g1 # Should be error: Argument 0 to "g1" of "M" has incompatible type "B"; expected Type[A] -B.g2 # Should be error: Argument 0 to "g2" of "M" has incompatible type "B"; expected Type[TA] +B.g1 # Should be error: Argument 0 to "g1" of "M" has incompatible type "B"; expected "Type[A]" +B.g2 # Should be error: Argument 0 to "g2" of "M" has incompatible type "B"; expected "Type[TA]" B.g3 # Should be error: Argument 0 to "g3" of "M" has incompatible type "B"; expected "TTA" reveal_type(B.g4) # E: Revealed type is 'def () -> def () -> __main__.B' # 4 examples of unsoundness - instantiation, classmethod, staticmethod and ClassVar: -ta: Type[A] = m # E: Incompatible types in assignment (expression has type "M", variable has type Type[A]) +ta: Type[A] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[A]") a: A = ta() reveal_type(ta.g1) # E: Revealed type is 'def () -> __main__.A' reveal_type(ta.g2) # E: Revealed type is 'def () -> __main__.A*' @@ -3307,8 +3307,8 @@ reveal_type(ta.g3) # E: Revealed type is 'def () -> Type[__main__.A]' reveal_type(ta.g4) # E: Revealed type is 'def () -> Type[__main__.A]' x: M = ta -x.g1 # should be error: Argument 0 to "g1" of "M" has incompatible type "M"; expected Type[A] -x.g2 # should be error: Argument 0 to "g2" of "M" has incompatible type "M"; expected Type[TA] +x.g1 # should be error: Argument 0 to "g1" of "M" has incompatible type "M"; expected "Type[A]" +x.g2 # should be error: Argument 0 to "g2" of "M" has incompatible type "M"; expected "Type[TA]" x.g3 # should be error: Argument 0 to "g3" of "M" has incompatible type "M"; expected "TTA" reveal_type(x.g4) # E: Revealed type is 'def () -> __main__.M*' @@ -3321,7 +3321,7 @@ class Class(metaclass=M): def f1(cls: Type[Class]) -> None: pass @classmethod def f2(cls: M) -> None: pass -cl: Type[Class] = m # E: Incompatible types in assignment (expression has type "M", variable has type Type[Class]) +cl: Type[Class] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Class]") reveal_type(cl.f1) # E: Revealed type is 'def ()' reveal_type(cl.f2) # E: Revealed type is 'def ()' x1: M = cl @@ -3329,14 +3329,14 @@ x1: M = cl class Static(metaclass=M): @staticmethod def f() -> None: pass -s: Type[Static] = m # E: Incompatible types in assignment (expression has type "M", variable has type Type[Static]) +s: Type[Static] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Static]") reveal_type(s.f) # E: Revealed type is 'def ()' x2: M = s from typing import ClassVar class Cvar(metaclass=M): x = 1 # type: ClassVar[int] -cv: Type[Cvar] = m # E: Incompatible types in assignment (expression has type "M", variable has type Type[Cvar]) +cv: Type[Cvar] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Cvar]") cv.x x3: M = cv diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index b8e13464ab65..6ea4e3e5ab33 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -118,7 +118,7 @@ from mypy_extensions import DefaultArg from m import Signal s: Signal[[int, DefaultArg(str, 'x')]] = Signal() reveal_type(s) # E: Revealed type is 'm.Signal[def (builtins.int, x: builtins.str =)]' -s.x # E: Signal[Callable[[int, str], None]] has no attribute "x" +s.x # E: "Signal[Callable[[int, str], None]]" has no attribute "x" ss: Signal[int, str] # E: Invalid "Signal" type (expected "Signal[[t, ...]]") [file m.py] from typing import TypeVar, Generic, Callable diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index c991d1bf4117..9b1afdadf7f7 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -462,7 +462,7 @@ x = 0 x = None [file optional.py] x = 0 -x = None # E: Incompatible types in assignment (expression has type None, variable has type "int") +x = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") [file mypy.ini] [[mypy] @@ -486,10 +486,10 @@ f(optional_int) # optional ints can be used as ints in this file [file optional.py] import standard def f(x: int) -> None: pass -standard.an_int = None # E: Incompatible types in assignment (expression has type None, variable has type "int") +standard.an_int = None # E: Incompatible types in assignment (expression has type "None", variable has type "int") standard.optional_int = None # OK -- explicitly declared as optional f(standard.an_int) # ints can be used as ints -f(standard.optional_int) # E: Argument 1 to "f" has incompatible type None; expected "int" +f(standard.optional_int) # E: Argument 1 to "f" has incompatible type "None"; expected "int" [file mypy.ini] [[mypy] @@ -603,9 +603,9 @@ def foo(l: List[Unchecked]) -> List[Unchecked]: return l [builtins fixtures/list.pyi] [out] -main:5: error: Return type becomes List[Any] due to an unfollowed import -main:5: error: Argument 1 to "foo" becomes List[Any] due to an unfollowed import -main:6: error: Type of variable becomes List[Any] due to an unfollowed import +main:5: error: Return type becomes "List[Any]" due to an unfollowed import +main:5: error: Argument 1 to "foo" becomes "List[Any]" due to an unfollowed import +main:6: error: Type of variable becomes "List[Any]" due to an unfollowed import [case testDisallowImplicitAnyInherit] # flags: --ignore-missing-imports --disallow-any=unimported @@ -615,7 +615,7 @@ from typing import List class C(Unchecked): # E: Base type Unchecked becomes "Any" due to an unfollowed import pass -class A(List[Unchecked]): # E: Base type becomes List[Any] due to an unfollowed import +class A(List[Unchecked]): # E: Base type becomes "List[Any]" due to an unfollowed import pass [builtins fixtures/list.pyi] @@ -626,7 +626,7 @@ from typing import List X = List[Unchecked] -def f(x: X) -> None: # E: Argument 1 to "f" becomes List[Any] due to an unfollowed import +def f(x: X) -> None: # E: Argument 1 to "f" becomes "List[Any]" due to an unfollowed import pass [builtins fixtures/list.pyi] @@ -637,7 +637,7 @@ from typing import List, cast foo = [1, 2, 3] -cast(List[Unchecked], foo) # E: Target type of cast becomes List[Any] due to an unfollowed import +cast(List[Unchecked], foo) # E: Target type of cast becomes "List[Any]" due to an unfollowed import cast(Unchecked, foo) # E: Target type of cast becomes "Any" due to an unfollowed import [builtins fixtures/list.pyi] @@ -661,7 +661,7 @@ T = TypeVar('T', Unchecked, List[Unchecked], str) [builtins fixtures/list.pyi] [out] main:5: error: Constraint 1 becomes "Any" due to an unfollowed import -main:5: error: Constraint 2 becomes List[Any] due to an unfollowed import +main:5: error: Constraint 2 becomes "List[Any]" due to an unfollowed import [case testDisallowImplicitAnyNewType] # flags: --ignore-missing-imports --disallow-any=unimported @@ -669,7 +669,7 @@ from typing import NewType, List from missing import Unchecked Baz = NewType('Baz', Unchecked) # E: Argument 2 to NewType(...) must be subclassable (got Any) -Bar = NewType('Bar', List[Unchecked]) # E: Argument 2 to NewType(...) becomes List[Any] due to an unfollowed import +Bar = NewType('Bar', List[Unchecked]) # E: Argument 2 to NewType(...) becomes "List[Any]" due to an unfollowed import [builtins fixtures/list.pyi] @@ -720,7 +720,7 @@ from mypy_extensions import TypedDict from typing import List from x import Unchecked -M = TypedDict('M', {'x': str, 'y': List[Unchecked]}) # E: Type of a TypedDict key becomes List[Any] due to an unfollowed import +M = TypedDict('M', {'x': str, 'y': List[Unchecked]}) # E: Type of a TypedDict key becomes "List[Any]" due to an unfollowed import def f(m: M) -> M: pass # no error [builtins fixtures/dict.pyi] @@ -883,9 +883,9 @@ def g(s: List[Any]) -> None: f(0) -# type of list below is inferred with expected type of List[Any], so that becomes it's type +# type of list below is inferred with expected type of "List[Any]", so that becomes it's type # instead of List[str] -g(['']) # E: Expression type contains "Any" (has type List[Any]) +g(['']) # E: Expression type contains "Any" (has type "List[Any]") [builtins fixtures/list.pyi] [case testDisallowAnyExprAllowsAnyInCast] @@ -916,8 +916,8 @@ n = Foo().g # type: Any # E: Expression has type "Any" from typing import List l: List = [] -l.append(1) # E: Expression type contains "Any" (has type List[Any]) -k = l[0] # E: Expression type contains "Any" (has type List[Any]) # E: Expression has type "Any" +l.append(1) # E: Expression type contains "Any" (has type "List[Any]") +k = l[0] # E: Expression type contains "Any" (has type "List[Any]") # E: Expression has type "Any" [builtins fixtures/list.pyi] [case testDisallowAnyExprTypeVar] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index fe14853e32b5..21381d4238e9 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -978,7 +978,7 @@ class C: c: Type[object] = Iterable[int] # This is however also a variable a = B b = int # E: Cannot assign multiple types to name "b" without an explicit "Type[...]" annotation \ - # E: Incompatible types in assignment (expression has type Type[int], variable has type "Type alias to Union") + # E: Incompatible types in assignment (expression has type "Type[int]", variable has type "Type alias to Union") c = int def f(self, x: a) -> None: pass # E: Invalid type "__main__.C.a" def g(self, x: b) -> None: pass diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index cb40772fe56b..545df7b31147 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -127,7 +127,7 @@ f(None) [case testNoInferOptionalFromDefaultNone] # flags: --no-implicit-optional -def f(x: int = None) -> None: # E: Incompatible types in assignment (expression has type "None", variable has type "int") +def f(x: int = None) -> None: # E: Incompatible default for argument "x" (default has type "None", argument has type "int") pass [out] @@ -140,7 +140,7 @@ f(None) [case testNoInferOptionalFromDefaultNoneComment] # flags: --no-implicit-optional -def f(x=None): # E: Incompatible types in assignment (expression has type "None", variable has type "int") +def f(x=None): # E: Incompatible default for argument "x" (default has type "None", argument has type "int") # type: (int) -> None pass [out] @@ -455,7 +455,7 @@ reveal_type(l) # E: Revealed type is 'builtins.list[typing.Generator*[builtins. [builtins fixtures/list.pyi] [case testNoneListTernary] -x = [None] if "" else [1] # E: List item 0 has incompatible type "int"; expected None +x = [None] if "" else [1] # E: List item 0 has incompatible type "int"; expected "None" [builtins fixtures/list.pyi] [case testListIncompatibleErrorMessage] @@ -465,7 +465,7 @@ def foo(l: List[Callable[[], str]]) -> None: pass def f() -> int: return 42 -foo([f]) # E: List item 0 has incompatible type Callable[[], int]; expected Callable[[], str] +foo([f]) # E: List item 0 has incompatible type "Callable[[], int]"; expected "Callable[[], str]" [builtins fixtures/list.pyi] [case testInferEqualsNotOptional] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index ba190988be61..b6adfedaab9c 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -197,7 +197,7 @@ class C: meth: int x: P = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P") \ # N: Following member(s) of "C" have conflicts: \ - # N: meth: expected Callable[[], int], got "int" + # N: meth: expected "Callable[[], int]", got "int" [case testProtocolMethodVsAttributeErrors2] from typing import Protocol @@ -272,7 +272,7 @@ class MyHashable(Protocol): class C(MyHashable): __my_hash__ = None # E: Incompatible types in assignment \ -(expression has type None, base class "MyHashable" defined the type as Callable[[MyHashable], int]) +(expression has type "None", base class "MyHashable" defined the type as Callable[[MyHashable], int]) [case testProtocolsWithNoneAndStrictOptional] # flags: --strict-optional @@ -289,10 +289,10 @@ f(C()) # Error! [out] main:9: error: Incompatible types in assignment (expression has type "C", variable has type "P") main:9: note: Following member(s) of "C" have conflicts: -main:9: note: x: expected "int", got None +main:9: note: x: expected "int", got "None" main:11: error: Argument 1 to "f" has incompatible type "C"; expected "P" main:11: note: Following member(s) of "C" have conflicts: -main:11: note: x: expected "int", got None +main:11: note: x: expected "int", got "None" -- Semanal errors in protocol types -- -------------------------------- @@ -442,18 +442,18 @@ class B(A): pass x1: Pco[B] y1: Pco[A] -x1 = y1 # E: Incompatible types in assignment (expression has type Pco[A], variable has type Pco[B]) -y1 = x1 # E: Incompatible types in assignment (expression has type Pco[B], variable has type Pco[A]) +x1 = y1 # E: Incompatible types in assignment (expression has type "Pco[A]", variable has type "Pco[B]") +y1 = x1 # E: Incompatible types in assignment (expression has type "Pco[B]", variable has type "Pco[A]") x2: Pcontra[B] y2: Pcontra[A] -y2 = x2 # E: Incompatible types in assignment (expression has type Pcontra[B], variable has type Pcontra[A]) -x2 = y2 # E: Incompatible types in assignment (expression has type Pcontra[A], variable has type Pcontra[B]) +y2 = x2 # E: Incompatible types in assignment (expression has type "Pcontra[B]", variable has type "Pcontra[A]") +x2 = y2 # E: Incompatible types in assignment (expression has type "Pcontra[A]", variable has type "Pcontra[B]") x3: Pinv[B] y3: Pinv[A] -y3 = x3 # E: Incompatible types in assignment (expression has type Pinv[B], variable has type Pinv[A]) -x3 = y3 # E: Incompatible types in assignment (expression has type Pinv[A], variable has type Pinv[B]) +y3 = x3 # E: Incompatible types in assignment (expression has type "Pinv[B]", variable has type "Pinv[A]") +x3 = y3 # E: Incompatible types in assignment (expression has type "Pinv[A]", variable has type "Pinv[B]") [case testProtocolVarianceWithCallableAndList] from typing import Protocol, TypeVar, Callable, List @@ -586,7 +586,7 @@ class C: c: C var: P2[int, int] = c -var2: P2[int, str] = c # E: Incompatible types in assignment (expression has type "C", variable has type P2[int, str]) \ +var2: P2[int, str] = c # E: Incompatible types in assignment (expression has type "C", variable has type "P2[int, str]") \ # N: Following member(s) of "C" have conflicts: \ # N: attr2: expected "Tuple[int, str]", got "Tuple[int, int]" @@ -597,7 +597,7 @@ class E(D[T]): def f(x: T) -> T: z: P2[T, T] = E[T]() - y: P2[T, T] = D[T]() # E: Incompatible types in assignment (expression has type D[T], variable has type P2[T, T]) \ + y: P2[T, T] = D[T]() # E: Incompatible types in assignment (expression has type "D[T]", variable has type "P2[T, T]") \ # N: 'D' is missing following 'P2' protocol member: \ # N: attr2 return x @@ -628,7 +628,7 @@ class D(A, B): pass x: P = D() # Same as P[Any, Any] -var: P[Union[int, P], Union[P, str]] = C() # E: Incompatible types in assignment (expression has type "C", variable has type P[Union[int, P[Any, Any]], Union[P[Any, Any], str]]) \ +var: P[Union[int, P], Union[P, str]] = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P[Union[int, P[Any, Any]], Union[P[Any, Any], str]]") \ # N: Following member(s) of "C" have conflicts: \ # N: attr1: expected "Union[int, P[Any, Any]]", got "int" \ # N: attr2: expected "Union[P[Any, Any], str]", got "str" @@ -653,7 +653,7 @@ class C: var: P[Union[int, P], Union[P, str]] = C() # OK for covariant var2: P[Union[str, P], Union[P, int]] = C() [out] -main:18: error: Incompatible types in assignment (expression has type "C", variable has type P[Union[str, P[Any, Any]], Union[P[Any, Any], int]]) +main:18: error: Incompatible types in assignment (expression has type "C", variable has type "P[Union[str, P[Any, Any]], Union[P[Any, Any], int]]") main:18: note: Following member(s) of "C" have conflicts: main:18: note: Expected: main:18: note: def attr1(self) -> Union[str, P[Any, Any]] @@ -799,7 +799,7 @@ class L: def last(seq: Linked[T]) -> T: pass -last(L()) # E: Argument 1 to "last" has incompatible type "L"; expected Linked[] +last(L()) # E: Argument 1 to "last" has incompatible type "L"; expected "Linked[]" [case testMutuallyRecursiveProtocols] from typing import Protocol, Sequence, List @@ -842,7 +842,7 @@ class B: t: P1 t = A() # E: Incompatible types in assignment (expression has type "A", variable has type "P1") \ # N: Following member(s) of "A" have conflicts: \ - # N: attr1: expected Sequence[P2], got List[B] + # N: attr1: expected "Sequence[P2]", got "List[B]" [builtins fixtures/list.pyi] [case testMutuallyRecursiveProtocolsTypesWithSubteMismatchWriteable] @@ -1385,13 +1385,13 @@ def f(cls: Type[P]) -> P: def g() -> P: return P() # E: Cannot instantiate protocol class "P" -f(P) # E: Only concrete class can be given where 'Type[P]' is expected +f(P) # E: Only concrete class can be given where "Type[P]" is expected f(B) # OK f(C) # OK x: Type[P1] xbad: Type[Pbad] f(x) # OK -f(xbad) # E: Argument 1 to "f" has incompatible type Type[Pbad]; expected Type[P] +f(xbad) # E: Argument 1 to "f" has incompatible type "Type[Pbad]"; expected "Type[P]" [case testInstantiationProtocolInTypeForAliases] from typing import Type, Protocol @@ -1409,7 +1409,7 @@ Alias = P GoodAlias = C Alias() # E: Cannot instantiate protocol class "P" GoodAlias() -f(Alias) # E: Only concrete class can be given where 'Type[P]' is expected +f(Alias) # E: Only concrete class can be given where "Type[P]" is expected f(GoodAlias) [case testInstantiationProtocolInTypeForVariables] @@ -1424,13 +1424,13 @@ class C: var: Type[P] var() -var = P # E: Can only assign concrete classes to a variable of type 'Type[P]' +var = P # E: Can only assign concrete classes to a variable of type "Type[P]" var = B # OK var = C # OK var_old = None # type: Type[P] # Old syntax for variable annotations var_old() -var_old = P # E: Can only assign concrete classes to a variable of type 'Type[P]' +var_old = P # E: Can only assign concrete classes to a variable of type "Type[P]" var_old = B # OK var_old = C # OK @@ -1596,7 +1596,7 @@ def f(x: MyProto[int]) -> None: f(t) # OK y: MyProto[str] -y = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type MyProto[str]) +y = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "MyProto[str]") [builtins fixtures/isinstancelist.pyi] [case testBasicNamedTupleStructuralSubtyping] @@ -1631,11 +1631,11 @@ def fun3(x: P[T, T]) -> T: return x.x fun(z) -fun2(z) # E: Argument 1 to "fun2" has incompatible type "N"; expected P[int, int] \ +fun2(z) # E: Argument 1 to "fun2" has incompatible type "N"; expected "P[int, int]" \ # N: Following member(s) of "N" have conflicts: \ # N: y: expected "int", got "str" -fun(N2(1)) # E: Argument 1 to "fun" has incompatible type "N2"; expected P[int, str] \ +fun(N2(1)) # E: Argument 1 to "fun" has incompatible type "N2"; expected "P[int, str]" \ # N: 'N2' is missing following 'P' protocol member: \ # N: y @@ -1663,7 +1663,7 @@ def apply_gen(f: Callable[[T], T]) -> T: reveal_type(apply_gen(Add5())) # E: Revealed type is 'builtins.int*' def apply_str(f: Callable[[str], int], x: str) -> int: return f(x) -apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected Callable[[str], int] \ +apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "Callable[[str], int]" \ # N: 'Add5.__call__' has type 'Callable[[Arg(int, 'x')], int]' [builtins fixtures/isinstancelist.pyi] @@ -1783,7 +1783,7 @@ f1(C1()) f2(C2()) f3(C3()) -f2(C3()) # E: Argument 1 to "f2" has incompatible type "C3"; expected P2[str] +f2(C3()) # E: Argument 1 to "f2" has incompatible type "C3"; expected "P2[str]" a: Any f1(a) f2(a) @@ -2042,8 +2042,8 @@ def f1(x: Iterable[str]) -> None: pass def f2(x: Sequence[str]) -> None: pass # The errors below should be short -f1(N(1)) # E: Argument 1 to "f1" has incompatible type "N"; expected Iterable[str] -f2(N(2)) # E: Argument 1 to "f2" has incompatible type "N"; expected Sequence[str] +f1(N(1)) # E: Argument 1 to "f1" has incompatible type "N"; expected "Iterable[str]" +f2(N(2)) # E: Argument 1 to "f2" has incompatible type "N"; expected "Sequence[str]" [builtins fixtures/tuple.pyi] [case testNotManyFlagConflitsShownInProtocols] @@ -2092,7 +2092,7 @@ class MockDict(MockMapping[T]): def f(x: MockMapping[int]) -> None: pass x: MockDict[str] -f(x) # E: Argument 1 to "f" has incompatible type MockDict[str]; expected MockMapping[int] +f(x) # E: Argument 1 to "f" has incompatible type "MockDict[str]"; expected "MockMapping[int]" [case testProtocolNotesForComplexSignatures] from typing import Protocol, Optional diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 97295a089176..33b27a1ad23e 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -343,7 +343,7 @@ Point = TypedDict('Point', {'x': int, 'y': int}) def as_dict(p: Point) -> Dict[str, int]: return p # E: Incompatible return value type (got "Point", expected "Dict[str, int]") def as_mutable_mapping(p: Point) -> MutableMapping[str, int]: - return p # E: Incompatible return value type (got "Point", expected "MutableMapping[str, int])" \ + return p # E: Incompatible return value type (got "Point", expected "MutableMapping[str, int]") \ # N: 'Point' is missing following 'MutableMapping' protocol member: \ # N: __setitem__ [builtins fixtures/dict.pyi] @@ -369,9 +369,9 @@ c: C def f(a: A) -> None: pass l = [a, b] # Join generates an anonymous TypedDict -f(l) # E: Argument 1 to "f" has incompatible type List[TypedDict({'x': int})]; expected "A" +f(l) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x': int})]"; expected "A" ll = [b, c] -f(ll) # E: Argument 1 to "f" has incompatible type List[TypedDict({'x': int, 'z': str})]; expected "A" +f(ll) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x': int, 'z': str})]"; expected "A" [builtins fixtures/dict.pyi] [case testTypedDictWithSimpleProtocol] @@ -1096,9 +1096,9 @@ c: C def f(a: A) -> None: pass l = [a, b] # Join generates an anonymous TypedDict -f(l) # E: Argument 1 to "f" has incompatible type List[TypedDict({'x'?: int})]; expected "A" +f(l) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x'?: int})]"; expected "A" ll = [b, c] -f(ll) # E: Argument 1 to "f" has incompatible type List[TypedDict({'x'?: int, 'z'?: str})]; expected "A" +f(ll) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x'?: int, 'z'?: str})]"; expected "A" [builtins fixtures/dict.pyi] @@ -1184,7 +1184,7 @@ f(a) [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] [out] -main:13: error: Argument 1 to "f" has incompatible type "A"; expected Iterable[int] +main:13: error: Argument 1 to "f" has incompatible type "A"; expected "Iterable[int]" main:13: note: Following member(s) of "A" have conflicts: main:13: note: Expected: main:13: note: def __iter__(self) -> Iterator[int] @@ -1284,7 +1284,7 @@ class C(B): pass x: X reveal_type(x) # E: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' m1: Mapping[str, B] = x -m2: Mapping[str, C] = x # E: Incompatible types in assignment (expression has type "X", variable has type Mapping[str, C]) +m2: Mapping[str, C] = x # E: Incompatible types in assignment (expression has type "X", variable has type "Mapping[str, C]") [builtins fixtures/dict.pyi] [case testForwardReferenceInClassTypedDict] @@ -1298,7 +1298,7 @@ class C(B): pass x: X reveal_type(x) # E: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' m1: Mapping[str, B] = x -m2: Mapping[str, C] = x # E: Incompatible types in assignment (expression has type "X", variable has type Mapping[str, C]) +m2: Mapping[str, C] = x # E: Incompatible types in assignment (expression has type "X", variable has type "Mapping[str, C]") [builtins fixtures/dict.pyi] [case testForwardReferenceToTypedDictInTypedDict] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 0cac3b2d962f..0450981e4f5f 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -603,15 +603,15 @@ a = {'a': [1, 2]} b = {'b': ['c', 'd']} c = {'c': 1.0} d = {'d': 1} -f(a) # E: Argument 1 to "f" has incompatible type Dict[str, List[int]]; expected Dict[str, Sequence[int]] \ +f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, List[int]]"; expected "Dict[str, Sequence[int]]" \ # N: "Dict" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type -f(b) # E: Argument 1 to "f" has incompatible type Dict[str, List[str]]; expected Dict[str, Sequence[int]] +f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, List[str]]"; expected "Dict[str, Sequence[int]]" g(c) -g(d) # E: Argument 1 to "g" has incompatible type Dict[str, int]; expected Dict[str, float] \ +g(d) # E: Argument 1 to "g" has incompatible type "Dict[str, int]"; expected "Dict[str, float]" \ # N: "Dict" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type -h(c) # E: Argument 1 to "h" has incompatible type Dict[str, float]; expected Dict[str, int] +h(c) # E: Argument 1 to "h" has incompatible type "Dict[str, float]"; expected "Dict[str, int]" h(d) [builtins fixtures/dict.pyi] @@ -619,12 +619,12 @@ h(d) from typing import List, Union def f(numbers: List[Union[int, float]]) -> None: pass a = [1, 2] -f(a) # E: Argument 1 to "f" has incompatible type List[int]; expected List[Union[int, float]] \ +f(a) # E: Argument 1 to "f" has incompatible type "List[int]"; expected "List[Union[int, float]]" \ # N: "List" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant x = [1] y = ['a'] -x = y # E: Incompatible types in assignment (expression has type List[str], variable has type List[int]) +x = y # E: Incompatible types in assignment (expression has type "List[str]", variable has type "List[int]") [builtins fixtures/list.pyi] [case testInvariantTypeConfusingNames] @@ -635,6 +635,6 @@ def f(x: Listener) -> None: pass def g(y: DictReader) -> None: pass a = [1, 2] b = {'b': 1} -f(a) # E: Argument 1 to "f" has incompatible type List[int]; expected "Listener" -g(b) # E: Argument 1 to "g" has incompatible type Dict[str, int]; expected "DictReader" +f(a) # E: Argument 1 to "f" has incompatible type "List[int]"; expected "Listener" +g(b) # E: Argument 1 to "g" has incompatible type "Dict[str, int]"; expected "DictReader" [builtins fixtures/dict.pyi] From 3bba4bd3be22e08838cd0bd03ae7988dfaa4886a Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 24 Aug 2017 12:49:26 -0400 Subject: [PATCH 11/25] Remove message-specific quoting from protocol error messages As all types are now quoted, this fixes places that they would be double-quoted in the protocol error messages. --- mypy/messages.py | 4 ++-- test-data/unit/check-abstract.test | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 652479ec930e..bb568302fdb9 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1020,11 +1020,11 @@ def bad_proto_variance(self, actual: int, tvar_name: str, expected: int, self.fail(msg, context) def concrete_only_assign(self, typ: Type, context: Context) -> None: - self.fail("Can only assign concrete classes to a variable of type '{}'" + self.fail("Can only assign concrete classes to a variable of type {}" .format(self.format(typ)), context) def concrete_only_call(self, typ: Type, context: Context) -> None: - self.fail("Only concrete class can be given where '{}' is expected" + self.fail("Only concrete class can be given where {} is expected" .format(self.format(typ)), context) def note_call(self, subtype: Type, call: Type, context: Context) -> None: diff --git a/test-data/unit/check-abstract.test b/test-data/unit/check-abstract.test index af078612818b..6295f73d0ad5 100644 --- a/test-data/unit/check-abstract.test +++ b/test-data/unit/check-abstract.test @@ -200,7 +200,7 @@ Alias = A GoodAlias = C Alias() # E: Cannot instantiate abstract class 'A' with abstract attribute 'm' GoodAlias() -f(Alias) # E: Only concrete class can be given where 'Type[A]' is expected +f(Alias) # E: Only concrete class can be given where "Type[A]" is expected f(GoodAlias) [out] @@ -218,14 +218,14 @@ class C(B): var: Type[A] var() -var = A # E: Can only assign concrete classes to a variable of type 'Type[A]' -var = B # E: Can only assign concrete classes to a variable of type 'Type[A]' +var = A # E: Can only assign concrete classes to a variable of type "Type[A]" +var = B # E: Can only assign concrete classes to a variable of type "Type[A]" var = C # OK var_old = None # type: Type[A] # Old syntax for variable annotations var_old() -var_old = A # E: Can only assign concrete classes to a variable of type 'Type[A]' -var_old = B # E: Can only assign concrete classes to a variable of type 'Type[A]' +var_old = A # E: Can only assign concrete classes to a variable of type "Type[A]" +var_old = B # E: Can only assign concrete classes to a variable of type "Type[A]" var_old = C # OK [out] From e6e1701b2d621f0d626026c6cf55097a9438d118 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 25 Aug 2017 06:23:40 -0400 Subject: [PATCH 12/25] Quote Callable types in message output --- mypy/messages.py | 4 +- test-data/unit/check-classes.test | 16 ++--- test-data/unit/check-default-plugin.test | 2 +- test-data/unit/check-dynamic-typing.test | 28 ++++---- test-data/unit/check-expressions.test | 10 +-- test-data/unit/check-flags.test | 10 +-- test-data/unit/check-functions.test | 80 ++++++++++----------- test-data/unit/check-generics.test | 44 ++++++------ test-data/unit/check-inference-context.test | 12 ++-- test-data/unit/check-inference.test | 8 +-- test-data/unit/check-modules.test | 14 ++-- test-data/unit/check-namedtuple.test | 2 +- test-data/unit/check-protocols.test | 8 +-- test-data/unit/check-serialize.test | 2 +- test-data/unit/check-statements.test | 2 +- test-data/unit/check-typevar-values.test | 2 +- test-data/unit/check-varargs.test | 2 +- 17 files changed, 123 insertions(+), 123 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index bb568302fdb9..7562d44dd3fd 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -202,7 +202,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(func, CallableType): return_type = strip_quotes(self.format(func.ret_type)) if func.is_ellipsis_args: - return 'Callable[..., {}]'.format(return_type) + return '"Callable[..., {}]"'.format(return_type) arg_strings = [] for arg_name, arg_type, arg_kind in zip( func.arg_names, func.arg_types, func.arg_kinds): @@ -226,7 +226,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: strip_quotes(self.format(arg_type)), repr(arg_name))) - return 'Callable[[{}], {}]'.format(", ".join(arg_strings), return_type) + return '"Callable[[{}], {}]"'.format(", ".join(arg_strings), return_type) else: # Use a simple representation for function types; proper # function types may result in long and difficult-to-read diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 5dc432bcdb24..87fbd59fce46 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -504,8 +504,8 @@ class A: h = f # type: Callable[[A], None] h = f g = h - ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type Callable[[A], None], variable has type Callable[[B], None]) - g = ff # E: Incompatible types in assignment (expression has type Callable[[B], None], variable has type Callable[[A], None]) + ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[B], None]") + g = ff # E: Incompatible types in assignment (expression has type "Callable[[B], None]", variable has type "Callable[[A], None]") [out] @@ -2894,7 +2894,7 @@ class B(A): a = 1 def b(self) -> None: pass [out] -main:5: error: Incompatible types in assignment (expression has type "int", base class "A" defined the type as Callable[[A], None]) +main:5: error: Incompatible types in assignment (expression has type "int", base class "A" defined the type as "Callable[[A], None]") main:6: error: Signature of "b" incompatible with supertype "A" [case testVariableProperty] @@ -2934,7 +2934,7 @@ class C(B): def m(self, a: str) -> None: pass n = m [out] -main:5: error: Incompatible types in assignment (expression has type Callable[[str], None], base class "B" defined the type as Callable[[int], None]) +main:5: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]") [case testInstanceMethodOverwriteTypevar] from typing import Generic, TypeVar @@ -2978,7 +2978,7 @@ class C(B): n = m [builtins fixtures/classmethod.pyi] [out] -main:7: error: Incompatible types in assignment (expression has type Callable[[str], None], base class "B" defined the type as Callable[[int], None]) +main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]") [case testClassSpec] from typing import Callable @@ -2996,7 +2996,7 @@ class B(A): def c(self, a: str) -> int: pass b = c [out] -main:6: error: Incompatible types in assignment (expression has type Callable[[str], int], base class "A" defined the type as Callable[[int], int]) +main:6: error: Incompatible types in assignment (expression has type "Callable[[str], int]", base class "A" defined the type as "Callable[[int], int]") [case testClassStaticMethod] class A(): @@ -3008,7 +3008,7 @@ class B(A): a = b [builtins fixtures/staticmethod.pyi] [out] -main:7: error: Incompatible types in assignment (expression has type Callable[[str], None], base class "A" defined the type as Callable[[int], None]) +main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]") [case testClassStaticMethodIndirect] class A(): @@ -3021,7 +3021,7 @@ class B(A): c = b [builtins fixtures/staticmethod.pyi] [out] -main:8: error: Incompatible types in assignment (expression has type Callable[[str], None], base class "A" defined the type as Callable[[int], None]) +main:8: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]") [case testClassStaticMethodSubclassing] class A: diff --git a/test-data/unit/check-default-plugin.test b/test-data/unit/check-default-plugin.test index c6a5677159e2..1aae55ff46eb 100644 --- a/test-data/unit/check-default-plugin.test +++ b/test-data/unit/check-default-plugin.test @@ -20,7 +20,7 @@ with yield_id(1) as x: f = yield_id def g(x, y): pass -f = g # E: Incompatible types in assignment (expression has type Callable[[Any, Any], Any], variable has type Callable[[T], GeneratorContextManager[T]]) +f = g # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[T], GeneratorContextManager[T]]") [typing fixtures/typing-full.pyi] [case testContextManagerWithUnspecifiedArguments] diff --git a/test-data/unit/check-dynamic-typing.test b/test-data/unit/check-dynamic-typing.test index 22626cfffd88..fce9692cc326 100644 --- a/test-data/unit/check-dynamic-typing.test +++ b/test-data/unit/check-dynamic-typing.test @@ -302,7 +302,7 @@ h = None # type: Callable[[A], None] f() # E: Too few arguments for "f" f(x, x) # E: Too many arguments for "f" -g = f # E: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type Callable[[], None]) +g = f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") f(a) f(x) a = f(a) @@ -319,10 +319,10 @@ g1 = None # type: Callable[[A], None] g2 = None # type: Callable[[A, A], None] a = None # type: A -g1 = f0 # E: Incompatible types in assignment (expression has type Callable[[], Any], variable has type Callable[[A], None]) -g2 = f0 # E: Incompatible types in assignment (expression has type Callable[[], Any], variable has type Callable[[A, A], None]) -g0 = f2 # E: Incompatible types in assignment (expression has type Callable[[Any, Any], Any], variable has type Callable[[], None]) -g1 = f2 # E: Incompatible types in assignment (expression has type Callable[[Any, Any], Any], variable has type Callable[[A], None]) +g1 = f0 # E: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "Callable[[A], None]") +g2 = f0 # E: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "Callable[[A, A], None]") +g0 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[], None]") +g1 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[A], None]") g0 = g0 g2 = f2 @@ -373,9 +373,9 @@ class B: pass main:10: error: Too many arguments for "f01" main:11: error: Too few arguments for "f13" main:12: error: Too many arguments for "f13" -main:13: error: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type Callable[[A, A], None]) -main:14: error: Incompatible types in assignment (expression has type Callable[[Any, Any, Any], Any], variable has type Callable[[], None]) -main:15: error: Incompatible types in assignment (expression has type Callable[[Any, Any, Any], Any], variable has type Callable[[A, A, A, A], None]) +main:13: error: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[A, A], None]") +main:14: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, Any], Any]", variable has type "Callable[[], None]") +main:15: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, Any], Any]", variable has type "Callable[[A, A, A, A], None]") [case testSkipTypeCheckingWithImplicitSignature] @@ -407,9 +407,9 @@ g1 = None # type: Callable[[A], None] g2 = None # type: Callable[[A, A], None] a = None # type: A -g0 = a.f # E: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type Callable[[], None]) -g2 = a.f # E: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type Callable[[A, A], None]) -a = a.f # E: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type "A") +g0 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") +g2 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[A, A], None]") +a = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "A") class A: def g(self) -> None: @@ -434,7 +434,7 @@ g0 = None # type: Callable[[], None] g1 = None # type: Callable[[A], None] a = None # type: A -g0 = a.f # E: Incompatible types in assignment (expression has type Callable[[Any], Any], variable has type Callable[[], None]) +g0 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") g1 = a.f a = a.f(a) @@ -485,7 +485,7 @@ class A: def __init__(self, a, b): pass [out] main:6: error: Too few arguments for "A" -main:7: error: Incompatible types in assignment (expression has type "Type[A]", variable has type Callable[[A], A]) +main:7: error: Incompatible types in assignment (expression has type "Type[A]", variable has type "Callable[[A], A]") [case testUsingImplicitTypeObjectWithIs] @@ -571,7 +571,7 @@ from typing import Any, Callable f1 = None # type: Callable[[Any], None] f2 = None # type: Callable[[Any, Any], None] -f1 = f2 # E: Incompatible types in assignment (expression has type Callable[[Any, Any], None], variable has type Callable[[Any], None]) +f1 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], None]", variable has type "Callable[[Any], None]") -- Overriding diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index b401edf0b4ea..ca6ed6680ed5 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1199,7 +1199,7 @@ f = lambda: ''.x f = lambda: '' [out] main:3: error: "str" has no attribute "x" -main:4: error: Incompatible types in assignment (expression has type Callable[[], str], variable has type Callable[[], int]) +main:4: error: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "Callable[[], int]") main:4: error: Incompatible return value type (got "str", expected "int") [case testVoidLambda] @@ -1359,7 +1359,7 @@ from typing import Callable, Iterator, List a = [] # type: List[Callable[[], str]] b = None # type: Iterator[Callable[[], int]] -b = (x for x in a) # E: Generator has incompatible item type Callable[[], str]; expected Callable[[], int] +b = (x for x in a) # E: Generator has incompatible item type "Callable[[], str]"; expected "Callable[[], int]" [builtins fixtures/list.pyi] -- Conditional expressions @@ -1416,8 +1416,8 @@ def f() -> None: pass [out] main:5: error: Unsupported left operand type for + ("None") -main:6: error: Unsupported left operand type for + (Callable[[], None]) -main:7: error: Unsupported operand types for + ("A" and Callable[[], None]) +main:6: error: Unsupported left operand type for + ("Callable[[], None]") +main:7: error: Unsupported operand types for + ("A" and "Callable[[], None]") [case testOperatorMethodWithInvalidArgCount] @@ -1733,7 +1733,7 @@ from typing import Dict, Callable def things() -> int: return 42 -stuff: Dict[int, Callable[[], str]] = { # E: Dict entry 0 has incompatible type "int": Callable[[], int]; expected "int": Callable[[], str] +stuff: Dict[int, Callable[[], str]] = { # E: Dict entry 0 has incompatible type "int": "Callable[[], int]"; expected "int": "Callable[[], str]" 1: things } [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 9b1afdadf7f7..d5e329425b14 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -683,7 +683,7 @@ def foo(f: Callable[[], Unchecked]) -> Tuple[Unchecked]: [builtins fixtures/list.pyi] [out] main:5: error: Return type becomes "Tuple[Any]" due to an unfollowed import -main:5: error: Argument 1 to "foo" becomes Callable[[], Any] due to an unfollowed import +main:5: error: Argument 1 to "foo" becomes "Callable[[], Any]" due to an unfollowed import [case testDisallowImplicitAnySubclassingExplicitAny] # flags: --ignore-missing-imports --disallow-any=unimported --disallow-subclassing-any @@ -770,7 +770,7 @@ def d(f) -> Callable[..., None]: return f @d -def g(i: int, s: str) -> None: pass # E: Type of decorated function contains type "Any" (Callable[..., None]) +def g(i: int, s: str) -> None: pass # E: Type of decorated function contains type "Any" ("Callable[..., None]") [builtins fixtures/list.pyi] [case testDisallowAnyDecoratedNonexistentDecorator] @@ -790,13 +790,13 @@ def d2(f) -> Callable[[int], List[Any]]: pass def d3(f) -> Callable[[Any], List[str]]: pass @d -def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" (Callable[[int, Any], Any]) +def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" ("Callable[[int, Any], Any]") pass @d2 -def g(i: int) -> None: # E: Type of decorated function contains type "Any" (Callable[[int], List[Any]]) +def g(i: int) -> None: # E: Type of decorated function contains type "Any" ("Callable[[int], List[Any]]") pass @d3 -def h(i: int) -> None: # E: Type of decorated function contains type "Any" (Callable[[Any], List[str]]) +def h(i: int) -> None: # E: Type of decorated function contains type "Any" ("Callable[[Any], List[str]]") pass [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 748e50f8ce19..ff10daab6169 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -65,10 +65,10 @@ class B(A): pass f = None # type: Callable[[B], A] g = None # type: Callable[[A], A] # subtype of f h = None # type: Callable[[B], B] # subtype of f -g = h # E: Incompatible types in assignment (expression has type Callable[[B], B], variable has type Callable[[A], A]) -h = f # E: Incompatible types in assignment (expression has type Callable[[B], A], variable has type Callable[[B], B]) -h = g # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[B], B]) -g = f # E: Incompatible types in assignment (expression has type Callable[[B], A], variable has type Callable[[A], A]) +g = h # E: Incompatible types in assignment (expression has type "Callable[[B], B]", variable has type "Callable[[A], A]") +h = f # E: Incompatible types in assignment (expression has type "Callable[[B], A]", variable has type "Callable[[B], B]") +h = g # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[B], B]") +g = f # E: Incompatible types in assignment (expression has type "Callable[[B], A]", variable has type "Callable[[A], A]") f = g f = h f = f @@ -79,13 +79,13 @@ h = h def l(x) -> None: ... def r(__, *, x) -> None: ... -r = l # E: Incompatible types in assignment (expression has type Callable[[Any], None], variable has type Callable[[Any, NamedArg(Any, 'x')], None]) +r = l # E: Incompatible types in assignment (expression has type "Callable[[Any], None]", variable has type "Callable[[Any, NamedArg(Any, 'x')], None]") [case testSubtypingFunctionsRequiredLeftArgNotPresent] def l(x, y) -> None: ... def r(x) -> None: ... -r = l # E: Incompatible types in assignment (expression has type Callable[[Any, Any], None], variable has type Callable[[Any], None]) +r = l # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], None]", variable has type "Callable[[Any], None]") [case testSubtypingFunctionsImplicitNames] from typing import Any @@ -115,10 +115,10 @@ hh = h ff = gg ff_nonames = ff ff_nonames = f_nonames # reset -ff = ff_nonames # E: Incompatible types in assignment (expression has type Callable[[int, str], None], variable has type Callable[[Arg(int, 'a'), Arg(str, 'b')], None]) +ff = ff_nonames # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") ff = f # reset -gg = ff # E: Incompatible types in assignment (expression has type Callable[[Arg(int, 'a'), Arg(str, 'b')], None], variable has type Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]) -gg = hh # E: Incompatible types in assignment (expression has type Callable[[Arg(int, 'aa'), DefaultArg(str, 'b')], None], variable has type Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]) +gg = ff # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]", variable has type "Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]") +gg = hh # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'aa'), DefaultArg(str, 'b')], None]", variable has type "Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]") [case testSubtypingFunctionsArgsKwargs] from typing import Any, Callable @@ -144,7 +144,7 @@ ee_var = everything ee_var = everywhere ee_var = specific_1 # The difference between Callable[..., blah] and one with a *args: Any, **kwargs: Any is that the ... goes loosely both ways. -ee_def = specific_1 # E: Incompatible types in assignment (expression has type Callable[[int, str], None], variable has type Callable[[VarArg(Any), KwArg(Any)], None]) +ee_def = specific_1 # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[VarArg(Any), KwArg(Any)], None]") [builtins fixtures/dict.pyi] @@ -175,7 +175,7 @@ ff = f gg = g ff = g -gg = f # E: Incompatible types in assignment (expression has type Callable[[int, str], None], variable has type Callable[[Arg(int, 'a'), Arg(str, 'b')], None]) +gg = f # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") [case testLackOfNamesFastparse] @@ -187,15 +187,15 @@ ff = f gg = g ff = g -gg = f # E: Incompatible types in assignment (expression has type Callable[[int, str], None], variable has type Callable[[Arg(int, 'a'), Arg(str, 'b')], None]) +gg = f # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") [case testFunctionTypeCompatibilityWithOtherTypes] from typing import Callable f = None # type: Callable[[], None] a, o = None, None # type: (A, object) -a = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type "A") -f = a # E: Incompatible types in assignment (expression has type "A", variable has type Callable[[], None]) -f = o # E: Incompatible types in assignment (expression has type "object", variable has type Callable[[], None]) +a = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "A") +f = a # E: Incompatible types in assignment (expression has type "A", variable has type "Callable[[], None]") +f = o # E: Incompatible types in assignment (expression has type "object", variable has type "Callable[[], None]") f = f() # E: Function does not return a value f = f @@ -208,7 +208,7 @@ class A: pass from typing import Callable f = None # type: Callable[[], None] g = None # type: Callable[[], object] -f = g # E: Incompatible types in assignment (expression has type Callable[[], object], variable has type Callable[[], None]) +f = g # E: Incompatible types in assignment (expression has type "Callable[[], object]", variable has type "Callable[[], None]") g = f # OK f = f @@ -219,9 +219,9 @@ from typing import Callable f = None # type: Callable[[A, A], None] g = None # type: Callable[[A, B], None] h = None # type: Callable[[B, B], None] -f = g # E: Incompatible types in assignment (expression has type Callable[[A, B], None], variable has type Callable[[A, A], None]) -f = h # E: Incompatible types in assignment (expression has type Callable[[B, B], None], variable has type Callable[[A, A], None]) -g = h # E: Incompatible types in assignment (expression has type Callable[[B, B], None], variable has type Callable[[A, B], None]) +f = g # E: Incompatible types in assignment (expression has type "Callable[[A, B], None]", variable has type "Callable[[A, A], None]") +f = h # E: Incompatible types in assignment (expression has type "Callable[[B, B], None]", variable has type "Callable[[A, A], None]") +g = h # E: Incompatible types in assignment (expression has type "Callable[[B, B], None]", variable has type "Callable[[A, B], None]") g = f h = f h = g @@ -238,10 +238,10 @@ f = None # type: Callable[[], None] g = None # type: Callable[[A], None] h = None # type: Callable[[A, A], None] -f = g # E: Incompatible types in assignment (expression has type Callable[[A], None], variable has type Callable[[], None]) -f = h # E: Incompatible types in assignment (expression has type Callable[[A, A], None], variable has type Callable[[], None]) -h = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type Callable[[A, A], None]) -h = g # E: Incompatible types in assignment (expression has type Callable[[A], None], variable has type Callable[[A, A], None]) +f = g # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[], None]") +f = h # E: Incompatible types in assignment (expression has type "Callable[[A, A], None]", variable has type "Callable[[], None]") +h = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "Callable[[A, A], None]") +h = g # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[A, A], None]") f = f g = g @@ -256,7 +256,7 @@ t = None # type: type a = None # type: A a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") -t = f # E: Incompatible types in assignment (expression has type Callable[[], None], variable has type "type") +t = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "type") t = A class A: @@ -272,7 +272,7 @@ f = None # type: Callable[[AA], A] g = None # type: Callable[[B], B] h = None # type: Callable[[A], AA] -h = i # E: Incompatible types in assignment (expression has type overloaded function, variable has type Callable[[A], AA]) +h = i # E: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[A], AA]") f = j f = i @@ -311,7 +311,7 @@ a, b, c = None, None, None # type: (A, B, C) b = f(a) # E: Incompatible types in assignment (expression has type "A", variable has type "B") a = f(b) # E: Incompatible types in assignment (expression has type "B", variable has type "A") b = f(c) # E: Incompatible types in assignment (expression has type "C", variable has type "B") -g4 = f # E: Incompatible types in assignment (expression has type overloaded function, variable has type Callable[[A], B]) +g4 = f # E: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[A], B]") g1 = f g2 = f @@ -353,7 +353,7 @@ from typing import Callable, Type class A: pass x = None # type: Callable[..., A] y = None # type: Type[A] -y = x # E: Incompatible types in assignment (expression has type Callable[..., A], variable has type "Type[A]") +y = x # E: Incompatible types in assignment (expression has type "Callable[..., A]", variable has type "Type[A]") -- Default argument values -- ----------------------- @@ -676,8 +676,8 @@ def f() -> None: g(1) g.x # E [out] -main:7: error: Callable[..., Any] has no attribute "x" -main:11: error: Callable[..., Any] has no attribute "x" +main:7: error: "Callable[..., Any]" has no attribute "x" +main:11: error: "Callable[..., Any]" has no attribute "x" [case testNestedGenericFunctions] from typing import TypeVar @@ -785,7 +785,7 @@ f(None) # E: Too many arguments for "f" from typing import Any, Callable def dec1(f: Callable[[Any], None]) -> Callable[[], None]: pass def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass -@dec1 # E: Argument 1 to "dec2" has incompatible type Callable[[Any], Any]; expected Callable[[Any, Any], None] +@dec1 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]" @dec2 def f(x): pass @@ -793,7 +793,7 @@ def f(x): pass from typing import Any, Callable def dec1(f: Callable[[Any, Any], None]) -> Callable[[], None]: pass def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass -@dec1 # E: Argument 1 to "dec1" has incompatible type Callable[[Any], None]; expected Callable[[Any, Any], None] +@dec1 # E: Argument 1 to "dec1" has incompatible type "Callable[[Any], None]"; expected "Callable[[Any, Any], None]" @dec2 def f(x, y): pass @@ -1322,7 +1322,7 @@ def g() -> None: def g(): pass f = g if g(): - def f(x): pass # E: Incompatible redefinition (redefinition with type Callable[[Any], Any], original type Callable[[], Any]) + def f(x): pass # E: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "Callable[[], Any]") [case testRedefineFunctionDefinedAsVariableWithVariance1] class B: pass @@ -1560,7 +1560,7 @@ def f2(*args, **kwargs) -> int: pass d(f1) e(f2) d(f2) -e(f1) # E: Argument 1 to "e" has incompatible type Callable[[VarArg(Any)], int]; expected Callable[[VarArg(Any), KwArg(Any)], int] +e(f1) # E: Argument 1 to "e" has incompatible type "Callable[[VarArg(Any)], int]"; expected "Callable[[VarArg(Any), KwArg(Any)], int]" [builtins fixtures/dict.pyi] @@ -1681,12 +1681,12 @@ def isf_unnamed(__i: int, __s: str) -> str: int_str_fun = isf int_str_fun = isf_unnamed -int_named_str_fun = isf_unnamed # E: Incompatible types in assignment (expression has type Callable[[int, str], str], variable has type Callable[[int, Arg(str, 's')], str]) +int_named_str_fun = isf_unnamed # E: Incompatible types in assignment (expression has type "Callable[[int, str], str]", variable has type "Callable[[int, Arg(str, 's')], str]") int_opt_str_fun = iosf int_str_fun = iosf -int_opt_str_fun = isf # E: Incompatible types in assignment (expression has type Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str], variable has type Callable[[int, DefaultArg(str)], str]) +int_opt_str_fun = isf # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str]", variable has type "Callable[[int, DefaultArg(str)], str]") -int_named_str_fun = isf # E: Incompatible types in assignment (expression has type Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str], variable has type Callable[[int, Arg(str, 's')], str]) +int_named_str_fun = isf # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str]", variable has type "Callable[[int, Arg(str, 's')], str]") int_named_str_fun = iosf [builtins fixtures/dict.pyi] @@ -1718,7 +1718,7 @@ f(x=4) + '' # E: Unsupported operand types for + ("int" and "str") [case testCallableWithArbitraryArgsInErrorMessage] from typing import Callable def f(x: Callable[..., int]) -> None: - x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Callable[..., int]) + x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[..., int]") [out] [case testCallableWithArbitraryArgsInGenericFunction] @@ -1740,7 +1740,7 @@ def g4(*, y: int) -> str: pass f(g1) f(g2) f(g3) -f(g4) # E: Argument 1 to "f" has incompatible type Callable[[NamedArg(int, 'y')], str]; expected Callable[..., int] +f(g4) # E: Argument 1 to "f" has incompatible type "Callable[[NamedArg(int, 'y')], str]"; expected "Callable[..., int]" [case testCallableWithArbitraryArgsSubtypingWithGenericFunc] from typing import Callable, TypeVar @@ -1869,8 +1869,8 @@ def g(x, y): pass def h(x): pass def j(y) -> Any: pass f = h -f = j # E: Incompatible types in assignment (expression has type Callable[[Arg(Any, 'y')], Any], variable has type Callable[[Arg(Any, 'x')], Any]) -f = g # E: Incompatible types in assignment (expression has type Callable[[Any, Any], Any], variable has type Callable[[Any], Any]) +f = j # E: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'y')], Any]", variable has type "Callable[[Arg(Any, 'x')], Any]") +f = g # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[Any], Any]") [case testRedefineFunction2] def f() -> None: pass diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 21381d4238e9..6e8fcd43e6e4 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -825,9 +825,9 @@ reveal_type(make_cb(1)) # E: Revealed type is 'def (*Any, **Any) -> builtins.int def use_cb(arg: T, cb: C2[T]) -> Node[T]: return cb(arg, arg) -use_cb(1, 1) # E: Argument 2 to "use_cb" has incompatible type "int"; expected Callable[[int, int], Node[int]] +use_cb(1, 1) # E: Argument 2 to "use_cb" has incompatible type "int"; expected "Callable[[int, int], Node[int]]" my_cb = None # type: C2[int] -use_cb('x', my_cb) # E: Argument 2 to "use_cb" has incompatible type Callable[[int, int], Node[int]]; expected Callable[[str, str], Node[str]] +use_cb('x', my_cb) # E: Argument 2 to "use_cb" has incompatible type "Callable[[int, int], Node[int]]"; expected "Callable[[str, str], Node[str]]" reveal_type(use_cb(1, my_cb)) # E: Revealed type is '__main__.Node[builtins.int]' [out] @@ -1499,25 +1499,25 @@ y1 = f1 y1 = f1 y1 = f2 y1 = f3 -y1 = f4 # E: Incompatible types in assignment (expression has type Callable[[int], A], variable has type Callable[[A], A]) +y1 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A]", variable has type "Callable[[A], A]") y2 = f2 y2 = f2 -y2 = f1 # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[A], B]) -y2 = f3 # E: Incompatible types in assignment (expression has type Callable[[B], B], variable has type Callable[[A], B]) -y2 = f4 # E: Incompatible types in assignment (expression has type Callable[[int], A], variable has type Callable[[A], B]) +y2 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[A], B]") +y2 = f3 # E: Incompatible types in assignment (expression has type "Callable[[B], B]", variable has type "Callable[[A], B]") +y2 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A]", variable has type "Callable[[A], B]") y3 = f3 y3 = f3 y3 = f1 y3 = f2 -y3 = f4 # E: Incompatible types in assignment (expression has type Callable[[int], A], variable has type Callable[[B], B]) +y3 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A]", variable has type "Callable[[B], B]") y4 = f4 y4 = f4 -y4 = f1 # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[int], A]) +y4 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[int], A]") y4 = f2 -y4 = f3 # E: Incompatible types in assignment (expression has type Callable[[B], B], variable has type Callable[[int], A]) +y4 = f3 # E: Incompatible types in assignment (expression has type "Callable[[B], B]", variable has type "Callable[[int], A]") [case testSubtypingWithGenericInnerFunctions] from typing import TypeVar @@ -1533,24 +1533,24 @@ def outer(t: T) -> None: y1 = f1 y1 = f2 - y1 = f3 # E: Incompatible types in assignment (expression has type Callable[[T], A], variable has type Callable[[A], A]) - y1 = f4 # E: Incompatible types in assignment (expression has type Callable[[A], T], variable has type Callable[[A], A]) - y1 = f5 # E: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[A], A]) + y1 = f3 # E: Incompatible types in assignment (expression has type "Callable[[T], A]", variable has type "Callable[[A], A]") + y1 = f4 # E: Incompatible types in assignment (expression has type "Callable[[A], T]", variable has type "Callable[[A], A]") + y1 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[A], A]") y2 = f2 - y2 = f1 # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[A], B]) + y2 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[A], B]") y3 = f3 - y3 = f1 # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[T], A]) + y3 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[T], A]") y3 = f2 - y3 = f4 # E: Incompatible types in assignment (expression has type Callable[[A], T], variable has type Callable[[T], A]) - y3 = f5 # E: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[T], A]) + y3 = f4 # E: Incompatible types in assignment (expression has type "Callable[[A], T]", variable has type "Callable[[T], A]") + y3 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], A]") y4 = f4 - y4 = f1 # E: Incompatible types in assignment (expression has type Callable[[A], A], variable has type Callable[[A], T]) + y4 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[A], T]") y4 = f2 - y4 = f3 # E: Incompatible types in assignment (expression has type Callable[[T], A], variable has type Callable[[A], T]) - y4 = f5 # E: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[A], T]) + y4 = f3 # E: Incompatible types in assignment (expression has type "Callable[[T], A]", variable has type "Callable[[A], T]") + y4 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[A], T]") y5 = f5 y5 = f1 @@ -1568,8 +1568,8 @@ g1(f) def g2(f: Callable[[int], int]) -> None: pass g2(f) def g3(f: Callable[[object], object]) -> None: pass -g3(f) # E: Argument 1 to "g3" has incompatible type Callable[[T], T]; \ - expected Callable[[object], object] +g3(f) # E: Argument 1 to "g3" has incompatible type "Callable[[T], T]"; \ + expected "Callable[[object], object]" [case testSubtypingWithGenericFunctionUsingTypevarWithValues2-skip] from typing import TypeVar, Callable @@ -1626,7 +1626,7 @@ T = TypeVar('T') class C(Generic[T]): def __init__(self) -> None: pass x = C # type: Callable[[], C[int]] -y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type Callable[[], int]) +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Callable[[], int]") -- Special cases diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 1cb669d6d091..541b0dc43a08 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -610,9 +610,9 @@ f = lambda x: A() # type: Callable[[], A] f2 = lambda: A() # type: Callable[[A], A] class A: pass [out] -main:2: error: Incompatible types in assignment (expression has type Callable[[Any], A], variable has type Callable[[], A]) +main:2: error: Incompatible types in assignment (expression has type "Callable[[Any], A]", variable has type "Callable[[], A]") main:2: error: Cannot infer type of lambda -main:3: error: Incompatible types in assignment (expression has type Callable[[], A], variable has type Callable[[A], A]) +main:3: error: Incompatible types in assignment (expression has type "Callable[[], A]", variable has type "Callable[[A], A]") main:3: error: Cannot infer type of lambda [case testEllipsisContextForLambda] @@ -624,7 +624,7 @@ f4 = lambda x: x # type: Callable[..., int] g = lambda x: 1 # type: Callable[..., str] [builtins fixtures/dict.pyi] [out] -main:6: error: Incompatible types in assignment (expression has type Callable[[Any], int], variable has type Callable[..., str]) +main:6: error: Incompatible types in assignment (expression has type "Callable[[Any], int]", variable has type "Callable[..., str]") main:6: error: Incompatible return value type (got "int", expected "str") [case testEllipsisContextForLambda2] @@ -651,7 +651,7 @@ def f(func: Callable[[T], S], *z: T, r: S = None) -> S: pass f(lambda x: 0 if isinstance(x, B) else 1) # E: Cannot infer type argument 1 of "f" f(lambda x: 0 if isinstance(x, B) else 1, A())() # E: "int" not callable f(lambda x: x if isinstance(x, B) else B(), A(), r=B())() # E: "B" not callable -f( # E: Argument 1 to "f" has incompatible type Callable[[A], A]; expected Callable[[A], B] +f( # E: Argument 1 to "f" has incompatible type "Callable[[A], A]"; expected "Callable[[A], B]" lambda x: B() if isinstance(x, B) else x, # E: Incompatible return value type (got "A", expected "B") A(), r=B()) [builtins fixtures/isinstance.pyi] @@ -825,7 +825,7 @@ S = TypeVar('S') def f(a: T, b: S) -> None: c = lambda x: x # type: Callable[[T], S] [out] -main:5: error: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[T], S]) +main:5: error: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], S]") main:5: error: Incompatible return value type (got "T", expected "S") [case testLambdaInGenericClass] @@ -836,7 +836,7 @@ class A(Generic[T]): def f(self, b: S) -> None: c = lambda x: x # type: Callable[[T], S] [out] -main:6: error: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[T], S]) +main:6: error: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], S]") main:6: error: Incompatible return value type (got "T", expected "S") [case testRevealTypeContext] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 76d0913bb47b..9fa918782b2a 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -792,7 +792,7 @@ def k1(x: int, y: List[T]) -> List[Union[T, int]]: pass def k2(x: S, y: List[T]) -> List[Union[T, int]]: pass a = k2 a = k2 -a = k1 # E: Incompatible types in assignment (expression has type Callable[[int, List[T]], List[Union[T, int]]], variable has type Callable[[S, List[T]], List[Union[T, int]]]) +a = k1 # E: Incompatible types in assignment (expression has type "Callable[[int, List[T]], List[Union[T, int]]]", variable has type "Callable[[S, List[T]], List[Union[T, int]]]") b = k1 b = k1 b = k2 @@ -1074,14 +1074,14 @@ from typing import List, Callable li = [1] l = lambda: li f1 = l # type: Callable[[], List[int]] -f2 = l # type: Callable[[], List[str]] # E: Incompatible types in assignment (expression has type Callable[[], List[int]], variable has type Callable[[], List[str]]) +f2 = l # type: Callable[[], List[str]] # E: Incompatible types in assignment (expression has type "Callable[[], List[int]]", variable has type "Callable[[], List[str]]") [builtins fixtures/list.pyi] [case testInferLambdaType2] from typing import List, Callable l = lambda: [B()] f1 = l # type: Callable[[], List[B]] -f2 = l # type: Callable[[], List[A]] # E: Incompatible types in assignment (expression has type Callable[[], List[B]], variable has type Callable[[], List[A]]) +f2 = l # type: Callable[[], List[A]] # E: Incompatible types in assignment (expression has type "Callable[[], List[B]]", variable has type "Callable[[], List[A]]") class A: pass class B: pass @@ -1119,7 +1119,7 @@ from typing import Callable def f(a: Callable[..., None] = lambda *a, **k: None): pass -def g(a: Callable[..., None] = lambda *a, **k: 1): # E: Incompatible default for argument "a" (default has type Callable[[VarArg(Any), KwArg(Any)], int], argument has type Callable[..., None]) +def g(a: Callable[..., None] = lambda *a, **k: 1): # E: Incompatible default for argument "a" (default has type "Callable[[VarArg(Any), KwArg(Any)], int]", argument has type "Callable[..., None]") pass [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 43a396746d78..f3104c6f2715 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -584,7 +584,7 @@ x = '' def f(x): pass def g(x): pass try: - from m import f, g # E: Incompatible import of "g" (imported name has type Callable[[Any, Any], Any], local name has type Callable[[Any], Any]) + from m import f, g # E: Incompatible import of "g" (imported name has type "Callable[[Any, Any], Any]", local name has type "Callable[[Any], Any]") except: pass [file m.py] @@ -620,7 +620,7 @@ def f(x): pass try: from m import f except: - f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Callable[[], Any]) + f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") [file m.py] def f(): pass @@ -630,7 +630,7 @@ from m import f def g() -> None: global f f = None - f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Callable[[], Any]) + f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") [file m.py] def f(): pass [out] @@ -638,7 +638,7 @@ def f(): pass [case testAssignToFuncDefViaNestedModules] import m.n m.n.f = None -m.n.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Callable[[], Any]) +m.n.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") [file m/__init__.py] [file m/n.py] def f(): pass @@ -647,7 +647,7 @@ def f(): pass [case testAssignToFuncDefViaModule] import m m.f = None -m.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type Callable[[], Any]) +m.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") [file m.py] def f(): pass [out] @@ -933,7 +933,7 @@ def y() -> str: return "foo" class z: pass [out] main:2: error: Incompatible import of "x" (imported name has type "str", local name has type "int") -main:2: error: Incompatible import of "y" (imported name has type Callable[[], str], local name has type Callable[[], int]) +main:2: error: Incompatible import of "y" (imported name has type "Callable[[], str]", local name has type "Callable[[], int]") main:2: error: Incompatible import of "z" (imported name has type "Type[b.z]", local name has type "Type[a.z]") -- Misc @@ -1937,4 +1937,4 @@ main:2: error: Revealed type is 'Any' main:2: error: Name 'name' is not defined main:3: error: Revealed type is 'Any' -[builtins fixtures/module.pyi] \ No newline at end of file +[builtins fixtures/module.pyi] diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 36e46681b061..f68279eef913 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -415,7 +415,7 @@ b = B._make(['']) # type: B [case testNamedTupleIncompatibleRedefinition] from typing import NamedTuple class Crash(NamedTuple): - count: int # E: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as Callable[[Tuple[Any, ...], Any], int]) + count: int # E: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[Tuple[Any, ...], Any], int]") [builtins fixtures/tuple.pyi] [case testNamedTupleInClassNamespace] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index b6adfedaab9c..05e9ab9a11e3 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -211,7 +211,7 @@ class C: pass x: P = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P") \ # N: Following member(s) of "C" have conflicts: \ - # N: meth: expected "int", got Callable[[], int] + # N: meth: expected "int", got "Callable[[], int]" [builtins fixtures/property.pyi] [case testCannotAssignNormalToProtocol] @@ -272,7 +272,7 @@ class MyHashable(Protocol): class C(MyHashable): __my_hash__ = None # E: Incompatible types in assignment \ -(expression has type "None", base class "MyHashable" defined the type as Callable[[MyHashable], int]) +(expression has type "None", base class "MyHashable" defined the type as "Callable[[MyHashable], int]") [case testProtocolsWithNoneAndStrictOptional] # flags: --strict-optional @@ -1680,9 +1680,9 @@ class Bad1: class Bad2: def __call__(self, y: int, *rest: str) -> int: pass call_soon(Good()) -call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected Callable[[int, VarArg(str)], int] \ +call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "Callable[[int, VarArg(str)], int]" \ # N: 'Bad1.__call__' has type 'Callable[[Arg(int, 'x'), VarArg(int)], int]' -call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected Callable[[int, VarArg(str)], int] \ +call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "Callable[[int, VarArg(str)], int]" \ # N: 'Bad2.__call__' has type 'Callable[[Arg(int, 'y'), VarArg(str)], int]' [builtins fixtures/isinstancelist.pyi] diff --git a/test-data/unit/check-serialize.test b/test-data/unit/check-serialize.test index 2996b8b6dadb..0c01b750c41d 100644 --- a/test-data/unit/check-serialize.test +++ b/test-data/unit/check-serialize.test @@ -662,7 +662,7 @@ class A: pass def f() -> None: pass [builtins fixtures/tuple.pyi] [out2] -tmp/a.py:4: error: Incompatible types in assignment (expression has type Callable[[], None], variable has type "type") +tmp/a.py:4: error: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "type") [case testSerializeOverloadedVsTypeObjectDistinction] import a diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 68dfdf961df6..687e8f6e591e 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -594,7 +594,7 @@ else: def f3() -> None: pass [builtins fixtures/exception.pyi] [out] -main:7: error: Incompatible redefinition (redefinition with type Callable[[], str], original type Callable[[], None]) +main:7: error: Incompatible redefinition (redefinition with type "Callable[[], str]", original type "Callable[[], None]") [case testExceptWithoutType] import typing diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 3e0f462ae70f..1dc5d143790e 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -524,7 +524,7 @@ a = f a = g b = g b = g -b = f # E: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[U], U]) +b = f # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[U], U]") [case testInnerFunctionWithTypevarValues] from typing import TypeVar diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 0450981e4f5f..4f5491903af6 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -577,7 +577,7 @@ x = None # type: Callable[[int], None] def f(*x: int) -> None: pass def g(*x: str) -> None: pass x = f -x = g # E: Incompatible types in assignment (expression has type Callable[[VarArg(str)], None], variable has type Callable[[int], None]) +x = g # E: Incompatible types in assignment (expression has type "Callable[[VarArg(str)], None]", variable has type "Callable[[int], None]") [builtins fixtures/list.pyi] [out] From d884e03f2ffefdbd6b7fade61f6067a6978ea21e Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 25 Aug 2017 11:27:53 +0100 Subject: [PATCH 13/25] Update MessageBuilder.note_call to remove double-quoting of types --- mypy/messages.py | 4 ++-- test-data/unit/check-protocols.test | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 7562d44dd3fd..55afe4868413 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1028,8 +1028,8 @@ def concrete_only_call(self, typ: Type, context: Context) -> None: .format(self.format(typ)), context) def note_call(self, subtype: Type, call: Type, context: Context) -> None: - self.note("'{}.__call__' has type '{}'".format(strip_quotes(self.format(subtype)), - self.format(call, verbosity=1)), context) + self.note("'{}.__call__' has type {}".format(strip_quotes(self.format(subtype)), + self.format(call, verbosity=1)), context) def report_protocol_problems(self, subtype: Union[Instance, TupleType, TypedDictType], supertype: Instance, context: Context) -> None: diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 05e9ab9a11e3..f8c10b49d7e8 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -1664,7 +1664,7 @@ reveal_type(apply_gen(Add5())) # E: Revealed type is 'builtins.int*' def apply_str(f: Callable[[str], int], x: str) -> int: return f(x) apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "Callable[[str], int]" \ - # N: 'Add5.__call__' has type 'Callable[[Arg(int, 'x')], int]' + # N: 'Add5.__call__' has type "Callable[[Arg(int, 'x')], int]" [builtins fixtures/isinstancelist.pyi] [case testMoreComplexCallableStructuralSubtyping] @@ -1681,9 +1681,9 @@ class Bad2: def __call__(self, y: int, *rest: str) -> int: pass call_soon(Good()) call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "Callable[[int, VarArg(str)], int]" \ - # N: 'Bad1.__call__' has type 'Callable[[Arg(int, 'x'), VarArg(int)], int]' + # N: 'Bad1.__call__' has type "Callable[[Arg(int, 'x'), VarArg(int)], int]" call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "Callable[[int, VarArg(str)], int]" \ - # N: 'Bad2.__call__' has type 'Callable[[Arg(int, 'y'), VarArg(str)], int]' + # N: 'Bad2.__call__' has type "Callable[[Arg(int, 'y'), VarArg(str)], int]" [builtins fixtures/isinstancelist.pyi] [case testStructuralSupportForPartial] From e0b5a307465f567ad31bb48cf71ad60e3bd09b98 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 25 Aug 2017 11:54:05 +0100 Subject: [PATCH 14/25] Fix non-pytest test failures --- test-data/unit/pythoneval-asyncio.test | 2 +- test-data/unit/pythoneval.test | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 114cd4b9cb66..b7f78beb5201 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -386,7 +386,7 @@ try: finally: loop.close() [out] -_program.py:18: error: Argument 1 to "add_done_callback" of "Future" has incompatible type Callable[[Future[int]], None]; expected Callable[[Future[str]], Any] +_program.py:18: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[int]], None]"; expected "Callable[[Future[str]], Any]" [case testErrorOneMoreFutureInReturnType] import typing diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 87520c5753ef..4ea16032e0d7 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -784,7 +784,7 @@ def f(*args: str) -> str: return args[0] map(f, ['x']) map(f, [1]) [out] -_program.py:4: error: Argument 1 to "map" has incompatible type Callable[[VarArg(str)], str]; expected Callable[[int], str] +_program.py:4: error: Argument 1 to "map" has incompatible type "Callable[[VarArg(str)], str]"; expected "Callable[[int], str]" [case testMapStr] import typing @@ -1122,7 +1122,7 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]): MyDDict(dict)['0'] MyDDict(dict)[0] [out] -_program.py:6: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected Callable[[], str] +_program.py:6: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Callable[[], str]" _program.py:9: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int" _program.py:9: error: Incompatible types in assignment (expression has type "int", target has type "str") _program.py:19: error: Dict entry 0 has incompatible type "str": "List[]"; expected "int": "List[]" @@ -1393,4 +1393,4 @@ c: Container[str] = p o: object = p it2: Iterable[int] = p [out] -_testCanConvertTypedDictToAnySuperclassOfMapping.py:11: error: Incompatible types in assignment (expression has type "Point", variable has type Iterable[int]) +_testCanConvertTypedDictToAnySuperclassOfMapping.py:11: error: Incompatible types in assignment (expression has type "Point", variable has type "Iterable[int]") From fc11a6f9f9fcd8ce10c8dba9f617db317ae0e3d2 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 09:17:46 +0100 Subject: [PATCH 15/25] Move FunctionLike formatting from MessageBuilder.format to _format_simple This makes the quoting code a little more consistent. --- mypy/messages.py | 85 +++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 55afe4868413..3f03b9e9b442 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -192,46 +192,6 @@ def format(self, typ: Type, verbosity: int = 0) -> str: if s != '' and s != '""': # If format_simple returns a non-trivial result, use that. return s - elif isinstance(typ, FunctionLike): - func = typ - if func.is_type_obj(): - # The type of a type object type can be derived from the - # return type (this always works). - return self.format(TypeType.make_normalized(erase_type(func.items()[0].ret_type)), - verbosity) - elif isinstance(func, CallableType): - return_type = strip_quotes(self.format(func.ret_type)) - if func.is_ellipsis_args: - return '"Callable[..., {}]"'.format(return_type) - arg_strings = [] - for arg_name, arg_type, arg_kind in zip( - func.arg_names, func.arg_types, func.arg_kinds): - if (arg_kind == ARG_POS and arg_name is None - or verbosity == 0 and arg_kind in (ARG_POS, ARG_OPT)): - - arg_strings.append( - strip_quotes( - self.format( - arg_type, - verbosity = max(verbosity - 1, 0)))) - else: - constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] - if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None: - arg_strings.append("{}({})".format( - constructor, - strip_quotes(self.format(arg_type)))) - else: - arg_strings.append("{}({}, {})".format( - constructor, - strip_quotes(self.format(arg_type)), - repr(arg_name))) - - return '"Callable[[{}], {}]"'.format(", ".join(arg_strings), return_type) - else: - # Use a simple representation for function types; proper - # function types may result in long and difficult-to-read - # error messages. - return 'overloaded function' else: # Default case; we simply have to return something meaningful here. return 'object' @@ -249,7 +209,8 @@ def format_simple(self, typ: Type, verbosity: int = 0) -> str: callable type -> "" (empty string) """ ret = self._format_simple(typ, verbosity) - if ret == "Module": + if ret in ['Module', 'overloaded function']: + # Messages are easier to read if these aren't quoted return ret return '"{}"'.format(self._format_simple(typ, verbosity)) @@ -348,6 +309,48 @@ def _format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, TypeType): return 'Type[{}]'.format( strip_quotes(self._format_simple(typ.item, verbosity))) + elif isinstance(typ, FunctionLike): + func = typ + if func.is_type_obj(): + # The type of a type object type can be derived from the + # return type (this always works). + return self._format_simple( + TypeType.make_normalized( + erase_type(func.items()[0].ret_type)), + verbosity) + elif isinstance(func, CallableType): + return_type = strip_quotes(self.format(func.ret_type)) + if func.is_ellipsis_args: + return 'Callable[..., {}]'.format(return_type) + arg_strings = [] + for arg_name, arg_type, arg_kind in zip( + func.arg_names, func.arg_types, func.arg_kinds): + if (arg_kind == ARG_POS and arg_name is None + or verbosity == 0 and arg_kind in (ARG_POS, ARG_OPT)): + + arg_strings.append( + strip_quotes( + self.format( + arg_type, + verbosity = max(verbosity - 1, 0)))) + else: + constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] + if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None: + arg_strings.append("{}({})".format( + constructor, + strip_quotes(self.format(arg_type)))) + else: + arg_strings.append("{}({}, {})".format( + constructor, + strip_quotes(self.format(arg_type)), + repr(arg_name))) + + return 'Callable[[{}], {}]'.format(", ".join(arg_strings), return_type) + else: + # Use a simple representation for function types; proper + # function types may result in long and difficult-to-read + # error messages. + return 'overloaded function' elif typ is None: raise RuntimeError('Type is None') else: From f288a60cebd8a15f2e234f75f821c3db16d1ad5c Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 09:22:33 +0100 Subject: [PATCH 16/25] Move fallback formatting from MessageBuilder.format to _format_simple --- mypy/messages.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 3f03b9e9b442..de99f3e685ca 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -188,13 +188,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: Mostly behave like format_simple below, but never return an empty string. """ - s = self.format_simple(typ, verbosity) - if s != '' and s != '""': - # If format_simple returns a non-trivial result, use that. - return s - else: - # Default case; we simply have to return something meaningful here. - return 'object' + return self.format_simple(typ, verbosity) def format_simple(self, typ: Type, verbosity: int = 0) -> str: """Convert simple types to string that is suitable for error messages. @@ -354,10 +348,8 @@ def _format_simple(self, typ: Type, verbosity: int = 0) -> str: elif typ is None: raise RuntimeError('Type is None') else: - # No simple representation for this type that would convey very - # useful information. No need to mention the type explicitly in a - # message. - return '' + # Default case; we simply have to return something meaningful here. + return 'object' def format_distinctly(self, type1: Type, type2: Type) -> Tuple[str, str]: """Jointly format a pair of types to distinct strings. From e10a8030b85d11bf41d16ffc1e07b13bdfd9a61d Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 09:40:52 +0100 Subject: [PATCH 17/25] Remove MessageBuilder.format_simple Instead update MessageBuilder.format to call _format_simple directly. --- mypy/messages.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index de99f3e685ca..f62f1c40a789 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -184,29 +184,12 @@ def warn(self, msg: str, context: Context, file: Optional[str] = None, self.report(msg, context, 'warning', file=file, origin=origin) def format(self, typ: Type, verbosity: int = 0) -> str: - """Convert a type to a relatively short string that is suitable for error messages. - - Mostly behave like format_simple below, but never return an empty string. - """ - return self.format_simple(typ, verbosity) - - def format_simple(self, typ: Type, verbosity: int = 0) -> str: - """Convert simple types to string that is suitable for error messages. - - Return "" for complex types. Try to keep the length of the result - relatively short to avoid overly long error messages. - - Examples: - builtins.int -> 'int' - Any type -> 'Any' - None -> None - callable type -> "" (empty string) - """ + """Convert a type to a relatively short string suitable for error messages.""" ret = self._format_simple(typ, verbosity) if ret in ['Module', 'overloaded function']: # Messages are easier to read if these aren't quoted return ret - return '"{}"'.format(self._format_simple(typ, verbosity)) + return '"{}"'.format(ret) def _format_simple(self, typ: Type, verbosity: int = 0) -> str: if isinstance(typ, Instance): From b4f0b78e3f31f7b711419942e40e21d908577f96 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 09:47:55 +0100 Subject: [PATCH 18/25] Introduce MessageBuilder.format_bare This is ._format_simple renamed to reflect its new intended contract. --- mypy/messages.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index f62f1c40a789..80393da222f3 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -184,14 +184,28 @@ def warn(self, msg: str, context: Context, file: Optional[str] = None, self.report(msg, context, 'warning', file=file, origin=origin) def format(self, typ: Type, verbosity: int = 0) -> str: - """Convert a type to a relatively short string suitable for error messages.""" - ret = self._format_simple(typ, verbosity) + """ + Convert a type to a relatively short string suitable for error messages. + + This method returns a string appropriate for unmodified use in error + messages; this means that it will be quoted in most cases. If + modification of the formatted string is required, callers should use + .format_bare. + """ + ret = self.format_bare(typ, verbosity) if ret in ['Module', 'overloaded function']: # Messages are easier to read if these aren't quoted return ret return '"{}"'.format(ret) - def _format_simple(self, typ: Type, verbosity: int = 0) -> str: + def format_bare(self, typ: Type, verbosity: int = 0) -> str: + """ + Convert a type to a relatively short string suitable for error messages. + + This method will return an unquoted string. If a caller doesn't need to + perform post-processing on the string output, .format should be used + instead. + """ if isinstance(typ, Instance): itype = typ # Get the short name of the type. @@ -235,7 +249,7 @@ def _format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, TupleType): # Prefer the name of the fallback class (if not tuple), as it's more informative. if typ.fallback.type.fullname() != 'builtins.tuple': - return self._format_simple(typ.fallback) + return self.format_bare(typ.fallback) items = [] for t in typ.items: items.append(strip_quotes(self.format(t))) @@ -247,7 +261,7 @@ def _format_simple(self, typ: Type, verbosity: int = 0) -> str: elif isinstance(typ, TypedDictType): # If the TypedDictType is named, return the name if not typ.is_anonymous(): - return self._format_simple(typ.fallback) + return self.format_bare(typ.fallback) items = [] for (item_name, item_type) in typ.items.items(): modifier = '' if item_name in typ.required_keys else '?' @@ -285,13 +299,13 @@ def _format_simple(self, typ: Type, verbosity: int = 0) -> str: return '' elif isinstance(typ, TypeType): return 'Type[{}]'.format( - strip_quotes(self._format_simple(typ.item, verbosity))) + strip_quotes(self.format_bare(typ.item, verbosity))) elif isinstance(typ, FunctionLike): func = typ if func.is_type_obj(): # The type of a type object type can be derived from the # return type (this always works). - return self._format_simple( + return self.format_bare( TypeType.make_normalized( erase_type(func.items()[0].ret_type)), verbosity) From 4bb8d3f27b482e8270196ace11e15d4e959dd20d Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 09:53:11 +0100 Subject: [PATCH 19/25] Use MessageBuilder.format_bare where appropriate This replaces strip_quotes(self.format(...)) calls, which have identical effect. --- mypy/messages.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 80393da222f3..7aa4589607c6 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -223,12 +223,12 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: # interpreted as a normal word. return base_str elif itype.type.fullname() == 'builtins.tuple': - item_type_str = strip_quotes(self.format(itype.args[0])) + item_type_str = self.format_bare(itype.args[0]) return 'Tuple[{}, ...]'.format(item_type_str) elif itype.type.fullname() in reverse_type_aliases: alias = reverse_type_aliases[itype.type.fullname()] alias = alias.split('.')[-1] - items = [strip_quotes(self.format(arg)) for arg in itype.args] + items = [self.format_bare(arg) for arg in itype.args] return '{}[{}]'.format(alias, ', '.join(items)) else: # There are type arguments. Convert the arguments to strings @@ -237,7 +237,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: # with [...]. a = [] # type: List[str] for arg in itype.args: - a.append(strip_quotes(self.format(arg))) + a.append(self.format_bare(arg)) s = ', '.join(a) if len((base_str + s)) < 150: return '{}[{}]'.format(base_str, s) @@ -252,7 +252,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: return self.format_bare(typ.fallback) items = [] for t in typ.items: - items.append(strip_quotes(self.format(t))) + items.append(self.format_bare(t)) s = 'Tuple[{}]'.format(', '.join(items)) if len(s) < 400: return s @@ -267,7 +267,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: modifier = '' if item_name in typ.required_keys else '?' items.append('{!r}{}: {}'.format(item_name, modifier, - strip_quotes(self.format(item_type)))) + self.format_bare(item_type))) s = 'TypedDict({{{}}})'.format(', '.join(items)) return s elif isinstance(typ, UnionType): @@ -276,11 +276,11 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: sum(isinstance(t, NoneTyp) for t in typ.items) == 1) if print_as_optional: rest = [t for t in typ.items if not isinstance(t, NoneTyp)] - return 'Optional[{}]'.format(strip_quotes(self.format(rest[0]))) + return 'Optional[{}]'.format(self.format_bare(rest[0])) else: items = [] for t in typ.items: - items.append(strip_quotes(self.format(t))) + items.append(self.format_bare(t)) s = 'Union[{}]'.format(', '.join(items)) if len(s) < 400: return s @@ -298,8 +298,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: else: return '' elif isinstance(typ, TypeType): - return 'Type[{}]'.format( - strip_quotes(self.format_bare(typ.item, verbosity))) + return 'Type[{}]'.format(self.format_bare(typ.item, verbosity)) elif isinstance(typ, FunctionLike): func = typ if func.is_type_obj(): @@ -310,7 +309,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: erase_type(func.items()[0].ret_type)), verbosity) elif isinstance(func, CallableType): - return_type = strip_quotes(self.format(func.ret_type)) + return_type = self.format_bare(func.ret_type) if func.is_ellipsis_args: return 'Callable[..., {}]'.format(return_type) arg_strings = [] @@ -320,20 +319,19 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: or verbosity == 0 and arg_kind in (ARG_POS, ARG_OPT)): arg_strings.append( - strip_quotes( - self.format( - arg_type, - verbosity = max(verbosity - 1, 0)))) + self.format_bare( + arg_type, + verbosity = max(verbosity - 1, 0))) else: constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None: arg_strings.append("{}({})".format( constructor, - strip_quotes(self.format(arg_type)))) + self.format_bare(arg_type))) else: arg_strings.append("{}({}, {})".format( constructor, - strip_quotes(self.format(arg_type)), + self.format_bare(arg_type), repr(arg_name))) return 'Callable[[{}], {}]'.format(", ".join(arg_strings), return_type) @@ -1020,7 +1018,7 @@ def concrete_only_call(self, typ: Type, context: Context) -> None: .format(self.format(typ)), context) def note_call(self, subtype: Type, call: Type, context: Context) -> None: - self.note("'{}.__call__' has type {}".format(strip_quotes(self.format(subtype)), + self.note("'{}.__call__' has type {}".format(self.format_bare(subtype), self.format(call, verbosity=1)), context) def report_protocol_problems(self, subtype: Union[Instance, TupleType, TypedDictType], @@ -1146,7 +1144,7 @@ def [T <: int] f(self, x: int, y: T) -> None name = tp.arg_names[i] if name: s += name + ': ' - s += strip_quotes(self.format(tp.arg_types[i])) + s += self.format_bare(tp.arg_types[i]) if tp.arg_kinds[i] in (ARG_OPT, ARG_NAMED_OPT): s += ' = ...' @@ -1162,17 +1160,17 @@ def [T <: int] f(self, x: int, y: T) -> None else: s = '({})'.format(s) - s += ' -> ' + strip_quotes(self.format(tp.ret_type)) + s += ' -> ' + self.format_bare(tp.ret_type) if tp.variables: tvars = [] for tvar in tp.variables: if (tvar.upper_bound and isinstance(tvar.upper_bound, Instance) and tvar.upper_bound.type.fullname() != 'builtins.object'): tvars.append('{} <: {}'.format(tvar.name, - strip_quotes(self.format(tvar.upper_bound)))) + self.format_bare(tvar.upper_bound))) elif tvar.values: tvars.append('{} in ({})' - .format(tvar.name, ', '.join([strip_quotes(self.format(tp)) + .format(tvar.name, ', '.join([self.format_bare(tp) for tp in tvar.values]))) else: tvars.append(tvar.name) From 8a27e2c770a926e18fe12bd7ac0e35648ac3f309 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 10:00:45 +0100 Subject: [PATCH 20/25] Move * and ** inside quotes in MessageBuilder.incompatible_argument This adds a bare parameter to format_distinctly, so that MessageBuilder.incompatible_argument can take care of the quoting for its special case. --- mypy/messages.py | 14 +++++--- test-data/unit/check-expressions.test | 2 +- test-data/unit/check-kwargs.test | 10 +++--- test-data/unit/check-varargs.test | 52 +++++++++++++-------------- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 7aa4589607c6..de572cca2c47 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -346,15 +346,19 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: # Default case; we simply have to return something meaningful here. return 'object' - def format_distinctly(self, type1: Type, type2: Type) -> Tuple[str, str]: + def format_distinctly(self, type1: Type, type2: Type, bare: bool = False) -> Tuple[str, str]: """Jointly format a pair of types to distinct strings. Increase the verbosity of the type strings until they become distinct. """ + if bare: + format_method = self.format_bare + else: + format_method = self.format verbosity = 0 for verbosity in range(3): - str1 = self.format(type1, verbosity=verbosity) - str2 = self.format(type2, verbosity=verbosity) + str1 = format_method(type1, verbosity=verbosity) + str2 = format_method(type2, verbosity=verbosity) if str1 != str2: return (str1, str2) return (str1, str2) @@ -600,12 +604,12 @@ def incompatible_argument(self, n: int, m: int, callee: CallableType, arg_type: expected_type = callee.arg_types[m - 1] except IndexError: # Varargs callees expected_type = callee.arg_types[-1] - arg_type_str, expected_type_str = self.format_distinctly(arg_type, expected_type) + arg_type_str, expected_type_str = self.format_distinctly(arg_type, expected_type, bare=True) if arg_kind == ARG_STAR: arg_type_str = '*' + arg_type_str elif arg_kind == ARG_STAR2: arg_type_str = '**' + arg_type_str - msg = 'Argument {} {}has incompatible type {}; expected {}'.format( + msg = 'Argument {} {}has incompatible type "{}"; expected "{}"'.format( n, target, arg_type_str, expected_type_str) if isinstance(arg_type, Instance) and isinstance(expected_type, Instance): notes = append_invariance_notes(notes, arg_type, expected_type) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index ca6ed6680ed5..0d9afcd67db9 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1606,7 +1606,7 @@ kw2 = {'x': ''} d2 = dict(it, **kw2) # E: Cannot infer type argument 2 of "dict" d2() # E: "Dict[Any, Any]" not callable -d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type **"Dict[str, str]"; expected "int" +d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type "**Dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs2] diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index 74ceb4566742..3d682b40760c 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -252,8 +252,8 @@ d = None # type: Dict[str, A] f(**d) f(x=A(), **d) d2 = None # type: Dict[str, B] -f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, B]"; expected "A" -f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type **"Dict[str, B]"; expected "A" +f(**d2) # E: Argument 1 to "f" has incompatible type "**Dict[str, B]"; expected "A" +f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type "**Dict[str, B]"; expected "A" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -316,7 +316,7 @@ def f(a: 'A', b: 'B') -> None: pass d = None # type: Dict[str, Any] f(**d) d2 = None # type: Dict[str, A] -f(**d2) # E: Argument 1 to "f" has incompatible type **"Dict[str, A]"; expected "B" +f(**d2) # E: Argument 1 to "f" has incompatible type "**Dict[str, A]"; expected "B" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -362,7 +362,7 @@ def f(a: int) -> None: pass s = ('',) -f(*s) # E: Argument 1 to "f" has incompatible type *"Tuple[str]"; expected "int" +f(*s) # E: Argument 1 to "f" has incompatible type "*Tuple[str]"; expected "int" a = {'': 0} f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, int]"; expected "int" @@ -370,7 +370,7 @@ f(**a) # okay b = {'': ''} f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, str]"; expected "int" -f(**b) # E: Argument 1 to "f" has incompatible type **"Dict[str, str]"; expected "int" +f(**b) # E: Argument 1 to "f" has incompatible type "**Dict[str, str]"; expected "int" c = {0: 0} f(**c) # E: Keywords must be strings diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 4f5491903af6..d1c41a7ae627 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -108,7 +108,7 @@ it1 = None # type: Iterable[int] it2 = None # type: Iterable[str] def f(*x: int) -> None: pass f(*it1) -f(*it2) # E: Argument 1 to "f" has incompatible type *"Iterable[str]"; expected "int" +f(*it2) # E: Argument 1 to "f" has incompatible type "*Iterable[str]"; expected "int" [builtins fixtures/for.pyi] [case testCallVarargsFunctionWithIterableAndPositional] @@ -208,7 +208,7 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:7: error: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" [case testCallingWithTupleVarArgs] @@ -217,9 +217,9 @@ b = None # type: B c = None # type: C cc = None # type: CC -f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type *"Tuple[A, B, B]"; expected "C" -f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type *"Tuple[B, B, C]"; expected "A" -f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type *"Tuple[B, B]"; expected "C" +f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B, B]"; expected "C" +f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type "*Tuple[B, B, C]"; expected "A" +f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type "*Tuple[B, B]"; expected "C" f(b, *(b, c)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(*(a, b)) # E: Too few arguments for "f" f(*(a, b, c, c)) # E: Too many arguments for "f" @@ -277,26 +277,26 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:3: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" -main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" +main:3: error: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" +main:4: error: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" main:5: error: Argument 1 to "f" has incompatible type "B"; expected "A" main:6: error: Argument 2 to "f" has incompatible type "A"; expected "B" -main:7: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" +main:7: error: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 1 to "g" has incompatible type *"List[B]"; expected "A" +main:9: error: Argument 1 to "g" has incompatible type "*List[B]"; expected "A" [case testCallingVarArgsFunctionWithTupleVarArgs] a, b, c, cc = None, None, None, None # type: (A, B, C, CC) -f(*(b, b, b)) # E: Argument 1 to "f" has incompatible type *"Tuple[B, B, B]"; expected "A" -f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type *"Tuple[A, A, B]"; expected "B" -f(*(a, b, a)) # E: Argument 1 to "f" has incompatible type *"Tuple[A, B, A]"; expected "B" -f(a, *(a, b)) # E: Argument 2 to "f" has incompatible type *"Tuple[A, B]"; expected "B" +f(*(b, b, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[B, B, B]"; expected "A" +f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, A, B]"; expected "B" +f(*(a, b, a)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B, A]"; expected "B" +f(a, *(a, b)) # E: Argument 2 to "f" has incompatible type "*Tuple[A, B]"; expected "B" f(b, *(b, b)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(b, b, *(b,)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(a, a, *(b,)) # E: Argument 2 to "f" has incompatible type "A"; expected "B" -f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type *"Tuple[A]"; expected "B" +f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type "*Tuple[A]"; expected "B" f(*()) # E: Too few arguments for "f" f(*(a, b, b)) f(a, *(b, b)) @@ -340,7 +340,7 @@ from typing import List aa = None # type: List[A] ab = None # type: List[B] -g(*aa) # E: Argument 1 to "g" has incompatible type *"List[A]"; expected "B" +g(*aa) # E: Argument 1 to "g" has incompatible type "*List[A]"; expected "B" f(*aa) f(*ab) g(*ab) @@ -377,10 +377,10 @@ class B: pass [builtins fixtures/list.pyi] [out] main:3: error: Too few arguments for "f" -main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "Optional[B]" -main:4: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" -main:5: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" -main:6: error: Argument 1 to "f" has incompatible type *"Tuple[A, A, B]"; expected "Optional[B]" +main:4: error: Argument 2 to "f" has incompatible type "*List[A]"; expected "Optional[B]" +main:4: error: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" +main:5: error: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" +main:6: error: Argument 1 to "f" has incompatible type "*Tuple[A, A, B]"; expected "Optional[B]" [case testVarArgsAfterKeywordArgInCall1-skip] # see: mypy issue #2729 @@ -492,11 +492,11 @@ class A: pass class B: pass [builtins fixtures/list.pyi] [out] -main:6: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" -main:7: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" +main:6: error: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" +main:7: error: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" main:8: error: Argument 1 to "f" has incompatible type "B"; expected "A" -main:9: error: Argument 2 to "f" has incompatible type *"List[A]"; expected "B" -main:10: error: Argument 3 to "f" has incompatible type *"List[A]"; expected "B" +main:9: error: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" +main:10: error: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" main:11: error: List or tuple expected as variable arguments main:12: error: List or tuple expected as variable arguments @@ -506,9 +506,9 @@ S = TypeVar('S') T = TypeVar('T') a, b = None, None # type: (A, B) -a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type *"Tuple[A, B]"; expected "A" +a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B]"; expected "A" b, b = f(a, *(b,)) # E: Argument 1 to "f" has incompatible type "A"; expected "B" -a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type *"Tuple[A, B]"; expected "A" +a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B]"; expected "A" b, b = f(a, *(b,)) # E: Argument 1 to "f" has incompatible type "A"; expected "B" a, b = f(*(a, b, b)) # E: Too many arguments for "f" @@ -549,7 +549,7 @@ main:9: error: Incompatible types in assignment (expression has type "List[A]", main:9: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") main:10: error: Incompatible types in assignment (expression has type "List[]", variable has type "A") main:11: error: Incompatible types in assignment (expression has type "List[]", variable has type "List[A]") -main:11: error: Argument 1 to "f" of "G" has incompatible type *"List[A]"; expected "B" +main:11: error: Argument 1 to "f" of "G" has incompatible type "*List[A]"; expected "B" -- Comment signatures From a8fe40009d67bedca93b54e905e6882ae114f6c2 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Sun, 27 Aug 2017 10:27:17 +0100 Subject: [PATCH 21/25] Fix long line --- mypy/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index de572cca2c47..292f7e1d8b8b 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -604,7 +604,8 @@ def incompatible_argument(self, n: int, m: int, callee: CallableType, arg_type: expected_type = callee.arg_types[m - 1] except IndexError: # Varargs callees expected_type = callee.arg_types[-1] - arg_type_str, expected_type_str = self.format_distinctly(arg_type, expected_type, bare=True) + arg_type_str, expected_type_str = self.format_distinctly( + arg_type, expected_type, bare=True) if arg_kind == ARG_STAR: arg_type_str = '*' + arg_type_str elif arg_kind == ARG_STAR2: From daa6792ae1ddaf85ce94dd8e674b27d119183509 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Tue, 29 Aug 2017 19:33:24 +0100 Subject: [PATCH 22/25] Fix up now-inaccurate comments --- mypy/messages.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 292f7e1d8b8b..b96b1b11871a 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -218,9 +218,7 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: else: base_str = itype.type.name() if itype.args == []: - # No type arguments. Place the type name in quotes to avoid - # potential for confusion: otherwise, the type name could be - # interpreted as a normal word. + # No type arguments, just return the type name return base_str elif itype.type.fullname() == 'builtins.tuple': item_type_str = self.format_bare(itype.args[0]) @@ -231,10 +229,8 @@ def format_bare(self, typ: Type, verbosity: int = 0) -> str: items = [self.format_bare(arg) for arg in itype.args] return '{}[{}]'.format(alias, ', '.join(items)) else: - # There are type arguments. Convert the arguments to strings - # (using format() instead of format_simple() to avoid empty - # strings). If the result is too long, replace arguments - # with [...]. + # There are type arguments. Convert the arguments to strings. + # If the result is too long, replace arguments with [...]. a = [] # type: List[str] for arg in itype.args: a.append(self.format_bare(arg)) From 96961c0b507b1308e5f00f6ede8bc7e8929667a9 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 30 Aug 2017 09:38:55 +0100 Subject: [PATCH 23/25] Elaborate on the bare parameter in format_distinctly --- mypy/messages.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mypy/messages.py b/mypy/messages.py index b96b1b11871a..b54e2dfdfe88 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -346,6 +346,11 @@ def format_distinctly(self, type1: Type, type2: Type, bare: bool = False) -> Tup """Jointly format a pair of types to distinct strings. Increase the verbosity of the type strings until they become distinct. + + By default, the returned strings are created using .format() and will be + quoted accordingly. If ``bare`` is True, the returned strings will not + be quoted; callers who need to do post-processing of the strings before + quoting them (such as prepending * or **) should use this. """ if bare: format_method = self.format_bare From 5bc72516c82cb7fd04f807da80076063a15446a1 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 30 Aug 2017 09:59:02 +0100 Subject: [PATCH 24/25] Don't quote or in messages --- mypy/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index b54e2dfdfe88..c606678d4dd8 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -193,7 +193,7 @@ def format(self, typ: Type, verbosity: int = 0) -> str: .format_bare. """ ret = self.format_bare(typ, verbosity) - if ret in ['Module', 'overloaded function']: + if ret in ['Module', 'overloaded function', '', '']: # Messages are easier to read if these aren't quoted return ret return '"{}"'.format(ret) From a84b4bb281247a9c8240c68140ef0c5bfd2b7bbf Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 30 Aug 2017 13:38:01 +0100 Subject: [PATCH 25/25] Don't surround tuple(length N) in quotes in message output --- mypy/messages.py | 7 +++++-- test-data/unit/check-tuples.test | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index c606678d4dd8..a59d28678ab1 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -193,8 +193,11 @@ def format(self, typ: Type, verbosity: int = 0) -> str: .format_bare. """ ret = self.format_bare(typ, verbosity) - if ret in ['Module', 'overloaded function', '', '']: - # Messages are easier to read if these aren't quoted + no_quote_regex = r'^tuple\(length \d+\)$' + if (ret in ['Module', 'overloaded function', '', ''] + or re.match(no_quote_regex, ret) is not None): + # Messages are easier to read if these aren't quoted. We use a + # regex to match strings with variable contents. return ret return '"{}"'.format(ret) diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 504cf431743a..ad435666fb22 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -579,7 +579,7 @@ class LongTypeName: def __add__(self, x: 'LongTypeName') -> 'LongTypeName': pass [builtins fixtures/tuple.pyi] [out] -main:3: error: Unsupported operand types for + ("LongTypeName" and "tuple(length 50)") +main:3: error: Unsupported operand types for + ("LongTypeName" and tuple(length 50)) -- Tuple methods