From 2d38a660abf13f0d30bf447fa1d7c16719764155 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 31 Aug 2017 10:20:02 +0100 Subject: [PATCH 1/3] Quote __aexit__ and __aenter__ in error messages --- mypy/messages.py | 4 ++-- test-data/unit/check-async-await.test | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index a59d28678ab1..890ddccd4d99 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -46,8 +46,8 @@ INCOMPATIBLE_TYPES_IN_ASSIGNMENT = 'Incompatible types in assignment' INCOMPATIBLE_REDEFINITION = 'Incompatible redefinition' INCOMPATIBLE_TYPES_IN_AWAIT = 'Incompatible types in await' -INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTER = 'Incompatible types in "async with" for __aenter__' -INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT = 'Incompatible types in "async with" for __aexit__' +INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTER = 'Incompatible types in "async with" for "__aenter__"' +INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT = 'Incompatible types in "async with" for "__aexit__"' INCOMPATIBLE_TYPES_IN_ASYNC_FOR = 'Incompatible types in "async for"' INCOMPATIBLE_TYPES_IN_YIELD = 'Incompatible types in yield' diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index c460aed2882e..505a7aeadb27 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -290,7 +290,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] [typing fixtures/typing-full.pyi] @@ -312,7 +312,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] [typing fixtures/typing-full.pyi] From 3d48b0198a29ec1a1c020c980bfeb461183b79c2 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 31 Aug 2017 10:35:37 +0100 Subject: [PATCH 2/3] Make quoting in incompatible types messages more consistent --- mypy/messages.py | 4 ++-- test-data/unit/check-async-await.test | 20 ++++++++++---------- test-data/unit/check-expressions.test | 2 +- test-data/unit/check-statements.test | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 890ddccd4d99..3e1601f5181c 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -45,12 +45,12 @@ INCOMPATIBLE_TYPES = 'Incompatible types' INCOMPATIBLE_TYPES_IN_ASSIGNMENT = 'Incompatible types in assignment' INCOMPATIBLE_REDEFINITION = 'Incompatible redefinition' -INCOMPATIBLE_TYPES_IN_AWAIT = 'Incompatible types in await' +INCOMPATIBLE_TYPES_IN_AWAIT = 'Incompatible types in "await"' INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTER = 'Incompatible types in "async with" for "__aenter__"' INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT = 'Incompatible types in "async with" for "__aexit__"' INCOMPATIBLE_TYPES_IN_ASYNC_FOR = 'Incompatible types in "async for"' -INCOMPATIBLE_TYPES_IN_YIELD = 'Incompatible types in yield' +INCOMPATIBLE_TYPES_IN_YIELD = 'Incompatible types in "yield"' INCOMPATIBLE_TYPES_IN_YIELD_FROM = 'Incompatible types in "yield from"' INCOMPATIBLE_TYPES_IN_STR_INTERPOLATION = 'Incompatible types in string interpolation' MUST_HAVE_NONE_RETURN_TYPE = 'The return type of "{}" must be None' diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 505a7aeadb27..e243bd50f415 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -93,7 +93,7 @@ async def f() -> int: return x [typing fixtures/typing-full.pyi] [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] @@ -105,7 +105,7 @@ async def f() -> int: return x [typing fixtures/typing-full.pyi] [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] @@ -117,7 +117,7 @@ async def f() -> int: [builtins fixtures/async_await.pyi] [typing fixtures/typing-full.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] @@ -419,7 +419,7 @@ from types import coroutine @coroutine def f() -> Generator[int, str, int]: x = yield 0 - x = yield '' # E: Incompatible types in yield (actual type "str", expected type "int") + x = yield '' # E: Incompatible types in "yield" (actual type "str", expected type "int") reveal_type(x) # E: Revealed type is 'builtins.str' if x: return 0 @@ -443,7 +443,7 @@ async def g() -> AsyncGenerator[int, None]: reveal_type(value) # E: Revealed type is 'builtins.int*' yield value - yield 'not an int' # E: Incompatible types in yield (actual type "str", expected type "int") + yield 'not an int' # E: Incompatible types in "yield" (actual type "str", expected type "int") # return without a value is fine return reveal_type(g) # E: Revealed type is 'def () -> typing.AsyncGenerator[builtins.int, builtins.None]' @@ -466,7 +466,7 @@ from typing import AsyncIterator async def gen() -> AsyncIterator[int]: yield 3 - yield 'not an int' # E: Incompatible types in yield (actual type "str", expected type "int") + yield 'not an int' # E: Incompatible types in "yield" (actual type "str", expected type "int") async def use_gen() -> None: async for item in gen(): @@ -644,11 +644,11 @@ def plain_host_generator() -> Generator[str, None, None]: 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 @@ -665,11 +665,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-expressions.test b/test-data/unit/check-expressions.test index 0d9afcd67db9..8b862d042185 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1215,7 +1215,7 @@ from typing import Iterator, Callable lambda: (yield) gen: Callable[[], Iterator[str]] -gen = (lambda: (yield 1)) # E: Incompatible types in yield (actual type "int", expected type "str") +gen = (lambda: (yield 1)) # E: Incompatible types in "yield" (actual type "int", expected type "str") def fun(cb: Callable[[], Iterator[str]]) -> None: pass diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 687e8f6e591e..5d45c15d128d 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -1050,7 +1050,7 @@ while x == 5: ... # E: Trying to read deleted variable 'x' from typing import Iterator def f() -> Iterator[int]: yield 1 - yield '' # E: Incompatible types in yield (actual type "str", expected type "int") + yield '' # E: Incompatible types in "yield" (actual type "str", expected type "int") [builtins fixtures/for.pyi] [out] From a810f2a2c9dbb1385b77c2bf8dfbfd17b9902bcd Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 31 Aug 2017 10:44:32 +0100 Subject: [PATCH 3/3] Use double quotes in note_call output --- mypy/messages.py | 2 +- test-data/unit/check-protocols.test | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 3e1601f5181c..7b6a0e158419 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1027,7 +1027,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(self.format_bare(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], diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index f8c10b49d7e8..fd43bbf3e0f3 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]