Skip to content

Commit

Permalink
Use level "note" for reveal_type and reveal_locals (python#6919)
Browse files Browse the repository at this point in the history
Tests were fixed using:
- sed -i 's/# E: Revealed type/# N: Revealed type/g' test-data/**/*.test
- sed -i 's/: error: Revealed type/: note: Revealed type/g' test-data/**/*.test

Fixes python#6901.
  • Loading branch information
blueyed authored and PattenR committed Jun 23, 2019
1 parent e5ddbb6 commit 9f04044
Show file tree
Hide file tree
Showing 60 changed files with 3,263 additions and 3,263 deletions.
4 changes: 2 additions & 2 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ to see the types of all local variables at once. Example:
b = 'one'
reveal_locals()
# Revealed local types are:
# a: builtins.int
# b: builtins.str
# a: builtins.int
# b: builtins.str
.. note::

``reveal_type`` and ``reveal_locals`` are only understood by mypy and
Expand Down
8 changes: 4 additions & 4 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,15 +1068,15 @@ def invalid_signature_for_special_method(
self.fail('Invalid signature "{}" for "{}"'.format(func_type, method_name), context)

def reveal_type(self, typ: Type, context: Context) -> None:
self.fail('Revealed type is \'{}\''.format(typ), context)
self.note('Revealed type is \'{}\''.format(typ), context)

def reveal_locals(self, type_map: Dict[str, Optional[Type]], context: Context) -> None:
# To ensure that the output is predictable on Python < 3.6,
# use an ordered dictionary sorted by variable name
sorted_locals = OrderedDict(sorted(type_map.items(), key=lambda t: t[0]))
self.fail("Revealed local types are:", context)
for line in ['{}: {}'.format(k, v) for k, v in sorted_locals.items()]:
self.fail(line, context)
self.note("Revealed local types are:", context)
for line in [' {}: {}'.format(k, v) for k, v in sorted_locals.items()]:
self.note(line, context)

def unsupported_type_type(self, item: Type, context: Context) -> None:
self.fail('Unsupported type Type[{}]'.format(self.format(item)), context)
Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class NSImportStyle(Enum):

class SimpleMsg(Enum):
msg_dne = "{tempfile}:3: error: Module 'typedpkg' has no attribute 'dne'"
msg_list = "{tempfile}:5: error: Revealed type is 'builtins.list[builtins.str]'"
msg_tuple = "{tempfile}:5: error: Revealed type is 'builtins.tuple[builtins.str]'"
msg_list = "{tempfile}:5: note: Revealed type is 'builtins.list[builtins.str]'"
msg_tuple = "{tempfile}:5: note: Revealed type is 'builtins.tuple[builtins.str]'"


class NamespaceMsg(Enum):
Expand Down
2 changes: 1 addition & 1 deletion scripts/find_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run_mypy(mypy_and_args: List[str], filename: str, tmp_name: str) -> str:
return proc.stdout.decode(encoding="utf-8")

def get_revealed_type(line: str, relevant_file: str, relevant_line: int) -> Optional[str]:
m = re.match(r"(.+?):(\d+): error: Revealed type is '(.*)'$", line)
m = re.match(r"(.+?):(\d+): note: Revealed type is '(.*)'$", line)
if (m and
int(m.group(2)) == relevant_line and
os.path.samefile(relevant_file, m.group(1))):
Expand Down
58 changes: 29 additions & 29 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def f() -> int:

async def f() -> int:
return 0
reveal_type(f()) # E: Revealed type is 'typing.Coroutine[Any, Any, builtins.int]'
reveal_type(f()) # N: Revealed type is 'typing.Coroutine[Any, Any, builtins.int]'
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]

Expand All @@ -39,7 +39,7 @@ main:4: error: Return value expected

async def f() -> int:
x = await f()
reveal_type(x) # E: Revealed type is 'builtins.int*'
reveal_type(x) # N: Revealed type is 'builtins.int*'
return x
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
Expand All @@ -55,7 +55,7 @@ async def f(x: T) -> T:
return y
[typing fixtures/typing-full.pyi]
[out]
main:6: error: Revealed type is 'T`-1'
main:6: note: Revealed type is 'T`-1'

[case testAwaitAnyContext]

Expand All @@ -67,7 +67,7 @@ async def f(x: T) -> T:
return y
[typing fixtures/typing-full.pyi]
[out]
main:6: error: Revealed type is 'Any'
main:6: note: Revealed type is 'Any'

[case testAwaitExplicitContext]

Expand All @@ -80,7 +80,7 @@ async def f(x: T) -> T:
[typing fixtures/typing-full.pyi]
[out]
main:5: error: Argument 1 to "f" has incompatible type "T"; expected "int"
main:6: error: Revealed type is 'builtins.int'
main:6: note: Revealed type is 'builtins.int'

[case testAwaitGeneratorError]

Expand Down Expand Up @@ -150,7 +150,7 @@ class C(AsyncIterator[int]):
async def __anext__(self) -> int: return 0
async def f() -> None:
async for x in C():
reveal_type(x) # E: Revealed type is 'builtins.int*'
reveal_type(x) # N: Revealed type is 'builtins.int*'
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]

Expand Down Expand Up @@ -178,7 +178,7 @@ async def f() -> None:
pass

async for z in C(): # type: Union[int, str]
reveal_type(z) # E: Revealed type is 'Union[builtins.int, builtins.str]'
reveal_type(z) # N: Revealed type is 'Union[builtins.int, builtins.str]'
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]

Expand All @@ -201,23 +201,23 @@ class asyncify(Generic[T], AsyncIterator[T]):

async def listcomp(obj: Iterable[int]):
lst = [i async for i in asyncify(obj)]
reveal_type(lst) # E: Revealed type is 'builtins.list[builtins.int*]'
reveal_type(lst) # N: Revealed type is 'builtins.list[builtins.int*]'
lst2 = [i async for i in asyncify(obj) for j in obj]
reveal_type(lst2) # E: Revealed type is 'builtins.list[builtins.int*]'
reveal_type(lst2) # N: Revealed type is 'builtins.list[builtins.int*]'

async def setcomp(obj: Iterable[int]):
lst = {i async for i in asyncify(obj)}
reveal_type(lst) # E: Revealed type is 'builtins.set[builtins.int*]'
reveal_type(lst) # N: Revealed type is 'builtins.set[builtins.int*]'

async def dictcomp(obj: Iterable[Tuple[int, str]]):
lst = {i: j async for i, j in asyncify(obj)}
reveal_type(lst) # E: Revealed type is 'builtins.dict[builtins.int*, builtins.str*]'
reveal_type(lst) # N: Revealed type is 'builtins.dict[builtins.int*, builtins.str*]'

async def generatorexp(obj: Iterable[int]):
lst = (i async for i in asyncify(obj))
reveal_type(lst) # E: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'
reveal_type(lst) # N: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'
lst2 = (i async for i in asyncify(obj) for i in obj)
reveal_type(lst2) # E: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'
reveal_type(lst2) # N: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'

[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
Expand Down Expand Up @@ -260,7 +260,7 @@ class C:
async def __aexit__(self, x, y, z) -> None: pass
async def f() -> None:
async with C() as x:
reveal_type(x) # E: Revealed type is 'builtins.int*'
reveal_type(x) # N: Revealed type is 'builtins.int*'
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]

Expand Down Expand Up @@ -399,11 +399,11 @@ class I(AsyncIterator[int]):
return A()
async def main() -> None:
x = await A()
reveal_type(x) # E: Revealed type is 'builtins.int'
reveal_type(x) # N: Revealed type is 'builtins.int'
async with C() as y:
reveal_type(y) # E: Revealed type is 'builtins.int'
reveal_type(y) # N: Revealed type is 'builtins.int'
async for z in I():
reveal_type(z) # E: Revealed type is 'builtins.int'
reveal_type(z) # N: Revealed type is 'builtins.int'
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]

Expand All @@ -415,7 +415,7 @@ from types import coroutine
def f() -> Generator[int, str, int]:
x = yield 0
x = yield '' # E: Incompatible types in "yield" (actual type "str", expected type "int")
reveal_type(x) # E: Revealed type is 'builtins.str'
reveal_type(x) # N: Revealed type is 'builtins.str'
if x:
return 0
else:
Expand All @@ -435,18 +435,18 @@ async def f() -> int:

async def g() -> AsyncGenerator[int, None]:
value = await f()
reveal_type(value) # E: Revealed type is 'builtins.int*'
reveal_type(value) # N: Revealed type is 'builtins.int*'
yield value

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, None]'
reveal_type(g()) # E: Revealed type is 'typing.AsyncGenerator[builtins.int, None]'
reveal_type(g) # N: Revealed type is 'def () -> typing.AsyncGenerator[builtins.int, None]'
reveal_type(g()) # N: Revealed type is 'typing.AsyncGenerator[builtins.int, None]'

async def h() -> None:
async for item in g():
reveal_type(item) # E: Revealed type is 'builtins.int*'
reveal_type(item) # N: Revealed type is 'builtins.int*'

async def wrong_return() -> Generator[int, None, None]: # E: The return type of an async generator function should be "AsyncGenerator" or one of its supertypes
yield 3
Expand All @@ -465,7 +465,7 @@ async def gen() -> AsyncIterator[int]:

async def use_gen() -> None:
async for item in gen():
reveal_type(item) # E: Revealed type is 'builtins.int*'
reveal_type(item) # N: Revealed type is 'builtins.int*'

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]
Expand All @@ -481,9 +481,9 @@ async def genfunc() -> AsyncGenerator[int, None]:
async def user() -> None:
gen = genfunc()

reveal_type(gen.__aiter__()) # E: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'
reveal_type(gen.__aiter__()) # N: Revealed type is 'typing.AsyncGenerator[builtins.int*, None]'

reveal_type(await gen.__anext__()) # E: Revealed type is 'builtins.int*'
reveal_type(await gen.__anext__()) # N: Revealed type is 'builtins.int*'

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]
Expand All @@ -498,13 +498,13 @@ async def f() -> None:
async def gen() -> AsyncGenerator[int, str]:
await f()
v = yield 42
reveal_type(v) # E: Revealed type is 'builtins.str'
reveal_type(v) # N: Revealed type is 'builtins.str'
await f()

async def h() -> None:
g = gen()
await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "Tuple[]"; expected "str"
reveal_type(await g.asend('hello')) # E: Revealed type is 'builtins.int*'
reveal_type(await g.asend('hello')) # N: Revealed type is 'builtins.int*'

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]
Expand All @@ -522,8 +522,8 @@ async def gen() -> AsyncGenerator[str, int]:
async def h() -> None:
g = gen()
v = await g.asend(1)
reveal_type(v) # E: Revealed type is 'builtins.str*'
reveal_type(await g.athrow(BaseException)) # E: Revealed type is 'builtins.str*'
reveal_type(v) # N: Revealed type is 'builtins.str*'
reveal_type(await g.athrow(BaseException)) # N: Revealed type is 'builtins.str*'

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]
Expand Down

0 comments on commit 9f04044

Please sign in to comment.