diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 96faf05c6d7b..c0c8d7e9d8d1 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -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 diff --git a/mypy/messages.py b/mypy/messages.py index b777be83431c..b44aed962595 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -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) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index dcdc0fb04c93..b88fc6d88634 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -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): diff --git a/scripts/find_type.py b/scripts/find_type.py index ce10da62560c..f66ea6b54450 100755 --- a/scripts/find_type.py +++ b/scripts/find_type.py @@ -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))): diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 184d48019f8a..eff2c18690be 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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: @@ -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 @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/test-data/unit/check-attr.test b/test-data/unit/check-attr.test index b0f0791a4188..4d33b929a820 100644 --- a/test-data/unit/check-attr.test +++ b/test-data/unit/check-attr.test @@ -10,7 +10,7 @@ class A: def foo(self): return self.a -reveal_type(A) # E: Revealed type is 'def (a: Any, b: Any, c: Any =, d: Any =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: Any, b: Any, c: Any =, d: Any =) -> __main__.A' A(1, [2]) A(1, [2], '3', 4) A(1, 2, 3, 4) @@ -28,7 +28,7 @@ class A: _d: int = attr.ib(validator=None, default=18) E = 7 F: ClassVar[int] = 22 -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' A(1, [2]) A(1, [2], '3', 4) A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" @@ -46,7 +46,7 @@ class A: _d = attr.ib(validator=None, default=18) # type: int E = 7 F: ClassVar[int] = 22 -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' A(1, [2]) A(1, [2], '3', 4) A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" @@ -64,7 +64,7 @@ class A: _d: int = attr.ib(validator=None, default=18) E = 7 F: ClassVar[int] = 22 -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A' A(1, [2]) A(1, [2], '3', 4) A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" @@ -117,7 +117,7 @@ class A: c = attrib(18) _d = attrib(validator=None, default=18) CLASS_VAR = 18 -reveal_type(A) # E: Revealed type is 'def (a: Any, b: builtins.list[builtins.int], c: Any =, d: Any =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: Any, b: builtins.list[builtins.int], c: Any =, d: Any =) -> __main__.A' A(1, [2]) A(1, [2], '3', 4) A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" @@ -164,7 +164,7 @@ class A: _b: int c: int = 18 _d: int = attrib(validator=None, default=18) -reveal_type(A) # E: Revealed type is 'def () -> __main__.A' +reveal_type(A) # N: Revealed type is 'def () -> __main__.A' A() A(1, [2]) # E: Too many arguments for "A" A(1, [2], '3', 4) # E: Too many arguments for "A" @@ -176,7 +176,7 @@ from attr import attrib, attrs class A: a = attrib(init=False) b = attrib() -reveal_type(A) # E: Revealed type is 'def (b: Any) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (b: Any) -> __main__.A' [builtins fixtures/bool.pyi] [case testAttrsCmpTrue] @@ -184,13 +184,13 @@ from attr import attrib, attrs @attrs(auto_attribs=True) class A: a: int -reveal_type(A) # E: Revealed type is 'def (a: builtins.int) -> __main__.A' -reveal_type(A.__eq__) # E: Revealed type is 'def (self: __main__.A, other: builtins.object) -> builtins.bool' -reveal_type(A.__ne__) # E: Revealed type is 'def (self: __main__.A, other: builtins.object) -> builtins.bool' -reveal_type(A.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__le__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__gt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__ge__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int) -> __main__.A' +reveal_type(A.__eq__) # N: Revealed type is 'def (self: __main__.A, other: builtins.object) -> builtins.bool' +reveal_type(A.__ne__) # N: Revealed type is 'def (self: __main__.A, other: builtins.object) -> builtins.bool' +reveal_type(A.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__le__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__gt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__ge__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' A(1) < A(2) A(1) <= A(2) @@ -219,9 +219,9 @@ from attr import attrib, attrs @attrs(auto_attribs=True, cmp=False) class A: a: int -reveal_type(A) # E: Revealed type is 'def (a: builtins.int) -> __main__.A' -reveal_type(A.__eq__) # E: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' -reveal_type(A.__ne__) # E: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int) -> __main__.A' +reveal_type(A.__eq__) # N: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' +reveal_type(A.__ne__) # N: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' A(1) < A(2) # E: Unsupported left operand type for < ("A") A(1) <= A(2) # E: Unsupported left operand type for <= ("A") @@ -256,7 +256,7 @@ class B: @attr.s class C(A, B): c: bool = attr.ib() -reveal_type(C) # E: Revealed type is 'def (a: builtins.int, b: builtins.str, c: builtins.bool) -> __main__.C' +reveal_type(C) # N: Revealed type is 'def (a: builtins.int, b: builtins.str, c: builtins.bool) -> __main__.C' [builtins fixtures/bool.pyi] [case testAttrsNestedInClasses] @@ -267,8 +267,8 @@ class C: @attr.s class D: x: int = attr.ib() -reveal_type(C) # E: Revealed type is 'def (y: Any) -> __main__.C' -reveal_type(C.D) # E: Revealed type is 'def (x: builtins.int) -> __main__.C.D' +reveal_type(C) # N: Revealed type is 'def (y: Any) -> __main__.C' +reveal_type(C.D) # N: Revealed type is 'def (x: builtins.int) -> __main__.C.D' [builtins fixtures/bool.pyi] [case testAttrsInheritanceOverride] @@ -289,9 +289,9 @@ class C(B): c: bool = attr.ib() # No error here because the x below overwrites the x above. x: int = attr.ib() -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, x: builtins.int) -> __main__.A' -reveal_type(B) # E: Revealed type is 'def (a: builtins.int, b: builtins.str, x: builtins.int =) -> __main__.B' -reveal_type(C) # E: Revealed type is 'def (a: builtins.int, b: builtins.str, c: builtins.bool, x: builtins.int) -> __main__.C' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, x: builtins.int) -> __main__.A' +reveal_type(B) # N: Revealed type is 'def (a: builtins.int, b: builtins.str, x: builtins.int =) -> __main__.B' +reveal_type(C) # N: Revealed type is 'def (a: builtins.int, b: builtins.str, c: builtins.bool, x: builtins.int) -> __main__.C' [builtins fixtures/bool.pyi] [case testAttrsTypeEquals] @@ -301,7 +301,7 @@ import attr class A: a = attr.ib(type=int) b = attr.ib(18, type=int) -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.int =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.int =) -> __main__.A' [builtins fixtures/bool.pyi] [case testAttrsFrozen] @@ -326,7 +326,7 @@ class A: _d: int = attr.ib(validator=None, default=18) E = 7 F: ClassVar[int] = 22 -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.str], c: builtins.str =, d: builtins.int =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.list[builtins.str], c: builtins.str =, d: builtins.int =) -> __main__.A' A(1, ['2']) [builtins fixtures/list.pyi] @@ -339,7 +339,7 @@ class A: Alias2 = List[str] x: Alias y: Alias2 = attr.ib() -reveal_type(A) # E: Revealed type is 'def (x: builtins.list[builtins.int], y: builtins.list[builtins.str]) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (x: builtins.list[builtins.int], y: builtins.list[builtins.str]) -> __main__.A' [builtins fixtures/list.pyi] [case testAttrsGeneric] @@ -356,11 +356,11 @@ class A(Generic[T]): return self.x[0] def problem(self) -> T: return self.x # E: Incompatible return value type (got "List[T]", expected "T") -reveal_type(A) # E: Revealed type is 'def [T] (x: builtins.list[T`1], y: T`1) -> __main__.A[T`1]' +reveal_type(A) # N: Revealed type is 'def [T] (x: builtins.list[T`1], y: T`1) -> __main__.A[T`1]' a = A([1], 2) -reveal_type(a) # E: Revealed type is '__main__.A[builtins.int*]' -reveal_type(a.x) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(a.y) # E: Revealed type is 'builtins.int*' +reveal_type(a) # N: Revealed type is '__main__.A[builtins.int*]' +reveal_type(a.x) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(a.y) # N: Revealed type is 'builtins.int*' A(['str'], 7) # E: Cannot infer type argument 1 of "A" A([1], '2') # E: Cannot infer type argument 1 of "A" @@ -376,7 +376,7 @@ class A(Generic[T]): x: Optional[T] @classmethod def clsmeth(cls) -> None: - reveal_type(cls) # E: Revealed type is 'Type[__main__.A[T`1]]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.A[T`1]]' [builtins fixtures/classmethod.pyi] @@ -390,8 +390,8 @@ class A: class B: parent: A -reveal_type(A) # E: Revealed type is 'def (parent: __main__.B) -> __main__.A' -reveal_type(B) # E: Revealed type is 'def (parent: __main__.A) -> __main__.B' +reveal_type(A) # N: Revealed type is 'def (parent: __main__.B) -> __main__.A' +reveal_type(B) # N: Revealed type is 'def (parent: __main__.A) -> __main__.B' A(B(None)) [builtins fixtures/list.pyi] @@ -405,14 +405,14 @@ class A: class B: parent: A -reveal_type(A) # E: Revealed type is 'def (parent: __main__.A.B) -> __main__.A' -reveal_type(A.B) # E: Revealed type is 'def (parent: __main__.A) -> __main__.A.B' +reveal_type(A) # N: Revealed type is 'def (parent: __main__.A.B) -> __main__.A' +reveal_type(A.B) # N: Revealed type is 'def (parent: __main__.A) -> __main__.A.B' A(A.B(None)) [builtins fixtures/list.pyi] [case testAttrsImporting] from helper import A -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.str) -> helper.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.str) -> helper.A' [file helper.py] import attr @attr.s(auto_attribs=True) @@ -429,16 +429,16 @@ class A: b: str = attr.ib() @classmethod def new(cls) -> A: - reveal_type(cls) # E: Revealed type is 'Type[__main__.A]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.A]' return cls(6, 'hello') @classmethod def bad(cls) -> A: return cls(17) # E: Too few arguments for "A" def foo(self) -> int: return self.a -reveal_type(A) # E: Revealed type is 'def (a: builtins.int, b: builtins.str) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int, b: builtins.str) -> __main__.A' a = A.new() -reveal_type(a.foo) # E: Revealed type is 'def () -> builtins.int' +reveal_type(a.foo) # N: Revealed type is 'def () -> builtins.int' [builtins fixtures/classmethod.pyi] [case testAttrsOtherOverloads] @@ -464,12 +464,12 @@ class A: @classmethod def foo(cls, x: Union[int, str]) -> Union[int, str]: - reveal_type(cls) # E: Revealed type is 'Type[__main__.A]' - reveal_type(cls.other()) # E: Revealed type is 'builtins.str' + reveal_type(cls) # N: Revealed type is 'Type[__main__.A]' + reveal_type(cls.other()) # N: Revealed type is 'builtins.str' return x -reveal_type(A.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(A.foo("foo")) # E: Revealed type is 'builtins.str' +reveal_type(A.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(A.foo("foo")) # N: Revealed type is 'builtins.str' [builtins fixtures/classmethod.pyi] @@ -524,8 +524,8 @@ class B: AOrB = Union[A, B] -reveal_type(A) # E: Revealed type is 'def (frob: builtins.list[Union[__main__.A, __main__.B]]) -> __main__.A' -reveal_type(B) # E: Revealed type is 'def () -> __main__.B' +reveal_type(A) # N: Revealed type is 'def (frob: builtins.list[Union[__main__.A, __main__.B]]) -> __main__.A' +reveal_type(B) # N: Revealed type is 'def () -> __main__.B' A([B()]) [builtins fixtures/list.pyi] @@ -541,8 +541,8 @@ class C: x: str = attr.ib(convert=convert) # E: convert is deprecated, use converter # Because of the convert the __init__ takes an int, but the variable is a str. -reveal_type(C) # E: Revealed type is 'def (x: builtins.int) -> __main__.C' -reveal_type(C(15).x) # E: Revealed type is 'builtins.str' +reveal_type(C) # N: Revealed type is 'def (x: builtins.int) -> __main__.C' +reveal_type(C(15).x) # N: Revealed type is 'builtins.str' [builtins fixtures/list.pyi] [case testAttrsUsingConverter] @@ -558,8 +558,8 @@ class C: y: str = attr.ib(converter=converter2) # Because of the converter the __init__ takes an int, but the variable is a str. -reveal_type(C) # E: Revealed type is 'def (x: builtins.int, y: builtins.int) -> __main__.C' -reveal_type(C(15, 16).x) # E: Revealed type is 'builtins.str' +reveal_type(C) # N: Revealed type is 'def (x: builtins.int, y: builtins.int) -> __main__.C' +reveal_type(C(15, 16).x) # N: Revealed type is 'builtins.str' [file helper.py] def converter(s:int) -> str: return 'hello' @@ -603,7 +603,7 @@ main:16: error: Cannot determine __init__ type from converter main:16: error: Argument "converter" has incompatible type "Callable[[], str]"; expected "Callable[[Any], str]" main:17: error: Cannot determine __init__ type from converter main:17: error: Argument "converter" has incompatible type overloaded function; expected "Callable[[Any], int]" -main:18: error: Revealed type is 'def (bad: Any, bad_overloaded: Any) -> __main__.A' +main:18: note: Revealed type is 'def (bad: Any, bad_overloaded: Any) -> __main__.A' [builtins fixtures/list.pyi] [case testAttrsUsingUnsupportedConverter] @@ -619,7 +619,7 @@ class C: x: str = attr.ib(converter=thing.do_it) # E: Unsupported converter, only named functions and types are currently supported y: str = attr.ib(converter=lambda x: x) # E: Unsupported converter, only named functions and types are currently supported z: str = attr.ib(converter=factory(8)) # E: Unsupported converter, only named functions and types are currently supported -reveal_type(C) # E: Revealed type is 'def (x: Any, y: Any, z: Any) -> __main__.C' +reveal_type(C) # N: Revealed type is 'def (x: Any, y: Any, z: Any) -> __main__.C' [builtins fixtures/list.pyi] [case testAttrsUsingConverterAndSubclass] @@ -637,8 +637,8 @@ class A(C): pass # Because of the convert the __init__ takes an int, but the variable is a str. -reveal_type(A) # E: Revealed type is 'def (x: builtins.int) -> __main__.A' -reveal_type(A(15).x) # E: Revealed type is 'builtins.str' +reveal_type(A) # N: Revealed type is 'def (x: builtins.int) -> __main__.A' +reveal_type(A(15).x) # N: Revealed type is 'builtins.str' [builtins fixtures/list.pyi] [case testAttrsUsingConverterWithTypes] @@ -670,10 +670,10 @@ class C(A, B): pass @attr.s class D(A): pass -reveal_type(A.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(B.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(C.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(D.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(B.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(C.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(D.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' A() < A() B() < B() @@ -717,8 +717,8 @@ class C: @attr.s class A(C): z: int = attr.ib(default=18) -reveal_type(C) # E: Revealed type is 'def (x: builtins.int =, y: builtins.int =) -> __main__.C' -reveal_type(A) # E: Revealed type is 'def (x: builtins.int =, y: builtins.int =, z: builtins.int =) -> __main__.A' +reveal_type(C) # N: Revealed type is 'def (x: builtins.int =, y: builtins.int =) -> __main__.C' +reveal_type(A) # N: Revealed type is 'def (x: builtins.int =, y: builtins.int =, z: builtins.int =) -> __main__.A' [builtins fixtures/list.pyi] [case testAttrsMultiAssign] @@ -726,7 +726,7 @@ import attr @attr.s class A: x, y, z = attr.ib(), attr.ib(type=int), attr.ib(default=17) -reveal_type(A) # E: Revealed type is 'def (x: Any, y: builtins.int, z: Any =) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (x: Any, y: builtins.int, z: Any =) -> __main__.A' [builtins fixtures/list.pyi] [case testAttrsMultiAssign2] @@ -764,19 +764,19 @@ class A: a = attr.ib(default=8) b = attr.ib() a = attr.ib() -reveal_type(A) # E: Revealed type is 'def (b: Any, a: Any) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (b: Any, a: Any) -> __main__.A' @attr.s class B: a: int = attr.ib(default=8) b: int = attr.ib() a: int = attr.ib() # E: Name 'a' already defined on line 10 -reveal_type(B) # E: Revealed type is 'def (b: builtins.int, a: builtins.int) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (b: builtins.int, a: builtins.int) -> __main__.B' @attr.s(auto_attribs=True) class C: a: int = 8 b: int a: int = attr.ib() # E: Name 'a' already defined on line 16 -reveal_type(C) # E: Revealed type is 'def (a: builtins.int, b: builtins.int) -> __main__.C' +reveal_type(C) # N: Revealed type is 'def (a: builtins.int, b: builtins.int) -> __main__.C' [builtins fixtures/bool.pyi] [case testAttrsNewStyleClassPy2] @@ -1036,7 +1036,7 @@ class B: class C(List[C]): pass -reveal_type(B) # E: Revealed type is 'def (x: __main__.C) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (x: __main__.C) -> __main__.B' [builtins fixtures/list.pyi] [case testDisallowUntypedWorksForwardBad] @@ -1047,5 +1047,5 @@ import attr class B: # E: Function is missing a type annotation for one or more arguments x = attr.ib() # E: Need type annotation for 'x' -reveal_type(B) # E: Revealed type is 'def (x: Any) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (x: Any) -> __main__.B' [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-basic.test b/test-data/unit/check-basic.test index 4267c7e4bbd1..fa13f6d5d7bd 100644 --- a/test-data/unit/check-basic.test +++ b/test-data/unit/check-basic.test @@ -368,7 +368,7 @@ def foo( [case testNoneHasBool] none = None b = none.__bool__() -reveal_type(b) # E: Revealed type is 'builtins.bool' +reveal_type(b) # N: Revealed type is 'builtins.bool' [builtins fixtures/bool.pyi] [case testAssignmentInvariantNoteForList] diff --git a/test-data/unit/check-bound.test b/test-data/unit/check-bound.test index 7fa778bdaf74..d8f3f6bb95c3 100644 --- a/test-data/unit/check-bound.test +++ b/test-data/unit/check-bound.test @@ -55,7 +55,7 @@ class C(Generic[T]): c1 = None # type: C[None] c1.get() d = c1.get() -reveal_type(d) # E: Revealed type is 'None' +reveal_type(d) # N: Revealed type is 'None' [case testBoundAny] @@ -82,7 +82,7 @@ def f(g: Callable[[], T]) -> T: def h() -> None: pass f(h) a = f(h) -reveal_type(a) # E: Revealed type is 'None' +reveal_type(a) # N: Revealed type is 'None' [case testBoundInheritance] diff --git a/test-data/unit/check-callable.test b/test-data/unit/check-callable.test index 447c74f50c0e..93aa0ce6eedf 100644 --- a/test-data/unit/check-callable.test +++ b/test-data/unit/check-callable.test @@ -188,9 +188,9 @@ from typing import Any x = 5 # type: Any if callable(x): - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' else: - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' [builtins fixtures/callable.pyi] [case testCallableCallableClasses] @@ -217,9 +217,9 @@ if not callable(b): 5 + 'test' if callable(c): - reveal_type(c) # E: Revealed type is '__main__.B' + reveal_type(c) # N: Revealed type is '__main__.B' else: - reveal_type(c) # E: Revealed type is '__main__.A' + reveal_type(c) # N: Revealed type is '__main__.A' [builtins fixtures/callable.pyi] @@ -230,9 +230,9 @@ T = Union[Union[int, Callable[[], int]], Union[str, Callable[[], str]]] def f(t: T) -> None: if callable(t): - reveal_type(t()) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(t()) # N: Revealed type is 'Union[builtins.int, builtins.str]' else: - reveal_type(t) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(t) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/callable.pyi] @@ -256,11 +256,11 @@ T = TypeVar('T', int, Callable[[], int], Union[str, Callable[[], str]]) def f(t: T) -> None: if callable(t): - reveal_type(t()) # E: Revealed type is 'Any' \ - # E: Revealed type is 'builtins.int' \ - # E: Revealed type is 'builtins.str' + reveal_type(t()) # N: Revealed type is 'Any' \ + # N: Revealed type is 'builtins.int' \ + # N: Revealed type is 'builtins.str' else: - reveal_type(t) # E: Revealed type is 'builtins.int*' # E: Revealed type is 'builtins.str' + reveal_type(t) # N: Revealed type is 'builtins.int*' # N: Revealed type is 'builtins.str' [builtins fixtures/callable.pyi] @@ -356,7 +356,7 @@ def f(o: object) -> None: o(1,2,3) 1 + 'boom' # E: Unsupported operand types for + ("int" and "str") o('hi') + 12 - reveal_type(o) # E: Revealed type is '__main__.' + reveal_type(o) # N: Revealed type is '__main__.' [builtins fixtures/callable.pyi] diff --git a/test-data/unit/check-class-namedtuple.test b/test-data/unit/check-class-namedtuple.test index 888e84586096..fb6aa73fcf66 100644 --- a/test-data/unit/check-class-namedtuple.test +++ b/test-data/unit/check-class-namedtuple.test @@ -279,7 +279,7 @@ class X(NamedTuple): y: Any x: X -reveal_type(x._asdict()) # E: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(x._asdict()) # N: Revealed type is 'builtins.dict[builtins.str, Any]' [builtins fixtures/dict.pyi] @@ -292,7 +292,7 @@ class X(NamedTuple): y: str x: X -reveal_type(x._replace()) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' +reveal_type(x._replace()) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' x._replace(x=5) x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str" @@ -304,10 +304,10 @@ class X(NamedTuple): x: int y: str -reveal_type(X._fields) # E: Revealed type is 'Tuple[builtins.str, builtins.str]' -reveal_type(X._field_types) # E: Revealed type is 'builtins.dict[builtins.str, Any]' -reveal_type(X._field_defaults) # E: Revealed type is 'builtins.dict[builtins.str, Any]' -reveal_type(X.__annotations__) # E: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(X._fields) # N: Revealed type is 'Tuple[builtins.str, builtins.str]' +reveal_type(X._field_types) # N: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(X._field_defaults) # N: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(X.__annotations__) # N: Revealed type is 'builtins.dict[builtins.str, Any]' [builtins fixtures/dict.pyi] @@ -333,7 +333,7 @@ class Y(NamedTuple): x: int y: str -reveal_type([X(3, 'b'), Y(1, 'a')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' [builtins fixtures/list.pyi] @@ -345,8 +345,8 @@ class X(NamedTuple): x: int y: str -reveal_type([(3, 'b'), X(1, 'a')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' -reveal_type([X(1, 'a'), (3, 'b')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' [builtins fixtures/list.pyi] @@ -409,8 +409,8 @@ class X(NamedTuple): x: int y: int = 2 -reveal_type(X(1)) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.X]' -reveal_type(X(1, 2)) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.X]' +reveal_type(X(1)) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.X]' +reveal_type(X(1, 2)) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.X]' X(1, 'a') # E: Argument 2 to "X" has incompatible type "str"; expected "int" X(1, z=3) # E: Unexpected keyword argument "z" for "X" @@ -419,14 +419,14 @@ class HasNone(NamedTuple): x: int y: Optional[int] = None -reveal_type(HasNone(1)) # E: Revealed type is 'Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]' +reveal_type(HasNone(1)) # N: Revealed type is 'Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]' class Parameterized(NamedTuple): x: int y: List[int] = [1] + [2] z: List[int] = [] -reveal_type(Parameterized(1)) # E: Revealed type is 'Tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]' +reveal_type(Parameterized(1)) # N: Revealed type is 'Tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]' Parameterized(1, ['not an int']) # E: List item 0 has incompatible type "str"; expected "int" class Default: @@ -435,8 +435,8 @@ class Default: class UserDefined(NamedTuple): x: Default = Default() -reveal_type(UserDefined()) # E: Revealed type is 'Tuple[__main__.Default, fallback=__main__.UserDefined]' -reveal_type(UserDefined(Default())) # E: Revealed type is 'Tuple[__main__.Default, fallback=__main__.UserDefined]' +reveal_type(UserDefined()) # N: Revealed type is 'Tuple[__main__.Default, fallback=__main__.UserDefined]' +reveal_type(UserDefined(Default())) # N: Revealed type is 'Tuple[__main__.Default, fallback=__main__.UserDefined]' UserDefined(1) # E: Argument 1 to "UserDefined" has incompatible type "int"; expected "Default" [builtins fixtures/list.pyi] @@ -449,7 +449,7 @@ class HasNone(NamedTuple): x: int y: Optional[int] = None -reveal_type(HasNone(1)) # E: Revealed type is 'Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]' +reveal_type(HasNone(1)) # N: Revealed type is 'Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]' HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int" HasNone(1, y=None) HasNone(1, y=2) @@ -488,7 +488,7 @@ class Y(X): self.y return self.x -reveal_type(Y('a')) # E: Revealed type is 'Tuple[builtins.str, builtins.int, fallback=__main__.Y]' +reveal_type(Y('a')) # N: Revealed type is 'Tuple[builtins.str, builtins.int, fallback=__main__.Y]' Y(y=1, x='1').method() class CallsBaseInit(X): @@ -513,11 +513,11 @@ class XRepr(NamedTuple): def __add__(self, other: XRepr) -> int: return 0 -reveal_type(XMeth(1).double()) # E: Revealed type is 'builtins.int' -reveal_type(XMeth(1).asyncdouble()) # E: Revealed type is 'typing.Coroutine[Any, Any, builtins.int]' -reveal_type(XMeth(42).x) # E: Revealed type is 'builtins.int' -reveal_type(XRepr(42).__str__()) # E: Revealed type is 'builtins.str' -reveal_type(XRepr(1, 2).__add__(XRepr(3))) # E: Revealed type is 'builtins.int' +reveal_type(XMeth(1).double()) # N: Revealed type is 'builtins.int' +reveal_type(XMeth(1).asyncdouble()) # N: Revealed type is 'typing.Coroutine[Any, Any, builtins.int]' +reveal_type(XMeth(42).x) # N: Revealed type is 'builtins.int' +reveal_type(XRepr(42).__str__()) # N: Revealed type is 'builtins.str' +reveal_type(XRepr(1, 2).__add__(XRepr(3))) # N: Revealed type is 'builtins.int' [typing fixtures/typing-full.pyi] [case testNewNamedTupleOverloading] @@ -532,8 +532,8 @@ class Overloader(NamedTuple): def method(self, y): return y -reveal_type(Overloader(1).method('string')) # E: Revealed type is 'builtins.str' -reveal_type(Overloader(1).method(1)) # E: Revealed type is 'builtins.int' +reveal_type(Overloader(1).method('string')) # N: Revealed type is 'builtins.str' +reveal_type(Overloader(1).method(1)) # N: Revealed type is 'builtins.int' Overloader(1).method(('tuple',)) # E: No overload variant of "method" of "Overloader" matches argument type "Tuple[str]" \ # N: Possible overload variants: \ # N: def method(self, y: str) -> str \ @@ -547,26 +547,26 @@ T = TypeVar('T') class Base(NamedTuple): x: int def copy(self: T) -> T: - reveal_type(self) # E: Revealed type is 'T`-1' + reveal_type(self) # N: Revealed type is 'T`-1' return self def good_override(self) -> int: - reveal_type(self) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.Base]' - reveal_type(self[0]) # E: Revealed type is 'builtins.int' + reveal_type(self) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.Base]' + reveal_type(self[0]) # N: Revealed type is 'builtins.int' self[0] = 3 # E: Unsupported target for indexed assignment - reveal_type(self.x) # E: Revealed type is 'builtins.int' + reveal_type(self.x) # N: Revealed type is 'builtins.int' self.x = 3 # E: Property "x" defined in "Base" is read-only self[1] # E: Tuple index out of range - reveal_type(self[T]) # E: Revealed type is 'builtins.int' + reveal_type(self[T]) # N: Revealed type is 'builtins.int' return self.x def bad_override(self) -> int: return self.x class Child(Base): def new_method(self) -> int: - reveal_type(self) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.Child]' - reveal_type(self[0]) # E: Revealed type is 'builtins.int' + reveal_type(self) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.Child]' + reveal_type(self[0]) # N: Revealed type is 'builtins.int' self[0] = 3 # E: Unsupported target for indexed assignment - reveal_type(self.x) # E: Revealed type is 'builtins.int' + reveal_type(self.x) # N: Revealed type is 'builtins.int' self.x = 3 # E: Property "x" defined in "Base" is read-only self[1] # E: Tuple index out of range return self.x @@ -578,13 +578,13 @@ class Child(Base): def takes_base(base: Base) -> int: return base.x -reveal_type(Base(1).copy()) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.Base]' -reveal_type(Child(1).copy()) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.Child]' -reveal_type(Base(1).good_override()) # E: Revealed type is 'builtins.int' -reveal_type(Child(1).good_override()) # E: Revealed type is 'builtins.int' -reveal_type(Base(1).bad_override()) # E: Revealed type is 'builtins.int' -reveal_type(takes_base(Base(1))) # E: Revealed type is 'builtins.int' -reveal_type(takes_base(Child(1))) # E: Revealed type is 'builtins.int' +reveal_type(Base(1).copy()) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.Base]' +reveal_type(Child(1).copy()) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.Child]' +reveal_type(Base(1).good_override()) # N: Revealed type is 'builtins.int' +reveal_type(Child(1).good_override()) # N: Revealed type is 'builtins.int' +reveal_type(Base(1).bad_override()) # N: Revealed type is 'builtins.int' +reveal_type(takes_base(Base(1))) # N: Revealed type is 'builtins.int' +reveal_type(takes_base(Child(1))) # N: Revealed type is 'builtins.int' [builtins fixtures/tuple.pyi] [case testNewNamedTupleIllegalNames] @@ -633,15 +633,15 @@ class Documented(NamedTuple): """This is a docstring.""" x: int -reveal_type(Documented.__doc__) # E: Revealed type is 'builtins.str' -reveal_type(Documented(1).x) # E: Revealed type is 'builtins.int' +reveal_type(Documented.__doc__) # N: Revealed type is 'builtins.str' +reveal_type(Documented(1).x) # N: Revealed type is 'builtins.int' class BadDoc(NamedTuple): x: int def __doc__(self) -> str: return '' -reveal_type(BadDoc(1).__doc__()) # E: Revealed type is 'builtins.str' +reveal_type(BadDoc(1).__doc__()) # N: Revealed type is 'builtins.str' [case testNewNamedTupleClassMethod] from typing import NamedTuple @@ -651,8 +651,8 @@ class HasClassMethod(NamedTuple): @classmethod def new(cls, f: str) -> 'HasClassMethod': - reveal_type(cls) # E: Revealed type is 'Type[Tuple[builtins.str, fallback=__main__.HasClassMethod]]' - reveal_type(HasClassMethod) # E: Revealed type is 'def (x: builtins.str) -> Tuple[builtins.str, fallback=__main__.HasClassMethod]' + reveal_type(cls) # N: Revealed type is 'Type[Tuple[builtins.str, fallback=__main__.HasClassMethod]]' + reveal_type(HasClassMethod) # N: Revealed type is 'def (x: builtins.str) -> Tuple[builtins.str, fallback=__main__.HasClassMethod]' return cls(x=f) [builtins fixtures/classmethod.pyi] @@ -677,7 +677,7 @@ class HasStaticMethod(NamedTuple): @property def size(self) -> int: - reveal_type(self) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.HasStaticMethod]' + reveal_type(self) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.HasStaticMethod]' return 4 [builtins fixtures/property.pyi] diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index c18e8da0a375..a536b9d42978 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -239,7 +239,7 @@ class A(object): class B(object): attr = 0 def f(self) -> None: - reveal_type(self.attr) # E: Revealed type is 'builtins.int' + reveal_type(self.attr) # N: Revealed type is 'builtins.int' [out] @@ -362,7 +362,7 @@ class B(Generic[T]): def __new__(cls, foo: T) -> 'B[T]': x = object.__new__(cls) # object.__new__ doesn't have a great type :( - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' return x [builtins fixtures/__new__.pyi] @@ -995,16 +995,16 @@ if int(): class Outer: class Inner: def make_int(self) -> int: return 1 - reveal_type(Inner().make_int) # E: Revealed type is 'def () -> builtins.int' + reveal_type(Inner().make_int) # N: Revealed type is 'def () -> builtins.int' some_int = Inner().make_int() -reveal_type(Outer.Inner.make_int) # E: Revealed type is 'def (self: __main__.Outer.Inner) -> builtins.int' -reveal_type(Outer().some_int) # E: Revealed type is 'builtins.int' +reveal_type(Outer.Inner.make_int) # N: Revealed type is 'def (self: __main__.Outer.Inner) -> builtins.int' +reveal_type(Outer().some_int) # N: Revealed type is 'builtins.int' Bar = Outer.Inner -reveal_type(Bar.make_int) # E: Revealed type is 'def (self: __main__.Outer.Inner) -> builtins.int' +reveal_type(Bar.make_int) # N: Revealed type is 'def (self: __main__.Outer.Inner) -> builtins.int' x = Bar() # type: Bar def produce() -> Bar: - reveal_type(Bar().make_int) # E: Revealed type is 'def () -> builtins.int' + reveal_type(Bar().make_int) # N: Revealed type is 'def () -> builtins.int' return Bar() [case testInnerClassPropertyAccess] @@ -1013,14 +1013,14 @@ class Foo: name = 'Bar' meta = Meta -reveal_type(Foo.Meta) # E: Revealed type is 'def () -> __main__.Foo.Meta' -reveal_type(Foo.meta) # E: Revealed type is 'def () -> __main__.Foo.Meta' -reveal_type(Foo.Meta.name) # E: Revealed type is 'builtins.str' -reveal_type(Foo.meta.name) # E: Revealed type is 'builtins.str' -reveal_type(Foo().Meta) # E: Revealed type is 'def () -> __main__.Foo.Meta' -reveal_type(Foo().meta) # E: Revealed type is 'def () -> __main__.Foo.Meta' -reveal_type(Foo().meta.name) # E: Revealed type is 'builtins.str' -reveal_type(Foo().Meta.name) # E: Revealed type is 'builtins.str' +reveal_type(Foo.Meta) # N: Revealed type is 'def () -> __main__.Foo.Meta' +reveal_type(Foo.meta) # N: Revealed type is 'def () -> __main__.Foo.Meta' +reveal_type(Foo.Meta.name) # N: Revealed type is 'builtins.str' +reveal_type(Foo.meta.name) # N: Revealed type is 'builtins.str' +reveal_type(Foo().Meta) # N: Revealed type is 'def () -> __main__.Foo.Meta' +reveal_type(Foo().meta) # N: Revealed type is 'def () -> __main__.Foo.Meta' +reveal_type(Foo().meta.name) # N: Revealed type is 'builtins.str' +reveal_type(Foo().Meta.name) # N: Revealed type is 'builtins.str' -- Declaring attribute type in method -- ---------------------------------- @@ -1217,7 +1217,7 @@ class A: @property def f(self) -> str: pass a = A() -reveal_type(a.f) # E: Revealed type is 'builtins.str' +reveal_type(a.f) # N: Revealed type is 'builtins.str' [builtins fixtures/property.pyi] [case testAssigningToReadOnlyProperty] @@ -1277,7 +1277,7 @@ a.f = a.f a.f.x # E: "int" has no attribute "x" a.f = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") a.f = 1 -reveal_type(a.f) # E: Revealed type is 'builtins.int' +reveal_type(a.f) # N: Revealed type is 'builtins.int' [builtins fixtures/property.pyi] [case testPropertyWithDeleterButNoSetter] @@ -1305,7 +1305,7 @@ class D: class A: f = D() a = A() -reveal_type(a.f) # E: Revealed type is 'builtins.str' +reveal_type(a.f) # N: Revealed type is 'builtins.str' [case testSettingNonDataDescriptor] from typing import Any @@ -1336,15 +1336,15 @@ class A: f = D() def __init__(self): self.f = 's' a = A() -reveal_type(a.f) # E: Revealed type is '__main__.D' +reveal_type(a.f) # N: Revealed type is '__main__.D' [case testAccessingDescriptorFromClass] # flags: --strict-optional from d import D, Base class A(Base): f = D() -reveal_type(A.f) # E: Revealed type is 'd.D' -reveal_type(A().f) # E: Revealed type is 'builtins.str' +reveal_type(A.f) # N: Revealed type is 'd.D' +reveal_type(A().f) # N: Revealed type is 'builtins.str' [file d.pyi] from typing import TypeVar, Type, Generic, overload class Base: pass @@ -1374,9 +1374,9 @@ class D: def __get__(self, inst: Base, own: Type[Base]) -> str: pass [builtins fixtures/bool.pyi] [out] -main:5: error: Revealed type is 'd.D' +main:5: note: Revealed type is 'd.D' main:5: error: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "Type[Base]" -main:6: error: Revealed type is 'Any' +main:6: note: Revealed type is 'Any' main:6: error: No overload variant of "__get__" of "D" matches argument types "A", "Type[A]" main:6: note: Possible overload variants: main:6: note: def __get__(self, inst: None, own: Type[Base]) -> D @@ -1393,8 +1393,8 @@ class A: f = D(10) g = D('10') a = A() -reveal_type(a.f) # E: Revealed type is 'builtins.int*' -reveal_type(a.g) # E: Revealed type is 'builtins.str*' +reveal_type(a.f) # N: Revealed type is 'builtins.int*' +reveal_type(a.g) # N: Revealed type is 'builtins.str*' [case testSettingGenericDataDescriptor] from typing import TypeVar, Type, Generic, Any @@ -1418,10 +1418,10 @@ from d import D class A: f = D(10) # type: D[A, int] g = D('10') # type: D[A, str] -reveal_type(A.f) # E: Revealed type is 'd.D[__main__.A*, builtins.int*]' -reveal_type(A.g) # E: Revealed type is 'd.D[__main__.A*, builtins.str*]' -reveal_type(A().f) # E: Revealed type is 'builtins.int*' -reveal_type(A().g) # E: Revealed type is 'builtins.str*' +reveal_type(A.f) # N: Revealed type is 'd.D[__main__.A*, builtins.int*]' +reveal_type(A.g) # N: Revealed type is 'd.D[__main__.A*, builtins.str*]' +reveal_type(A().f) # N: Revealed type is 'builtins.int*' +reveal_type(A().g) # N: Revealed type is 'builtins.str*' [file d.pyi] from typing import TypeVar, Type, Generic, overload T = TypeVar('T') @@ -1456,8 +1456,8 @@ class D(Generic[T, V]): def __get__(self, inst: T, own: Type[T]) -> V: pass [builtins fixtures/bool.pyi] [out] -main:8: error: Revealed type is 'd.D[__main__.A*, builtins.int*]' -main:9: error: Revealed type is 'd.D[__main__.A*, builtins.str*]' +main:8: note: Revealed type is 'd.D[__main__.A*, builtins.int*]' +main:9: note: Revealed type is 'd.D[__main__.A*, builtins.str*]' [case testAccessingGenericDescriptorFromClassBadOverload] # flags: --strict-optional @@ -1477,7 +1477,7 @@ class D(Generic[T, V]): def __get__(self, inst: T, own: Type[T]) -> V: pass [builtins fixtures/bool.pyi] [out] -main:5: error: Revealed type is 'Any' +main:5: note: Revealed type is 'Any' main:5: error: No overload variant of "__get__" of "D" matches argument types "None", "Type[A]" main:5: note: Possible overload variants: main:5: note: def __get__(self, inst: None, own: None) -> D[A, int] @@ -1492,7 +1492,7 @@ class D(C): pass class A: f = D() a = A() -reveal_type(a.f) # E: Revealed type is 'builtins.str' +reveal_type(a.f) # N: Revealed type is 'builtins.str' [case testSettingDataDescriptorSubclass] from typing import Any @@ -1515,7 +1515,7 @@ class A: f = D() def __init__(self): self.f = 's' a = A() -reveal_type(a.f) # E: Revealed type is '__main__.D' +reveal_type(a.f) # N: Revealed type is '__main__.D' [case testAccessingGenericNonDataDescriptorSubclass] from typing import TypeVar, Type, Generic, Any @@ -1528,8 +1528,8 @@ class A: f = D(10) g = D('10') a = A() -reveal_type(a.f) # E: Revealed type is 'builtins.int*' -reveal_type(a.g) # E: Revealed type is 'builtins.str*' +reveal_type(a.f) # N: Revealed type is 'builtins.int*' +reveal_type(a.g) # N: Revealed type is 'builtins.str*' [case testSettingGenericDataDescriptorSubclass] from typing import TypeVar, Type, Generic @@ -1651,7 +1651,7 @@ class A: f = D() a = A() a.f = 1 -reveal_type(a.f) # E: Revealed type is 'builtins.str' +reveal_type(a.f) # N: Revealed type is 'builtins.str' [case testDescriptorGetUnion] from typing import Any, Union @@ -1666,7 +1666,7 @@ class B: attr = String() def foo(x: Union[A, B]) -> None: - reveal_type(x.attr) # E: Revealed type is 'builtins.str' + reveal_type(x.attr) # N: Revealed type is 'builtins.str' -- _promote decorators -- ------------------- @@ -1774,8 +1774,8 @@ class B(A): pass A() + A() # E: Unsupported operand types for + ("A" and "A") # Here, Python *will* call __radd__(...) -reveal_type(B() + A()) # E: Revealed type is '__main__.A' -reveal_type(A() + B()) # E: Revealed type is '__main__.A' +reveal_type(B() + A()) # N: Revealed type is '__main__.A' +reveal_type(A() + B()) # N: Revealed type is '__main__.A' [builtins fixtures/isinstance.pyi] [case testOperatorMethodOverrideWithIdenticalOverloadedType] @@ -1894,8 +1894,8 @@ class A: def __lt__(self, other: object) -> bool: ... # Not all operators have the above shortcut though. -reveal_type(A() > A()) # E: Revealed type is 'builtins.bool' -reveal_type(A() < A()) # E: Revealed type is 'builtins.bool' +reveal_type(A() > A()) # N: Revealed type is 'builtins.bool' +reveal_type(A() < A()) # N: Revealed type is 'builtins.bool' [builtins fixtures/bool.pyi] [case testReverseOperatorOrderingCase3] @@ -1906,7 +1906,7 @@ class B: def __radd__(self, other: A) -> str: ... # E: Signatures of "__radd__" of "B" and "__add__" of "A" are unsafely overlapping # Normally, we try calling __add__ before __radd__ -reveal_type(A() + B()) # E: Revealed type is 'builtins.int' +reveal_type(A() + B()) # N: Revealed type is 'builtins.int' [case testReverseOperatorOrderingCase4] class A: @@ -1916,7 +1916,7 @@ class B(A): def __radd__(self, other: A) -> str: ... # E: Signatures of "__radd__" of "B" and "__add__" of "A" are unsafely overlapping # However, if B is a subtype of A, we try calling __radd__ first. -reveal_type(A() + B()) # E: Revealed type is 'builtins.str' +reveal_type(A() + B()) # N: Revealed type is 'builtins.str' [case testReverseOperatorOrderingCase5] # Note: these two methods are not unsafely overlapping because __radd__ is @@ -1928,7 +1928,7 @@ class A: class B(A): pass # ...but only if B specifically defines a new __radd__. -reveal_type(A() + B()) # E: Revealed type is 'builtins.int' +reveal_type(A() + B()) # N: Revealed type is 'builtins.int' [case testReverseOperatorOrderingCase6] class A: @@ -1940,7 +1940,7 @@ class B(A): # unsafe overlap check kicks in here. def __radd__(self, other: A) -> str: ... # E: Signatures of "__radd__" of "B" and "__add__" of "A" are unsafely overlapping -reveal_type(A() + B()) # E: Revealed type is 'builtins.str' +reveal_type(A() + B()) # N: Revealed type is 'builtins.str' [case testReverseOperatorOrderingCase7] class A: @@ -1953,7 +1953,7 @@ class B(A): class C(B): pass # A refinement made by a parent also counts -reveal_type(A() + C()) # E: Revealed type is 'builtins.str' +reveal_type(A() + C()) # N: Revealed type is 'builtins.str' [case testReverseOperatorWithOverloads1] from typing import overload @@ -1971,8 +1971,8 @@ class C: def __radd__(self, other: B) -> str: ... # E: Signatures of "__radd__" of "C" and "__add__" of "B" are unsafely overlapping def __radd__(self, other): pass -reveal_type(A() + C()) # E: Revealed type is 'builtins.int' -reveal_type(B() + C()) # E: Revealed type is 'builtins.int' +reveal_type(A() + C()) # N: Revealed type is 'builtins.int' +reveal_type(B() + C()) # N: Revealed type is 'builtins.int' [case testReverseOperatorWithOverloads2] from typing import overload, Union @@ -1998,14 +1998,14 @@ class Num3(Num1): def __add__(self, other: Union[Num1, Num3]) -> Num3: ... def __radd__(self, other: Union[Num1, Num3]) -> Num3: ... -reveal_type(Num1() + Num2()) # E: Revealed type is '__main__.Num2' -reveal_type(Num2() + Num1()) # E: Revealed type is '__main__.Num2' +reveal_type(Num1() + Num2()) # N: Revealed type is '__main__.Num2' +reveal_type(Num2() + Num1()) # N: Revealed type is '__main__.Num2' -reveal_type(Num1() + Num3()) # E: Revealed type is '__main__.Num3' -reveal_type(Num3() + Num1()) # E: Revealed type is '__main__.Num3' +reveal_type(Num1() + Num3()) # N: Revealed type is '__main__.Num3' +reveal_type(Num3() + Num1()) # N: Revealed type is '__main__.Num3' -reveal_type(Num2() + Num3()) # E: Revealed type is '__main__.Num2' -reveal_type(Num3() + Num2()) # E: Revealed type is '__main__.Num3' +reveal_type(Num2() + Num3()) # N: Revealed type is '__main__.Num2' +reveal_type(Num3() + Num2()) # N: Revealed type is '__main__.Num3' [case testDivReverseOperatorPython3] # No error: __div__ has no special meaning in Python 3 @@ -2020,7 +2020,7 @@ class B2: def __rtruediv__(self, x: A2) -> str: ... # E: Signatures of "__rtruediv__" of "B2" and "__truediv__" of "A2" are unsafely overlapping A1() / B1() # E: Unsupported left operand type for / ("A1") -reveal_type(A2() / B2()) # E: Revealed type is 'builtins.int' +reveal_type(A2() / B2()) # N: Revealed type is 'builtins.int' [case testDivReverseOperatorPython2] # flags: --python-version 2.7 @@ -2050,7 +2050,7 @@ class B2: # 'from __future__ import division' is included, it doesn't display a very # graceful error if __div__ is missing but __truediv__ is present... # Also see https://github.com/python/mypy/issues/2048 -reveal_type(A1() / B1()) # E: Revealed type is 'builtins.int' +reveal_type(A1() / B1()) # N: Revealed type is 'builtins.int' A2() / B2() # E: "A2" has no attribute "__div__" [case testReverseOperatorMethodForwardIsAny] @@ -2116,10 +2116,10 @@ class Fraction(Real): # Note: When doing A + B and if B is a subtype of A, we will always call B.__radd__(A) first # and only try A.__add__(B) second if necessary. -reveal_type(Real() + Fraction()) # E: Revealed type is '__main__.Real*' +reveal_type(Real() + Fraction()) # N: Revealed type is '__main__.Real*' # Note: When doing A + A, we only ever call A.__add__(A), never A.__radd__(A). -reveal_type(Fraction() + Fraction()) # E: Revealed type is 'builtins.str' +reveal_type(Fraction() + Fraction()) # N: Revealed type is 'builtins.str' [case testReverseOperatorTypeVar2a] from typing import TypeVar @@ -2129,8 +2129,8 @@ class Real: class Fraction(Real): def __radd__(self, other: T) -> T: ... # E: Signatures of "__radd__" of "Fraction" and "__add__" of "T" are unsafely overlapping -reveal_type(Real() + Fraction()) # E: Revealed type is '__main__.Real*' -reveal_type(Fraction() + Fraction()) # E: Revealed type is 'builtins.str' +reveal_type(Real() + Fraction()) # N: Revealed type is '__main__.Real*' +reveal_type(Fraction() + Fraction()) # N: Revealed type is 'builtins.str' [case testReverseOperatorTypeVar2b] @@ -2141,8 +2141,8 @@ class Real: class Fraction(Real): def __radd__(self, other: T) -> T: ... # E: Signatures of "__radd__" of "Fraction" and "__add__" of "Real" are unsafely overlapping -reveal_type(Real() + Fraction()) # E: Revealed type is '__main__.Real*' -reveal_type(Fraction() + Fraction()) # E: Revealed type is 'builtins.str' +reveal_type(Real() + Fraction()) # N: Revealed type is '__main__.Real*' +reveal_type(Fraction() + Fraction()) # N: Revealed type is 'builtins.str' [case testReverseOperatorTypeVar3] from typing import TypeVar, Any @@ -2153,9 +2153,9 @@ class Fraction(Real): def __radd__(self, other: T) -> T: ... # E: Signatures of "__radd__" of "Fraction" and "__add__" of "T" are unsafely overlapping class FractionChild(Fraction): pass -reveal_type(Real() + Fraction()) # E: Revealed type is '__main__.Real*' -reveal_type(FractionChild() + Fraction()) # E: Revealed type is '__main__.FractionChild*' -reveal_type(FractionChild() + FractionChild()) # E: Revealed type is 'builtins.str' +reveal_type(Real() + Fraction()) # N: Revealed type is '__main__.Real*' +reveal_type(FractionChild() + Fraction()) # N: Revealed type is '__main__.FractionChild*' +reveal_type(FractionChild() + FractionChild()) # N: Revealed type is 'builtins.str' # Runtime error: we try calling __add__, it doesn't match, and we don't try __radd__ since # the LHS and the RHS are not the same. @@ -2178,11 +2178,11 @@ a: Union[int, float] b: int c: float -reveal_type(a + a) # E: Revealed type is 'builtins.float' -reveal_type(a + b) # E: Revealed type is 'builtins.float' -reveal_type(b + a) # E: Revealed type is 'builtins.float' -reveal_type(a + c) # E: Revealed type is 'builtins.float' -reveal_type(c + a) # E: Revealed type is 'builtins.float' +reveal_type(a + a) # N: Revealed type is 'builtins.float' +reveal_type(a + b) # N: Revealed type is 'builtins.float' +reveal_type(b + a) # N: Revealed type is 'builtins.float' +reveal_type(a + c) # N: Revealed type is 'builtins.float' +reveal_type(c + a) # N: Revealed type is 'builtins.float' [builtins fixtures/ops.pyi] [case testOperatorDoubleUnionStandardSubtyping] @@ -2200,11 +2200,11 @@ a: Union[Parent, Child] b: Parent c: Child -reveal_type(a + a) # E: Revealed type is '__main__.Parent' -reveal_type(a + b) # E: Revealed type is '__main__.Parent' -reveal_type(b + a) # E: Revealed type is '__main__.Parent' -reveal_type(a + c) # E: Revealed type is '__main__.Child' -reveal_type(c + a) # E: Revealed type is '__main__.Child' +reveal_type(a + a) # N: Revealed type is '__main__.Parent' +reveal_type(a + b) # N: Revealed type is '__main__.Parent' +reveal_type(b + a) # N: Revealed type is '__main__.Parent' +reveal_type(a + c) # N: Revealed type is '__main__.Child' +reveal_type(c + a) # N: Revealed type is '__main__.Child' [case testOperatorDoubleUnionNoRelationship1] from typing import Union @@ -2252,11 +2252,11 @@ a: Union[Foo, Bar] b: Foo c: Bar -reveal_type(a + a) # E: Revealed type is 'Union[__main__.Foo, __main__.Bar]' -reveal_type(a + b) # E: Revealed type is 'Union[__main__.Foo, __main__.Bar]' -reveal_type(b + a) # E: Revealed type is 'Union[__main__.Foo, __main__.Bar]' -reveal_type(a + c) # E: Revealed type is '__main__.Bar' -reveal_type(c + a) # E: Revealed type is '__main__.Bar' +reveal_type(a + a) # N: Revealed type is 'Union[__main__.Foo, __main__.Bar]' +reveal_type(a + b) # N: Revealed type is 'Union[__main__.Foo, __main__.Bar]' +reveal_type(b + a) # N: Revealed type is 'Union[__main__.Foo, __main__.Bar]' +reveal_type(a + c) # N: Revealed type is '__main__.Bar' +reveal_type(c + a) # N: Revealed type is '__main__.Bar' [case testOperatorDoubleUnionNaiveAdd] from typing import Union @@ -2295,11 +2295,11 @@ class D: x: Union[A, B] y: Union[C, D] -reveal_type(x + y) # E: Revealed type is 'Union[__main__.Out3, __main__.Out1, __main__.Out2, __main__.Out4]' -reveal_type(A() + y) # E: Revealed type is 'Union[__main__.Out3, __main__.Out1]' -reveal_type(B() + y) # E: Revealed type is 'Union[__main__.Out2, __main__.Out4]' -reveal_type(x + C()) # E: Revealed type is 'Union[__main__.Out3, __main__.Out2]' -reveal_type(x + D()) # E: Revealed type is 'Union[__main__.Out1, __main__.Out4]' +reveal_type(x + y) # N: Revealed type is 'Union[__main__.Out3, __main__.Out1, __main__.Out2, __main__.Out4]' +reveal_type(A() + y) # N: Revealed type is 'Union[__main__.Out3, __main__.Out1]' +reveal_type(B() + y) # N: Revealed type is 'Union[__main__.Out2, __main__.Out4]' +reveal_type(x + C()) # N: Revealed type is 'Union[__main__.Out3, __main__.Out2]' +reveal_type(x + D()) # N: Revealed type is 'Union[__main__.Out1, __main__.Out4]' [case testOperatorDoubleUnionDivisionPython2] # flags: --python-version 2.7 @@ -2308,7 +2308,7 @@ def f(a): # type: (Union[int, float]) -> None a /= 1.1 b = a / 1.1 - reveal_type(b) # E: Revealed type is 'builtins.float' + reveal_type(b) # N: Revealed type is 'builtins.float' [builtins_py2 fixtures/ops.pyi] [case testOperatorDoubleUnionDivisionPython3] @@ -2317,7 +2317,7 @@ def f(a): # type: (Union[int, float]) -> None a /= 1.1 b = a / 1.1 - reveal_type(b) # E: Revealed type is 'builtins.float' + reveal_type(b) # N: Revealed type is 'builtins.float' [builtins fixtures/ops.pyi] [case testOperatorWithInference] @@ -2329,8 +2329,8 @@ def sum(x: Iterable[T]) -> Union[T, int]: ... def len(x: Iterable[T]) -> int: ... x = [1.1, 2.2, 3.3] -reveal_type(sum(x)) # E: Revealed type is 'builtins.float*' -reveal_type(sum(x) / len(x)) # E: Revealed type is 'builtins.float' +reveal_type(sum(x)) # N: Revealed type is 'builtins.float*' +reveal_type(sum(x) / len(x)) # N: Revealed type is 'builtins.float' [builtins fixtures/floatdict.pyi] [case testOperatorWithEmptyListAndSum] @@ -2345,7 +2345,7 @@ def sum(x: Iterable[T], default: S) -> Union[T, S]: ... def sum(*args): pass x = ["a", "b", "c"] -reveal_type(x + sum([x, x, x], [])) # E: Revealed type is 'builtins.list[builtins.str*]' +reveal_type(x + sum([x, x, x], [])) # N: Revealed type is 'builtins.list[builtins.str*]' [builtins fixtures/floatdict.pyi] [case testAbstractReverseOperatorMethod] @@ -2809,16 +2809,16 @@ class B: bad = lambda: 42 B().bad() # E: Attribute function "bad" with type "Callable[[], int]" does not accept self argument -reveal_type(B.a) # E: Revealed type is 'def () -> __main__.A' -reveal_type(B().a) # E: Revealed type is 'def () -> __main__.A' -reveal_type(B().a()) # E: Revealed type is '__main__.A' +reveal_type(B.a) # N: Revealed type is 'def () -> __main__.A' +reveal_type(B().a) # N: Revealed type is 'def () -> __main__.A' +reveal_type(B().a()) # N: Revealed type is '__main__.A' class C: a = A def __init__(self) -> None: self.aa = self.a() -reveal_type(C().aa) # E: Revealed type is '__main__.A' +reveal_type(C().aa) # N: Revealed type is '__main__.A' [out] [case testClassValuedAttributesGeneric] @@ -2831,7 +2831,7 @@ class A(Generic[T]): class B(Generic[T]): a: Type[A[T]] = A -reveal_type(B[int]().a) # E: Revealed type is 'Type[__main__.A[builtins.int*]]' +reveal_type(B[int]().a) # N: Revealed type is 'Type[__main__.A[builtins.int*]]' B[int]().a('hi') # E: Argument 1 to "A" has incompatible type "str"; expected "int" class C(Generic[T]): @@ -2839,7 +2839,7 @@ class C(Generic[T]): def __init__(self) -> None: self.aa = self.a(42) -reveal_type(C().aa) # E: Revealed type is '__main__.A[builtins.int]' +reveal_type(C().aa) # N: Revealed type is '__main__.A[builtins.int]' [out] [case testClassValuedAttributesAlias] @@ -2855,15 +2855,15 @@ class B: a_any = SameA a_int = SameA[int] -reveal_type(B().a_any) # E: Revealed type is 'def () -> __main__.A[Any, Any]' -reveal_type(B().a_int()) # E: Revealed type is '__main__.A[builtins.int, builtins.int]' +reveal_type(B().a_any) # N: Revealed type is 'def () -> __main__.A[Any, Any]' +reveal_type(B().a_int()) # N: Revealed type is '__main__.A[builtins.int, builtins.int]' class C: a_int = SameA[int] def __init__(self) -> None: self.aa = self.a_int() -reveal_type(C().aa) # E: Revealed type is '__main__.A[builtins.int*, builtins.int*]' +reveal_type(C().aa) # N: Revealed type is '__main__.A[builtins.int*, builtins.int*]' [out] @@ -2877,8 +2877,8 @@ class User: pass class ProUser(User): pass def new_user(user_class: Type[User]) -> User: return user_class() -reveal_type(new_user(User)) # E: Revealed type is '__main__.User' -reveal_type(new_user(ProUser)) # E: Revealed type is '__main__.User' +reveal_type(new_user(User)) # N: Revealed type is '__main__.User' +reveal_type(new_user(ProUser)) # N: Revealed type is '__main__.User' [out] [case testTypeUsingTypeCDefaultInit] @@ -2911,8 +2911,8 @@ def new_user(user_class: Type[U]) -> U: pro_user = new_user(ProUser) reveal_type(pro_user) [out] -main:7: error: Revealed type is 'U`-1' -main:10: error: Revealed type is '__main__.ProUser*' +main:7: note: Revealed type is 'U`-1' +main:10: note: Revealed type is '__main__.ProUser*' [case testTypeUsingTypeCTypeVarDefaultInit] from typing import Type, TypeVar @@ -2949,7 +2949,7 @@ reveal_type(wiz) def error(u_c: Type[U]) -> P: return new_pro(u_c) # Error here, see below [out] -main:11: error: Revealed type is '__main__.WizUser*' +main:11: note: Revealed type is '__main__.WizUser*' main:13: error: Incompatible return value type (got "U", expected "P") main:13: error: Value of type variable "P" of "new_pro" cannot be "U" @@ -2972,9 +2972,9 @@ class C(Generic[T_co]): def __init__(self, x: T_co) -> None: # This should be allowed self.x = x def meth(self) -> None: - reveal_type(self.x) # E: Revealed type is 'T_co`1' + reveal_type(self.x) # N: Revealed type is 'T_co`1' -reveal_type(C(1).x) # E: Revealed type is 'builtins.int*' +reveal_type(C(1).x) # N: Revealed type is 'builtins.int*' [builtins fixtures/property.pyi] [out] @@ -3009,7 +3009,7 @@ def foo(arg: Type[Any]): x = arg() x = arg(0) x = arg('', ()) - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' x.foo class X: pass foo(X) @@ -3021,7 +3021,7 @@ def foo(arg: Type[Any]): x = arg.member_name arg.new_member_name = 42 # Member access is ok and types as Any - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: 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") [out] @@ -3029,8 +3029,8 @@ def foo(arg: Type[Any]): [case testTypeUsingTypeCTypeAnyMemberFallback] from typing import Type, Any def foo(arg: Type[Any]): - reveal_type(arg.__str__) # E: Revealed type is 'def () -> builtins.str' - reveal_type(arg.mro()) # E: Revealed type is 'builtins.list[builtins.type]' + reveal_type(arg.__str__) # N: Revealed type is 'def () -> builtins.str' + reveal_type(arg.mro()) # N: Revealed type is 'builtins.list[builtins.type]' [builtins fixtures/type.pyi] [out] @@ -3038,7 +3038,7 @@ def foo(arg: Type[Any]): from typing import Type def foo(arg: Type): x = arg() - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' class X: pass foo(X) [out] @@ -3060,9 +3060,9 @@ class User: def foo(cls) -> int: pass def bar(self) -> int: pass def process(cls: Type[User]): - reveal_type(cls.foo()) # E: Revealed type is 'builtins.int' + reveal_type(cls.foo()) # N: Revealed type is 'builtins.int' obj = cls() - reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' + reveal_type(cls.bar(obj)) # N: Revealed type is 'builtins.int' cls.mro() # Defined in class type cls.error # E: "Type[User]" has no attribute "error" [builtins fixtures/classmethod.pyi] @@ -3093,9 +3093,9 @@ class User: def bar(self) -> int: pass U = TypeVar('U', bound=User) def process(cls: Type[U]): - reveal_type(cls.foo()) # E: Revealed type is 'builtins.int' + reveal_type(cls.foo()) # N: Revealed type is 'builtins.int' obj = cls() - reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int' + reveal_type(cls.bar(obj)) # N: Revealed type is 'builtins.int' cls.mro() # Defined in class type cls.error # E: "Type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] @@ -3192,7 +3192,7 @@ def foo(c: Type[C], d: Type[D]) -> None: [builtins fixtures/list.pyi] [out] -main:7: error: Revealed type is 'builtins.list[Type[__main__.B]]' +main:7: note: Revealed type is 'builtins.list[Type[__main__.B]]' [case testTypeEquivalentTypeAny] from typing import Type, Any @@ -3220,7 +3220,7 @@ y = None # type: Type[Any] z = None # type: Type[C] lst = [x, y, z] -reveal_type(lst) # E: Revealed type is 'builtins.list[builtins.type*]' +reveal_type(lst) # N: Revealed type is 'builtins.list[builtins.type*]' T1 = TypeVar('T1', bound=type) T2 = TypeVar('T2', bound=Type[Any]) @@ -3258,8 +3258,8 @@ def f(a: int) -> Any: pass @overload def f(a: object) -> int: pass -reveal_type(f(User)) # E: Revealed type is 'builtins.int' -reveal_type(f(UserType)) # E: Revealed type is 'builtins.int' +reveal_type(f(User)) # N: Revealed type is 'builtins.int' +reveal_type(f(UserType)) # N: Revealed type is 'builtins.int' [builtins fixtures/classmethod.pyi] [out] @@ -3278,9 +3278,9 @@ def f(a: type) -> int: def f(a: int) -> str: return "a" -reveal_type(f(User)) # E: Revealed type is 'builtins.int' -reveal_type(f(UserType)) # E: Revealed type is 'builtins.int' -reveal_type(f(1)) # E: Revealed type is 'builtins.str' +reveal_type(f(User)) # N: Revealed type is 'builtins.int' +reveal_type(f(UserType)) # N: Revealed type is 'builtins.int' +reveal_type(f(1)) # N: Revealed type is 'builtins.str' [builtins fixtures/classmethod.pyi] [out] @@ -3302,10 +3302,10 @@ def f(a: Type[User]) -> int: def f(a: int) -> str: return "a" -reveal_type(f(User)) # E: Revealed type is 'builtins.int' -reveal_type(f(UserType)) # E: Revealed type is 'builtins.int' -reveal_type(f(User())) # E: Revealed type is 'foo.User' -reveal_type(f(1)) # E: Revealed type is 'builtins.str' +reveal_type(f(User)) # N: Revealed type is 'builtins.int' +reveal_type(f(UserType)) # N: Revealed type is 'builtins.int' +reveal_type(f(User())) # N: Revealed type is 'foo.User' +reveal_type(f(1)) # N: Revealed type is 'builtins.str' [builtins fixtures/classmethod.pyi] [out] @@ -3329,10 +3329,10 @@ def f(a: int) -> Type[User]: def f(a: str) -> User: return User() -reveal_type(f(User())) # E: Revealed type is 'Type[foo.User]' -reveal_type(f(User)) # E: Revealed type is 'foo.User' -reveal_type(f(3)) # E: Revealed type is 'Type[foo.User]' -reveal_type(f("hi")) # E: Revealed type is 'foo.User' +reveal_type(f(User())) # N: Revealed type is 'Type[foo.User]' +reveal_type(f(User)) # N: Revealed type is 'foo.User' +reveal_type(f(3)) # N: Revealed type is 'Type[foo.User]' +reveal_type(f("hi")) # N: Revealed type is 'foo.User' [builtins fixtures/classmethod.pyi] [out] @@ -3457,15 +3457,15 @@ def f(a: A) -> A: pass @overload def f(a: B) -> B: pass -reveal_type(f(A)) # E: Revealed type is 'builtins.int' -reveal_type(f(AChild)) # E: Revealed type is 'builtins.int' -reveal_type(f(B)) # E: Revealed type is 'builtins.str' -reveal_type(f(BChild)) # E: Revealed type is 'builtins.str' +reveal_type(f(A)) # N: Revealed type is 'builtins.int' +reveal_type(f(AChild)) # N: Revealed type is 'builtins.int' +reveal_type(f(B)) # N: Revealed type is 'builtins.str' +reveal_type(f(BChild)) # N: Revealed type is 'builtins.str' -reveal_type(f(A())) # E: Revealed type is 'foo.A' -reveal_type(f(AChild())) # E: Revealed type is 'foo.A' -reveal_type(f(B())) # E: Revealed type is 'foo.B' -reveal_type(f(BChild())) # E: Revealed type is 'foo.B' +reveal_type(f(A())) # N: Revealed type is 'foo.A' +reveal_type(f(AChild())) # N: Revealed type is 'foo.A' +reveal_type(f(B())) # N: Revealed type is 'foo.B' +reveal_type(f(BChild())) # N: Revealed type is 'foo.B' [builtins fixtures/classmethod.pyi] [out] @@ -3594,9 +3594,9 @@ class User: u = User() -reveal_type(type(u)) # E: Revealed type is 'Type[__main__.User]' -reveal_type(type(u).test_class_method()) # E: Revealed type is 'builtins.int' -reveal_type(type(u).test_static_method()) # E: Revealed type is 'builtins.str' +reveal_type(type(u)) # N: Revealed type is 'Type[__main__.User]' +reveal_type(type(u).test_class_method()) # N: Revealed type is 'builtins.int' +reveal_type(type(u).test_static_method()) # N: Revealed type is 'builtins.str' type(u).test_instance_method() # E: Too few arguments for "test_instance_method" of "User" [builtins fixtures/classmethod.pyi] [out] @@ -3613,8 +3613,8 @@ def f2(func: A) -> A: u = User() -reveal_type(f1(u)) # E: Revealed type is 'Type[__main__.User]' -reveal_type(f2(type)(u)) # E: Revealed type is 'Type[__main__.User]' +reveal_type(f1(u)) # N: Revealed type is 'Type[__main__.User]' +reveal_type(f2(type)(u)) # N: Revealed type is 'Type[__main__.User]' [builtins fixtures/classmethod.pyi] [out] @@ -3626,9 +3626,9 @@ def fake1(a: object) -> type: def fake2(a: int) -> type: return User -reveal_type(type(User())) # E: Revealed type is 'Type[__main__.User]' -reveal_type(fake1(User())) # E: Revealed type is 'builtins.type' -reveal_type(fake2(3)) # E: Revealed type is 'builtins.type' +reveal_type(type(User())) # N: Revealed type is 'Type[__main__.User]' +reveal_type(fake1(User())) # N: Revealed type is 'builtins.type' +reveal_type(fake2(3)) # N: Revealed type is 'builtins.type' [builtins fixtures/classmethod.pyi] [out] @@ -3636,7 +3636,7 @@ reveal_type(fake2(3)) # E: Revealed type is 'builtins.type' def foo(self) -> int: return self.attr User = type('User', (object,), {'foo': foo, 'attr': 3}) -reveal_type(User) # E: Revealed type is 'builtins.type' +reveal_type(User) # N: Revealed type is 'builtins.type' [builtins fixtures/args.pyi] [out] @@ -4065,8 +4065,8 @@ class M(type): class A(metaclass=M): pass def f(TA: Type[A]): - reveal_type(TA) # E: Revealed type is 'Type[__main__.A]' - reveal_type(TA.x) # E: Revealed type is 'builtins.int' + reveal_type(TA) # N: Revealed type is 'Type[__main__.A]' + reveal_type(TA.x) # N: Revealed type is 'builtins.int' [case testSubclassMetaclass] class M1(type): @@ -4074,7 +4074,7 @@ class M1(type): class M2(M1): pass class C(metaclass=M2): pass -reveal_type(C.x) # E: Revealed type is 'builtins.int' +reveal_type(C.x) # N: Revealed type is 'builtins.int' [case testMetaclassSubclass] from typing import Type @@ -4085,8 +4085,8 @@ class A(metaclass=M): pass class B(A): pass def f(TB: Type[B]): - reveal_type(TB) # E: Revealed type is 'Type[__main__.B]' - reveal_type(TB.x) # E: Revealed type is 'builtins.int' + reveal_type(TB) # N: Revealed type is 'Type[__main__.B]' + reveal_type(TB.x) # N: Revealed type is 'builtins.int' [case testMetaclassIterable] from typing import Iterable, Iterator @@ -4097,14 +4097,14 @@ class ImplicitMeta(type): class Implicit(metaclass=ImplicitMeta): pass for _ in Implicit: pass -reveal_type(list(Implicit)) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(list(Implicit)) # N: Revealed type is 'builtins.list[builtins.int*]' class ExplicitMeta(type, Iterable[int]): def __iter__(self) -> Iterator[int]: yield 1 class Explicit(metaclass=ExplicitMeta): pass for _ in Explicit: pass -reveal_type(list(Explicit)) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(list(Explicit)) # N: Revealed type is 'builtins.list[builtins.int*]' [builtins fixtures/list.pyi] @@ -4126,7 +4126,7 @@ class Meta(type): class Concrete(metaclass=Meta): pass -reveal_type(Concrete + X()) # E: Revealed type is 'builtins.str' +reveal_type(Concrete + X()) # N: Revealed type is 'builtins.str' Concrete + "hello" # E: Unsupported operand types for + ("Type[Concrete]" and "str") [case testMetaclassOperatorTypeVar] @@ -4144,7 +4144,7 @@ S = TypeVar("S", bound=Test) def f(x: Type[Test]) -> str: return x * 0 def g(x: Type[S]) -> str: - return reveal_type(x * 0) # E: Revealed type is 'builtins.str' + return reveal_type(x * 0) # N: Revealed type is 'builtins.str' [case testMetaclassGetitem] class M(type): @@ -4152,7 +4152,7 @@ class M(type): class A(metaclass=M): pass -reveal_type(A[M]) # E: Revealed type is 'builtins.int' +reveal_type(A[M]) # N: Revealed type is 'builtins.int' [case testMetaclassSelfType] from typing import TypeVar, Type @@ -4164,14 +4164,14 @@ class M1(M): def foo(cls: Type[T]) -> T: ... class A(metaclass=M1): pass -reveal_type(A.foo()) # E: Revealed type is '__main__.A*' +reveal_type(A.foo()) # N: Revealed type is '__main__.A*' [case testMetaclassAndSkippedImport] # flags: --ignore-missing-imports from missing import M class A(metaclass=M): y = 0 -reveal_type(A.y) # E: Revealed type is 'builtins.int' +reveal_type(A.y) # N: Revealed type is 'builtins.int' A.x # E: "Type[A]" has no attribute "x" [case testAnyMetaclass] @@ -4179,7 +4179,7 @@ from typing import Any M = None # type: Any class A(metaclass=M): y = 0 -reveal_type(A.y) # E: Revealed type is 'builtins.int' +reveal_type(A.y) # N: Revealed type is 'builtins.int' A.x # E: "Type[A]" has no attribute "x" [case testInvalidVariableAsMetaclass] @@ -4190,7 +4190,7 @@ class A(metaclass=M): # E: Invalid metaclass 'M' y = 0 class B(metaclass=MM): # E: Invalid metaclass 'MM' y = 0 -reveal_type(A.y) # E: Revealed type is 'builtins.int' +reveal_type(A.y) # N: Revealed type is 'builtins.int' A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] @@ -4208,11 +4208,11 @@ 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]" a.f(1) # E: Too many arguments for "f" of "A" - reveal_type(a.y) # E: Revealed type is 'builtins.int' + reveal_type(a.y) # N: Revealed type is 'builtins.int' x = A # type: MM -reveal_type(A.y) # E: Revealed type is 'builtins.int' -reveal_type(A.x) # E: Revealed type is 'Any' +reveal_type(A.y) # N: Revealed type is 'builtins.int' +reveal_type(A.x) # N: Revealed type is 'Any' A.f(1) # E: Too many arguments for "f" of "A" A().g(1) # E: Too many arguments for "g" of "A" [builtins fixtures/classmethod.pyi] @@ -4222,7 +4222,7 @@ class M(type): x = 5 class A(metaclass=M): pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' [case testMetaclassStrictSupertypeOfTypeWithClassmethods] from typing import Type, TypeVar @@ -4240,10 +4240,10 @@ m: M class A(metaclass=M): def foo(self): pass -reveal_type(A.g1) # E: Revealed type is 'def () -> __main__.A' -reveal_type(A.g2) # E: Revealed type is 'def () -> __main__.A*' -reveal_type(A.g3) # E: Revealed type is 'def () -> def () -> __main__.A' -reveal_type(A.g4) # E: Revealed type is 'def () -> def () -> __main__.A' +reveal_type(A.g1) # N: Revealed type is 'def () -> __main__.A' +reveal_type(A.g2) # N: Revealed type is 'def () -> __main__.A*' +reveal_type(A.g3) # N: Revealed type is 'def () -> def () -> __main__.A' +reveal_type(A.g4) # N: Revealed type is 'def () -> def () -> __main__.A' class B(metaclass=M): def foo(self): pass @@ -4251,22 +4251,22 @@ class B(metaclass=M): 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' +reveal_type(B.g4) # N: 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]") 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*' -reveal_type(ta.g3) # E: Revealed type is 'def () -> Type[__main__.A]' -reveal_type(ta.g4) # E: Revealed type is 'def () -> Type[__main__.A]' +reveal_type(ta.g1) # N: Revealed type is 'def () -> __main__.A' +reveal_type(ta.g2) # N: Revealed type is 'def () -> __main__.A*' +reveal_type(ta.g3) # N: Revealed type is 'def () -> Type[__main__.A]' +reveal_type(ta.g4) # N: 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.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*' +reveal_type(x.g4) # N: Revealed type is 'def () -> __main__.M*' def r(ta: Type[TA], tta: TTA) -> None: x: M = ta @@ -4278,15 +4278,15 @@ class Class(metaclass=M): @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]") -reveal_type(cl.f1) # E: Revealed type is 'def ()' -reveal_type(cl.f2) # E: Revealed type is 'def ()' +reveal_type(cl.f1) # N: Revealed type is 'def ()' +reveal_type(cl.f2) # N: Revealed type is 'def ()' 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]") -reveal_type(s.f) # E: Revealed type is 'def ()' +reveal_type(s.f) # N: Revealed type is 'def ()' x2: M = s from typing import ClassVar @@ -4317,18 +4317,18 @@ def f(x: str) -> str: ... def f(x: object) -> object: return '' e: EM -reveal_type(f(e)) # E: Revealed type is 'builtins.int' +reveal_type(f(e)) # N: Revealed type is 'builtins.int' et: Type[E] -reveal_type(f(et)) # E: Revealed type is 'builtins.int' +reveal_type(f(et)) # N: Revealed type is 'builtins.int' e1: EM1 -reveal_type(f(e1)) # E: Revealed type is '__main__.A' +reveal_type(f(e1)) # N: Revealed type is '__main__.A' e1t: Type[E1] -reveal_type(f(e1t)) # E: Revealed type is '__main__.A' +reveal_type(f(e1t)) # N: Revealed type is '__main__.A' -reveal_type(f('')) # E: Revealed type is 'builtins.str' +reveal_type(f('')) # N: Revealed type is 'builtins.str' [case testTypeCErasesGenericsFromC] from typing import Generic, Type, TypeVar @@ -4339,7 +4339,7 @@ class ExampleDict(Generic[K, V]): ... D = TypeVar('D') def mkdict(dict_type: Type[D]) -> D: ... -reveal_type(mkdict(ExampleDict)) # E: Revealed type is '__main__.ExampleDict*[Any, Any]' +reveal_type(mkdict(ExampleDict)) # N: Revealed type is '__main__.ExampleDict*[Any, Any]' [case testTupleForwardBase] from m import a @@ -4401,7 +4401,7 @@ class M(TypedDict): # E: Recursive types not fully supported yet, nested types n: N m: M lst = [n, m] -reveal_type(lst[0]['x']) # E: Revealed type is 'TypedDict('__main__.N', {'x': Any})' +reveal_type(lst[0]['x']) # N: Revealed type is 'TypedDict('__main__.N', {'x': Any})' [builtins fixtures/isinstancelist.pyi] [case testCrashInForwardRefToNamedTupleWithIsinstance] @@ -4414,7 +4414,7 @@ class NameInfo(NamedTuple): def parse_ast(name_dict: NameDict) -> None: if isinstance(name_dict[''], int): pass - reveal_type(name_dict['test']) # E: Revealed type is 'Tuple[builtins.bool, fallback=__main__.NameInfo]' + reveal_type(name_dict['test']) # N: Revealed type is 'Tuple[builtins.bool, fallback=__main__.NameInfo]' [builtins fixtures/isinstancelist.pyi] [out] @@ -4429,7 +4429,7 @@ class NameInfo(TypedDict): def parse_ast(name_dict: NameDict) -> None: if isinstance(name_dict[''], int): pass - reveal_type(name_dict['']['ast']) # E: Revealed type is 'builtins.bool' + reveal_type(name_dict['']['ast']) # N: Revealed type is 'builtins.bool' [builtins fixtures/isinstancelist.pyi] [out] @@ -4445,7 +4445,7 @@ def parse_ast(name_dict: NameDict) -> None: if isinstance(name_dict[''], int): pass x = name_dict[''] - reveal_type(x) # E: Revealed type is '__main__.NameInfo*' + reveal_type(x) # N: Revealed type is '__main__.NameInfo*' if int(): x = NameInfo(Base()) # OK x = Base() # E: Incompatible types in assignment (expression has type "Base", variable has type "NameInfo") @@ -4476,7 +4476,7 @@ class C: foo = foos.get(1) dict(foo) -reveal_type(x.frob) # E: Revealed type is 'def (foos: builtins.dict[Any, __main__.Foos])' +reveal_type(x.frob) # N: Revealed type is 'def (foos: builtins.dict[Any, __main__.Foos])' [builtins fixtures/dict.pyi] [out] @@ -4505,7 +4505,7 @@ class N(TypedDict): [case testCorrectAttributeInForwardRefToNamedTuple] from typing import NamedTuple proc: Process -reveal_type(proc.state) # E: Revealed type is 'builtins.int' +reveal_type(proc.state) # N: Revealed type is 'builtins.int' def get_state(proc: 'Process') -> int: return proc.state @@ -4516,7 +4516,7 @@ class Process(NamedTuple): [case testCorrectItemTypeInForwardRefToTypedDict] from mypy_extensions import TypedDict proc: Process -reveal_type(proc['state']) # E: Revealed type is 'builtins.int' +reveal_type(proc['state']) # N: Revealed type is 'builtins.int' def get_state(proc: 'Process') -> int: return proc['state'] @@ -4536,7 +4536,7 @@ class B(NamedTuple): attr: str y: A y = x -reveal_type(x.one.attr) # E: Revealed type is 'builtins.str' +reveal_type(x.one.attr) # N: Revealed type is 'builtins.str' [out] [case testCrashOnDoubleForwardTypedDict] @@ -4549,7 +4549,7 @@ class A(TypedDict): class B(TypedDict): attr: str -reveal_type(x['one']['attr']) # E: Revealed type is 'builtins.str' +reveal_type(x['one']['attr']) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstancelist.pyi] [out] @@ -4564,7 +4564,7 @@ class Bar(NamedTuple): def foo(node: Node) -> int: x = node - reveal_type(node) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.Foo], Tuple[builtins.int, fallback=__main__.Bar]]' + reveal_type(node) # N: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.Foo], Tuple[builtins.int, fallback=__main__.Bar]]' return x.x [out] @@ -4587,7 +4587,7 @@ def foo(node: NodeType) -> int: [case testSupportForwardUnionOfNewTypes] from typing import Union, NewType x: Node -reveal_type(x.x) # E: Revealed type is 'builtins.int' +reveal_type(x.x) # N: Revealed type is 'builtins.int' class A: x: int @@ -4612,7 +4612,7 @@ class A: class B(A): pass -reveal_type(x.x) # E: Revealed type is 'builtins.int' +reveal_type(x.x) # N: Revealed type is 'builtins.int' [out] [case testCrashOnComplexNamedTupleUnionProperty] @@ -4630,7 +4630,7 @@ class B(object): def x(self) -> int: return self.a.x -reveal_type(x.x) # E: Revealed type is 'builtins.int' +reveal_type(x.x) # N: Revealed type is 'builtins.int' [builtins fixtures/property.pyi] [out] @@ -4641,9 +4641,9 @@ ForwardUnion = Union['TP', int] class TP(NamedTuple('TP', [('x', int)])): pass def f(x: ForwardUnion) -> None: - reveal_type(x) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.TP], builtins.int]' + reveal_type(x) # N: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.TP], builtins.int]' if isinstance(x, TP): - reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.TP]' + reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.TP]' [builtins fixtures/isinstance.pyi] [out] @@ -4673,10 +4673,10 @@ x: TD x1 = TD({'x': []}) y: NM y1 = NM(x=[]) -reveal_type(x) # E: Revealed type is 'TypedDict('__main__.TD', {'x': builtins.list[Any]})' -reveal_type(x1) # E: Revealed type is 'TypedDict('__main__.TD', {'x': builtins.list[Any]})' -reveal_type(y) # E: Revealed type is 'Tuple[builtins.list[Any], fallback=__main__.NM]' -reveal_type(y1) # E: Revealed type is 'Tuple[builtins.list[Any], fallback=__main__.NM]' +reveal_type(x) # N: Revealed type is 'TypedDict('__main__.TD', {'x': builtins.list[Any]})' +reveal_type(x1) # N: Revealed type is 'TypedDict('__main__.TD', {'x': builtins.list[Any]})' +reveal_type(y) # N: Revealed type is 'Tuple[builtins.list[Any], fallback=__main__.NM]' +reveal_type(y1) # N: Revealed type is 'Tuple[builtins.list[Any], fallback=__main__.NM]' [builtins fixtures/dict.pyi] [out] @@ -4707,8 +4707,8 @@ class B: pass x: A1 y: A2 -reveal_type(x.b) # E: Revealed type is '__main__.B' -reveal_type(y['b']) # E: Revealed type is '__main__.B' +reveal_type(x.b) # N: Revealed type is '__main__.B' +reveal_type(y['b']) # N: Revealed type is '__main__.B' [builtins fixtures/dict.pyi] [out] @@ -4721,8 +4721,8 @@ class B: pass x: A1 y: A2 -reveal_type(x.b) # E: Revealed type is '__main__.B' -reveal_type(y['b']) # E: Revealed type is '__main__.B' +reveal_type(x.b) # N: Revealed type is '__main__.B' +reveal_type(y['b']) # N: Revealed type is '__main__.B' [builtins fixtures/dict.pyi] [out] @@ -4736,8 +4736,8 @@ class M(type): class A(six.with_metaclass(M)): pass @six.add_metaclass(M) class B: pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' -reveal_type(type(B).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' +reveal_type(type(B).x) # N: Revealed type is 'builtins.int' [case testSixMetaclass_python2] import six @@ -4746,8 +4746,8 @@ class M(type): class A(six.with_metaclass(M)): pass @six.add_metaclass(M) class B: pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' -reveal_type(type(B).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' +reveal_type(type(B).x) # N: Revealed type is 'builtins.int' [case testFromSixMetaclass] from six import with_metaclass, add_metaclass @@ -4756,8 +4756,8 @@ class M(type): class A(with_metaclass(M)): pass @add_metaclass(M) class B: pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' -reveal_type(type(B).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' +reveal_type(type(B).x) # N: Revealed type is 'builtins.int' [case testSixMetaclassImportFrom] import six @@ -4765,8 +4765,8 @@ from metadefs import M class A(six.with_metaclass(M)): pass @six.add_metaclass(M) class B: pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' -reveal_type(type(B).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' +reveal_type(type(B).x) # N: Revealed type is 'builtins.int' [file metadefs.py] class M(type): x = 5 @@ -4777,8 +4777,8 @@ import metadefs class A(six.with_metaclass(metadefs.M)): pass @six.add_metaclass(metadefs.M) class B: pass -reveal_type(type(A).x) # E: Revealed type is 'builtins.int' -reveal_type(type(B).x) # E: Revealed type is 'builtins.int' +reveal_type(type(A).x) # N: Revealed type is 'builtins.int' +reveal_type(type(B).x) # N: Revealed type is 'builtins.int' [file metadefs.py] class M(type): x = 5 @@ -4799,16 +4799,16 @@ class D1(A): pass class C2(six.with_metaclass(M, A, B)): pass @six.add_metaclass(M) class D2(A, B): pass -reveal_type(type(C1).x) # E: Revealed type is 'builtins.int' -reveal_type(type(D1).x) # E: Revealed type is 'builtins.int' -reveal_type(type(C2).x) # E: Revealed type is 'builtins.int' -reveal_type(type(D2).x) # E: Revealed type is 'builtins.int' +reveal_type(type(C1).x) # N: Revealed type is 'builtins.int' +reveal_type(type(D1).x) # N: Revealed type is 'builtins.int' +reveal_type(type(C2).x) # N: Revealed type is 'builtins.int' +reveal_type(type(D2).x) # N: Revealed type is 'builtins.int' C1().foo() D1().foo() C1().bar() # E: "C1" has no attribute "bar" D1().bar() # E: "D1" has no attribute "bar" -for x in C1: reveal_type(x) # E: Revealed type is 'builtins.int*' -for x in C2: reveal_type(x) # E: Revealed type is 'builtins.int*' +for x in C1: reveal_type(x) # N: Revealed type is 'builtins.int*' +for x in C2: reveal_type(x) # N: Revealed type is 'builtins.int*' C2().foo() D2().foo() C2().bar() @@ -4833,8 +4833,8 @@ class Arc1(Generic[T_co], Destroyable): pass class MyDestr(Destroyable): pass -reveal_type(Arc[MyDestr]()) # E: Revealed type is '__main__.Arc[__main__.MyDestr*]' -reveal_type(Arc1[MyDestr]()) # E: Revealed type is '__main__.Arc1[__main__.MyDestr*]' +reveal_type(Arc[MyDestr]()) # N: Revealed type is '__main__.Arc[__main__.MyDestr*]' +reveal_type(Arc1[MyDestr]()) # N: Revealed type is '__main__.Arc1[__main__.MyDestr*]' [builtins fixtures/bool.pyi] [typing fixtures/typing-full.pyi] @@ -4929,9 +4929,9 @@ class C(metaclass=M): x = C y: Type[C] = C -reveal_type(type(C).m) # E: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' -reveal_type(type(x).m) # E: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' -reveal_type(type(y).m) # E: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' +reveal_type(type(C).m) # N: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' +reveal_type(type(x).m) # N: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' +reveal_type(type(y).m) # N: Revealed type is 'def (cls: __main__.M, x: builtins.int) -> builtins.int' [out] [case testMetaclassMemberAccessViaType2] @@ -4944,8 +4944,8 @@ class C(B, metaclass=M): pass x: Type[C] -reveal_type(x.m) # E: Revealed type is 'def (x: builtins.int) -> builtins.int' -reveal_type(x.whatever) # E: Revealed type is 'Any' +reveal_type(x.m) # N: Revealed type is 'def (x: builtins.int) -> builtins.int' +reveal_type(x.whatever) # N: Revealed type is 'Any' [out] [case testMetaclassMemberAccessViaType3] @@ -4954,8 +4954,8 @@ T = TypeVar('T') class C(Any): def bar(self: T) -> Type[T]: pass def foo(self) -> None: - reveal_type(self.bar()) # E: Revealed type is 'Type[__main__.C*]' - reveal_type(self.bar().__name__) # E: Revealed type is 'builtins.str' + reveal_type(self.bar()) # N: Revealed type is 'Type[__main__.C*]' + reveal_type(self.bar().__name__) # N: Revealed type is 'builtins.str' [builtins fixtures/type.pyi] [out] @@ -5012,9 +5012,9 @@ class C1(object): reveal_locals() [out] -main:5: error: Revealed local types are: -main:5: error: t: builtins.str -main:5: error: y: builtins.float +main:5: note: Revealed local types are: +main:5: note: t: builtins.str +main:5: note: y: builtins.float [case testAbstractClasses] import a @@ -5095,8 +5095,8 @@ class C(B): import a x: a.A y: a.A.B.C -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(y) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(y) # N: Revealed type is 'Any' [file a.pyi] from typing import Any def __getattr__(attr: str) -> Any: ... @@ -5127,9 +5127,9 @@ class D(C[Descr]): other: Descr d: D -reveal_type(d.normal) # E: Revealed type is 'builtins.int' -reveal_type(d.dynamic) # E: Revealed type is '__main__.Descr*' -reveal_type(D.other) # E: Revealed type is 'builtins.int' +reveal_type(d.normal) # N: Revealed type is 'builtins.int' +reveal_type(d.dynamic) # N: Revealed type is '__main__.Descr*' +reveal_type(D.other) # N: Revealed type is 'builtins.int' D.dynamic # E: "Type[D]" has no attribute "dynamic" [out] @@ -5144,7 +5144,7 @@ class C: self.x = x c = C(Descr()) -reveal_type(c.x) # E: Revealed type is '__main__.Descr' +reveal_type(c.x) # N: Revealed type is '__main__.Descr' [out] [case testForwardInstanceWithWrongArgCount] @@ -5166,7 +5166,7 @@ class G(Generic[T]): ... A = G x: A[B] -reveal_type(x) # E: Revealed type is '__main__.G[__main__.G[Any]]' +reveal_type(x) # N: Revealed type is '__main__.G[__main__.G[Any]]' B = G [out] @@ -5192,7 +5192,7 @@ class B(Generic[T]): ... y: A z: A[int] x = [y, z] -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.B*[Any]]' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.B*[Any]]' A = B [builtins fixtures/list.pyi] @@ -5215,8 +5215,8 @@ class C(dynamic): name = Descr(str) c: C -reveal_type(c.id) # E: Revealed type is 'builtins.int*' -reveal_type(C.name) # E: Revealed type is 'd.Descr[builtins.str*]' +reveal_type(c.id) # N: Revealed type is 'builtins.int*' +reveal_type(C.name) # N: Revealed type is 'd.Descr[builtins.str*]' [file d.pyi] from typing import Any, overload, Generic, TypeVar, Type @@ -5246,8 +5246,8 @@ class C: def foo(cls) -> int: return 42 -reveal_type(C.foo) # E: Revealed type is 'builtins.int*' -reveal_type(C().foo) # E: Revealed type is 'builtins.int*' +reveal_type(C.foo) # N: Revealed type is 'builtins.int*' +reveal_type(C().foo) # N: Revealed type is 'builtins.int*' [out] [case testMultipleInheritanceCycle] @@ -5380,7 +5380,7 @@ class B(A): def __init__(self, x: int) -> None: pass -reveal_type(B) # E: Revealed type is 'def (x: builtins.int) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (x: builtins.int) -> __main__.B' [case testNewAndInit3] from typing import Any @@ -5391,7 +5391,7 @@ class A: def __init__(self, x: int) -> None: pass -reveal_type(A) # E: Revealed type is 'def (x: builtins.int) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (x: builtins.int) -> __main__.A' [case testCyclicDecorator] import b @@ -5449,7 +5449,7 @@ class A(b.B): @overload def meth(self, x: str) -> str: ... def meth(self, x) -> Union[int, str]: - reveal_type(other.x) # E: Revealed type is 'builtins.int' + reveal_type(other.x) # N: Revealed type is 'builtins.int' return 0 other: Other @@ -5573,7 +5573,7 @@ import c class A(b.B): @c.deco def meth(self) -> int: - reveal_type(other.x) # E: Revealed type is 'builtins.int' + reveal_type(other.x) # N: Revealed type is 'builtins.int' return 0 other: Other @@ -5605,7 +5605,7 @@ class A(b.B): @c.deco def meth(self) -> int: y = super().meth() - reveal_type(y) # E: Revealed type is 'Tuple[builtins.int*, builtins.int]' + reveal_type(y) # N: Revealed type is 'Tuple[builtins.int*, builtins.int]' return 0 [file b.py] from a import A @@ -5638,7 +5638,7 @@ import c class B: @c.deco def meth(self) -> int: - reveal_type(other.x) # E: Revealed type is 'builtins.int' + reveal_type(other.x) # N: Revealed type is 'builtins.int' return 0 other: Other @@ -5662,8 +5662,8 @@ class A(b.B): @c.deco def meth(self) -> int: y = super().meth() - reveal_type(y) # E: Revealed type is 'Tuple[builtins.int*, builtins.int]' - reveal_type(other.x) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'Tuple[builtins.int*, builtins.int]' + reveal_type(other.x) # N: Revealed type is 'builtins.int' return 0 other: Other @@ -5700,7 +5700,7 @@ class C: def meth_spec(self) -> None: if self.spec is None: self.spec = 0 - reveal_type(self.spec) # E: Revealed type is 'builtins.int' + reveal_type(self.spec) # N: Revealed type is 'builtins.int' [builtins fixtures/bool.pyi] [case testUnionDescriptorsBinder] @@ -5719,7 +5719,7 @@ class C: def meth_spec(self) -> None: self.spec = A() - reveal_type(self.spec) # E: Revealed type is '__main__.A' + reveal_type(self.spec) # N: Revealed type is '__main__.A' [builtins fixtures/bool.pyi] [case testSubclassDescriptorsBinder] @@ -5738,7 +5738,7 @@ class C: def meth_spec(self) -> None: self.spec = B() - reveal_type(self.spec) # E: Revealed type is '__main__.B' + reveal_type(self.spec) # N: Revealed type is '__main__.B' [builtins fixtures/bool.pyi] [case testClassLevelImport] @@ -5788,7 +5788,7 @@ class C: ... x: Union[C, Type[C]] if isinstance(x, type) and issubclass(x, C): - reveal_type(x) # E: Revealed type is 'Type[__main__.C]' + reveal_type(x) # N: Revealed type is 'Type[__main__.C]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceTypeByAssert] @@ -5797,7 +5797,7 @@ class A: i: type = A assert issubclass(i, A) -reveal_type(i.x) # E: Revealed type is 'builtins.int' +reveal_type(i.x) # N: Revealed type is 'builtins.int' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceTypeTypeVar] @@ -5812,11 +5812,11 @@ class C(Generic[T]): def meth(self, cls: Type[T]) -> None: if not issubclass(cls, Sub): return - reveal_type(cls) # E: Revealed type is 'Type[__main__.Sub]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Sub]' def other(self, cls: Type[T]) -> None: if not issubclass(cls, Sub): return - reveal_type(cls) # E: Revealed type is 'Type[__main__.Sub]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Sub]' [builtins fixtures/isinstancelist.pyi] @@ -5835,7 +5835,7 @@ def test() -> None: x = Other else: return - reveal_type(x) # E: Revealed type is 'Union[Type[__main__.One], Type[__main__.Other]]' + reveal_type(x) # N: Revealed type is 'Union[Type[__main__.One], Type[__main__.Other]]' [builtins fixtures/isinstancelist.pyi] [case testMemberRedefinition] @@ -5884,8 +5884,8 @@ class B: @dec def __new__(cls, x: int) -> B: ... -reveal_type(A) # E: Revealed type is 'def (x: builtins.int) -> __main__.A' -reveal_type(B) # E: Revealed type is 'def (x: builtins.int) -> __main__.B' +reveal_type(A) # N: Revealed type is 'def (x: builtins.int) -> __main__.A' +reveal_type(B) # N: Revealed type is 'def (x: builtins.int) -> __main__.B' [case testDecoratedConstructorsBad] from typing import Callable, Any diff --git a/test-data/unit/check-classvar.test b/test-data/unit/check-classvar.test index ba35e1ea8223..213aa42c776a 100644 --- a/test-data/unit/check-classvar.test +++ b/test-data/unit/check-classvar.test @@ -48,7 +48,7 @@ class A: A().x reveal_type(A().x) [out] -main:5: error: Revealed type is 'builtins.int' +main:5: note: Revealed type is 'builtins.int' [case testReadingFromSelf] from typing import ClassVar @@ -57,7 +57,7 @@ class A: def __init__(self) -> None: reveal_type(self.x) [out] -main:5: error: Revealed type is 'builtins.int' +main:5: note: Revealed type is 'builtins.int' [case testTypecheckSimple] from typing import ClassVar @@ -100,7 +100,7 @@ class A: x = None # type: ClassVar[int] reveal_type(A.x) [out] -main:4: error: Revealed type is 'builtins.int' +main:4: note: Revealed type is 'builtins.int' [case testInfer] from typing import ClassVar @@ -109,7 +109,7 @@ class A: y = A.x reveal_type(y) [out] -main:5: error: Revealed type is 'builtins.int' +main:5: note: Revealed type is 'builtins.int' [case testAssignmentOnUnion] from typing import ClassVar, Union @@ -166,7 +166,7 @@ A.x = B() reveal_type(A().x) [out] main:8: error: Incompatible types in assignment (expression has type "B", variable has type "Union[int, str]") -main:9: error: Revealed type is 'Union[builtins.int, builtins.str]' +main:9: note: Revealed type is 'Union[builtins.int, builtins.str]' [case testOverrideWithNarrowedUnion] from typing import ClassVar, Union @@ -278,5 +278,5 @@ from typing import ClassVar class A: x = None # type: ClassVar[int] [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' main:3: error: Cannot assign to class variable "x" via instance diff --git a/test-data/unit/check-ctypes.test b/test-data/unit/check-ctypes.test index 508b3bfd49c9..9784b99bdb8d 100644 --- a/test-data/unit/check-ctypes.test +++ b/test-data/unit/check-ctypes.test @@ -7,9 +7,9 @@ class MyCInt(ctypes.c_int): intarr4 = ctypes.c_int * 4 a = intarr4(1, ctypes.c_int(2), MyCInt(3), 4) intarr4(1, 2, 3, "invalid") # E: Array constructor argument 4 of type "builtins.str" is not convertible to the array element type "ctypes.c_int" -reveal_type(a) # E: Revealed type is 'ctypes.Array[ctypes.c_int]' -reveal_type(a[0]) # E: Revealed type is 'builtins.int' -reveal_type(a[1:3]) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a) # N: Revealed type is 'ctypes.Array[ctypes.c_int]' +reveal_type(a[0]) # N: Revealed type is 'builtins.int' +reveal_type(a[1:3]) # N: Revealed type is 'builtins.list[builtins.int]' a[0] = 42 a[1] = ctypes.c_int(42) a[2] = MyCInt(42) @@ -18,7 +18,7 @@ a[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches ar # N: def __setitem__(self, int, Union[c_int, int]) -> None \ # N: def __setitem__(self, slice, List[Union[c_int, int]]) -> None for x in a: - reveal_type(x) # E: Revealed type is 'builtins.int*' + reveal_type(x) # N: Revealed type is 'builtins.int*' [builtins fixtures/floatdict.pyi] [case testCtypesArrayCustomElementType] @@ -31,9 +31,9 @@ myintarr4 = MyCInt * 4 mya = myintarr4(1, 2, MyCInt(3), 4) myintarr4(1, ctypes.c_int(2), MyCInt(3), "invalid") # E: Array constructor argument 2 of type "ctypes.c_int" is not convertible to the array element type "__main__.MyCInt" \ # E: Array constructor argument 4 of type "builtins.str" is not convertible to the array element type "__main__.MyCInt" -reveal_type(mya) # E: Revealed type is 'ctypes.Array[__main__.MyCInt]' -reveal_type(mya[0]) # E: Revealed type is '__main__.MyCInt' -reveal_type(mya[1:3]) # E: Revealed type is 'builtins.list[__main__.MyCInt]' +reveal_type(mya) # N: Revealed type is 'ctypes.Array[__main__.MyCInt]' +reveal_type(mya[0]) # N: Revealed type is '__main__.MyCInt' +reveal_type(mya[1:3]) # N: Revealed type is 'builtins.list[__main__.MyCInt]' mya[0] = 42 mya[1] = ctypes.c_int(42) # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "c_int" \ # N: Possible overload variants: \ @@ -45,7 +45,7 @@ mya[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches # N: def __setitem__(self, int, Union[MyCInt, int]) -> None \ # N: def __setitem__(self, slice, List[Union[MyCInt, int]]) -> None for myx in mya: - reveal_type(myx) # E: Revealed type is '__main__.MyCInt*' + reveal_type(myx) # N: Revealed type is '__main__.MyCInt*' [builtins fixtures/floatdict.pyi] [case testCtypesArrayUnionElementType] @@ -56,9 +56,9 @@ class MyCInt(ctypes.c_int): pass mya: ctypes.Array[Union[MyCInt, ctypes.c_uint]] -reveal_type(mya) # E: Revealed type is 'ctypes.Array[Union[__main__.MyCInt, ctypes.c_uint]]' -reveal_type(mya[0]) # E: Revealed type is 'Union[__main__.MyCInt, builtins.int]' -reveal_type(mya[1:3]) # E: Revealed type is 'builtins.list[Union[__main__.MyCInt, builtins.int]]' +reveal_type(mya) # N: Revealed type is 'ctypes.Array[Union[__main__.MyCInt, ctypes.c_uint]]' +reveal_type(mya[0]) # N: Revealed type is 'Union[__main__.MyCInt, builtins.int]' +reveal_type(mya[1:3]) # N: Revealed type is 'builtins.list[Union[__main__.MyCInt, builtins.int]]' # The behavior here is not strictly correct, but intentional. # See the comment in mypy.plugins.ctypes._autoconvertible_to_cdata for details. mya[0] = 42 @@ -69,15 +69,15 @@ mya[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches # N: def __setitem__(self, int, Union[MyCInt, int, c_uint]) -> None \ # N: def __setitem__(self, slice, List[Union[MyCInt, int, c_uint]]) -> None for myx in mya: - reveal_type(myx) # E: Revealed type is 'Union[__main__.MyCInt, builtins.int]' + reveal_type(myx) # N: Revealed type is 'Union[__main__.MyCInt, builtins.int]' [builtins fixtures/floatdict.pyi] [case testCtypesCharArrayAttrs] import ctypes ca = (ctypes.c_char * 4)(b'a', b'b', b'c', b'\x00') -reveal_type(ca.value) # E: Revealed type is 'builtins.bytes' -reveal_type(ca.raw) # E: Revealed type is 'builtins.bytes' +reveal_type(ca.value) # N: Revealed type is 'builtins.bytes' +reveal_type(ca.raw) # N: Revealed type is 'builtins.bytes' [builtins fixtures/floatdict.pyi] [case testCtypesCharPArrayDoesNotCrash] @@ -92,15 +92,15 @@ ca = (ctypes.c_char_p * 0)() import ctypes ca = (ctypes.c_char * 4)('a', 'b', 'c', '\x00') -reveal_type(ca.value) # E: Revealed type is 'builtins.str' -reveal_type(ca.raw) # E: Revealed type is 'builtins.str' +reveal_type(ca.value) # N: Revealed type is 'builtins.str' +reveal_type(ca.raw) # N: Revealed type is 'builtins.str' [builtins_py2 fixtures/floatdict_python2.pyi] [case testCtypesWcharArrayAttrs] import ctypes wca = (ctypes.c_wchar * 4)('a', 'b', 'c', '\x00') -reveal_type(wca.value) # E: Revealed type is 'builtins.str' +reveal_type(wca.value) # N: Revealed type is 'builtins.str' wca.raw # E: ctypes.Array attribute "raw" is only available with element type c_char, not "ctypes.c_wchar" [builtins fixtures/floatdict.pyi] @@ -109,7 +109,7 @@ wca.raw # E: ctypes.Array attribute "raw" is only available with element type c import ctypes wca = (ctypes.c_wchar * 4)(u'a', u'b', u'c', u'\x00') -reveal_type(wca.value) # E: Revealed type is 'builtins.unicode' +reveal_type(wca.value) # N: Revealed type is 'builtins.unicode' wca.raw # E: ctypes.Array attribute "raw" is only available with element type c_char, not "ctypes.c_wchar" [builtins_py2 fixtures/floatdict_python2.pyi] @@ -118,7 +118,7 @@ import ctypes from typing import Union cua: ctypes.Array[Union[ctypes.c_char, ctypes.c_wchar]] -reveal_type(cua.value) # E: Revealed type is 'Union[builtins.bytes, builtins.str]' +reveal_type(cua.value) # N: Revealed type is 'Union[builtins.bytes, builtins.str]' cua.raw # E: ctypes.Array attribute "raw" is only available with element type c_char, not "Union[ctypes.c_char, ctypes.c_wchar]" [builtins fixtures/floatdict.pyi] @@ -127,8 +127,8 @@ import ctypes from typing import Any, Union caa: ctypes.Array[Union[ctypes.c_char, Any]] -reveal_type(caa.value) # E: Revealed type is 'Union[builtins.bytes, Any]' -reveal_type(caa.raw) # E: Revealed type is 'builtins.bytes' +reveal_type(caa.value) # N: Revealed type is 'Union[builtins.bytes, Any]' +reveal_type(caa.raw) # N: Revealed type is 'builtins.bytes' [builtins fixtures/floatdict.pyi] [case testCtypesOtherUnionArrayAttrs] @@ -144,8 +144,8 @@ cua.raw # E: ctypes.Array attribute "raw" is only available with element type c import ctypes aa: ctypes.Array[Any] -reveal_type(aa.value) # E: Revealed type is 'Any' -reveal_type(aa.raw) # E: Revealed type is 'builtins.bytes' +reveal_type(aa.value) # N: Revealed type is 'Any' +reveal_type(aa.raw) # N: Revealed type is 'builtins.bytes' [builtins fixtures/floatdict.pyi] [case testCtypesOtherArrayAttrs] @@ -163,10 +163,10 @@ intarr4 = ctypes.c_int * 4 intarr6 = ctypes.c_int * 6 int_values = [1, 2, 3, 4] c_int_values = [ctypes.c_int(1), ctypes.c_int(2), ctypes.c_int(3), ctypes.c_int(4)] -reveal_type(intarr4(*int_values)) # E: Revealed type is 'ctypes.Array[ctypes.c_int]' -reveal_type(intarr4(*c_int_values)) # E: Revealed type is 'ctypes.Array[ctypes.c_int]' -reveal_type(intarr6(1, ctypes.c_int(2), *int_values)) # E: Revealed type is 'ctypes.Array[ctypes.c_int]' -reveal_type(intarr6(1, ctypes.c_int(2), *c_int_values)) # E: Revealed type is 'ctypes.Array[ctypes.c_int]' +reveal_type(intarr4(*int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]' +reveal_type(intarr4(*c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]' +reveal_type(intarr6(1, ctypes.c_int(2), *int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]' +reveal_type(intarr6(1, ctypes.c_int(2), *c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]' float_values = [1.0, 2.0, 3.0, 4.0] intarr4(*float_values) # E: Array constructor argument 1 of type "builtins.list[builtins.float*]" is not convertible to the array element type "Iterable[ctypes.c_int]" diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index 44ac81cbc865..2b31c90a7110 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -6,7 +6,7 @@ [case testFunctionPluginFile] # flags: --config-file tmp/mypy.ini def f() -> str: ... -reveal_type(f()) # E: Revealed type is 'builtins.int' +reveal_type(f()) # N: Revealed type is 'builtins.int' [file mypy.ini] [[mypy] plugins=/test-data/unit/plugins/fnplugin.py @@ -14,7 +14,7 @@ plugins=/test-data/unit/plugins/fnplugin.py [case testFunctionPlugin] # flags: --config-file tmp/mypy.ini def f() -> str: ... -reveal_type(f()) # E: Revealed type is 'builtins.int' +reveal_type(f()) # N: Revealed type is 'builtins.int' [file mypy.ini] [[mypy] plugins=fnplugin @@ -35,9 +35,9 @@ plugins=/test-data/unit/plugins/fnplugin.py def f(): ... def g(): ... def h(): ... -reveal_type(f()) # E: Revealed type is 'builtins.int' -reveal_type(g()) # E: Revealed type is 'builtins.str' -reveal_type(h()) # E: Revealed type is 'Any' +reveal_type(f()) # N: Revealed type is 'builtins.int' +reveal_type(g()) # N: Revealed type is 'builtins.str' +reveal_type(h()) # N: Revealed type is 'Any' [file mypy.ini] [[mypy] plugins=/test-data/unit/plugins/fnplugin.py, @@ -48,9 +48,9 @@ plugins=/test-data/unit/plugins/fnplugin.py, def f(): ... def g(): ... def h(): ... -reveal_type(f()) # E: Revealed type is 'builtins.int' -reveal_type(g()) # E: Revealed type is 'builtins.str' -reveal_type(h()) # E: Revealed type is 'Any' +reveal_type(f()) # N: Revealed type is 'builtins.int' +reveal_type(g()) # N: Revealed type is 'builtins.str' +reveal_type(h()) # N: Revealed type is 'Any' [file mypy.ini] [[mypy] plugins=/test-data/unit/plugins/fnplugin.py, plugin2 @@ -105,7 +105,7 @@ tmp/mypy.ini:2: error: Plugin '/test-data/unit/plugins/noentry.py' does no [case testCustomPluginEntryPointFile] # flags: --config-file tmp/mypy.ini def f() -> str: ... -reveal_type(f()) # E: Revealed type is 'builtins.int' +reveal_type(f()) # N: Revealed type is 'builtins.int' [file mypy.ini] [[mypy] plugins=/test-data/unit/plugins/customentry.py:register @@ -113,7 +113,7 @@ plugins=/test-data/unit/plugins/customentry.py:register [case testCustomPluginEntryPoint] # flags: --config-file tmp/mypy.ini def f() -> str: ... -reveal_type(f()) # E: Revealed type is 'builtins.int' +reveal_type(f()) # N: Revealed type is 'builtins.int' [file mypy.ini] [[mypy] plugins=customentry:register @@ -165,12 +165,12 @@ plugins=/test-data/unit/plugins/attrhook.py from m import Magic, DerivedMagic magic = Magic() -reveal_type(magic.magic_field) # E: Revealed type is 'builtins.str' -reveal_type(magic.non_magic_method()) # E: Revealed type is 'builtins.int' -reveal_type(magic.non_magic_field) # E: Revealed type is 'builtins.int' +reveal_type(magic.magic_field) # N: Revealed type is 'builtins.str' +reveal_type(magic.non_magic_method()) # N: Revealed type is 'builtins.int' +reveal_type(magic.non_magic_field) # N: Revealed type is 'builtins.int' magic.nonexistent_field # E: Field does not exist -reveal_type(magic.fallback_example) # E: Revealed type is 'Any' -reveal_type(DerivedMagic().magic_field) # E: Revealed type is 'builtins.str' +reveal_type(magic.fallback_example) # N: Revealed type is 'Any' +reveal_type(DerivedMagic().magic_field) # N: Revealed type is 'builtins.str' [file m.py] from typing import Any class Magic: @@ -191,7 +191,7 @@ from typing import Callable 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 =)]' +reveal_type(s) # N: Revealed type is 'm.Signal[def (builtins.int, x: builtins.str =)]' 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] @@ -218,9 +218,9 @@ class C: z = AnotherAlias(int, required=False) c = C() -reveal_type(c.x) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(c.y) # E: Revealed type is 'builtins.int*' -reveal_type(c.z) # E: Revealed type is 'Union[builtins.int*, None]' +reveal_type(c.x) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(c.y) # N: Revealed type is 'builtins.int*' +reveal_type(c.z) # N: Revealed type is 'Union[builtins.int*, None]' [file mod.py] from typing import Generic, TypeVar, Type @@ -249,8 +249,8 @@ from m import decorator1, decorator2 def f() -> None: pass @decorator2() def g() -> None: pass -reveal_type(f) # E: Revealed type is 'def (*Any, **Any) -> builtins.str' -reveal_type(g) # E: Revealed type is 'def (*Any, **Any) -> builtins.int' +reveal_type(f) # N: Revealed type is 'def (*Any, **Any) -> builtins.str' +reveal_type(g) # N: Revealed type is 'def (*Any, **Any) -> builtins.int' [file m.py] from typing import Callable def decorator1() -> Callable[..., Callable[..., int]]: pass @@ -263,11 +263,11 @@ plugins=/test-data/unit/plugins/named_callable.py # flags: --config-file tmp/mypy.ini from mod import Class, func -reveal_type(Class().method(arg1=1, arg2=2, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(Class.myclassmethod(arg1=1, arg2=2, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(Class.mystaticmethod(arg1=1, arg2=2, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(Class.method(self=Class(), arg1=1, arg2=2, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(func(arg1=1, arg2=2, classname='builtins.str')) # E: Revealed type is 'builtins.str' +reveal_type(Class().method(arg1=1, arg2=2, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(Class.myclassmethod(arg1=1, arg2=2, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(Class.mystaticmethod(arg1=1, arg2=2, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(Class.method(self=Class(), arg1=1, arg2=2, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(func(arg1=1, arg2=2, classname='builtins.str')) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any @@ -292,11 +292,11 @@ plugins=/test-data/unit/plugins/arg_names.py # flags: --config-file tmp/mypy.ini from mod import Class, func -reveal_type(Class().method('builtins.str', arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' -reveal_type(Class.myclassmethod('builtins.str', arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' -reveal_type(Class.mystaticmethod('builtins.str', arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' -reveal_type(Class.method(Class(), 'builtins.str', arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' -reveal_type(func('builtins.str', arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' +reveal_type(Class().method('builtins.str', arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' +reveal_type(Class.myclassmethod('builtins.str', arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' +reveal_type(Class.mystaticmethod('builtins.str', arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' +reveal_type(Class.method(Class(), 'builtins.str', arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' +reveal_type(func('builtins.str', arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any @@ -321,9 +321,9 @@ plugins=/test-data/unit/plugins/arg_names.py # flags: --config-file tmp/mypy.ini from mod import ClassInit, Outer -reveal_type(ClassInit('builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(ClassInit(classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(Outer.NestedClassInit(classname='builtins.str')) # E: Revealed type is 'builtins.str' +reveal_type(ClassInit('builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(ClassInit(classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(Outer.NestedClassInit(classname='builtins.str')) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any class ClassInit: @@ -342,12 +342,12 @@ plugins=/test-data/unit/plugins/arg_names.py # flags: --config-file tmp/mypy.ini from mod import ClassUnfilled, func_unfilled -reveal_type(ClassUnfilled().method(classname='builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassUnfilled().method(arg2=1, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(ClassUnfilled().method('builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(func_unfilled(classname='builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(func_unfilled(arg2=1, classname='builtins.str')) # E: Revealed type is 'builtins.str' -reveal_type(func_unfilled('builtins.str')) # E: Revealed type is 'builtins.str' +reveal_type(ClassUnfilled().method(classname='builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassUnfilled().method(arg2=1, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(ClassUnfilled().method('builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(func_unfilled(classname='builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(func_unfilled(arg2=1, classname='builtins.str')) # N: Revealed type is 'builtins.str' +reveal_type(func_unfilled('builtins.str')) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any @@ -365,13 +365,13 @@ plugins=/test-data/unit/plugins/arg_names.py # flags: --config-file tmp/mypy.ini from mod import ClassStarExpr, func_star_expr -reveal_type(ClassStarExpr().method(classname='builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassStarExpr().method('builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassStarExpr().method('builtins.str', arg1=1, arg2=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassStarExpr().method('builtins.str', 2, 3, 4, arg1=1, arg2=1)) # E: Revealed type is 'builtins.str' -reveal_type(func_star_expr(classname='builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(func_star_expr('builtins.str', arg1=1)) # E: Revealed type is 'builtins.str' -reveal_type(func_star_expr('builtins.str', 2, 3, 4, arg1=1, arg2=2)) # E: Revealed type is 'builtins.str' +reveal_type(ClassStarExpr().method(classname='builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassStarExpr().method('builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassStarExpr().method('builtins.str', arg1=1, arg2=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassStarExpr().method('builtins.str', 2, 3, 4, arg1=1, arg2=1)) # N: Revealed type is 'builtins.str' +reveal_type(func_star_expr(classname='builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(func_star_expr('builtins.str', arg1=1)) # N: Revealed type is 'builtins.str' +reveal_type(func_star_expr('builtins.str', 2, 3, 4, arg1=1, arg2=2)) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any @@ -390,10 +390,10 @@ plugins=/test-data/unit/plugins/arg_names.py # flags: --config-file tmp/mypy.ini from mod import ClassChild -reveal_type(ClassChild().method(classname='builtins.str', arg1=1, arg2=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassChild().method(arg1=1, classname='builtins.str', arg2=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassChild().method('builtins.str', arg1=1, arg2=1)) # E: Revealed type is 'builtins.str' -reveal_type(ClassChild.myclassmethod('builtins.str')) # E: Revealed type is 'builtins.str' +reveal_type(ClassChild().method(classname='builtins.str', arg1=1, arg2=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassChild().method(arg1=1, classname='builtins.str', arg2=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassChild().method('builtins.str', arg1=1, arg2=1)) # N: Revealed type is 'builtins.str' +reveal_type(ClassChild.myclassmethod('builtins.str')) # N: Revealed type is 'builtins.str' [file mod.py] from typing import Any class Base: @@ -427,12 +427,12 @@ class Foo: def m(self, arg: str) -> str: ... foo = Foo() -reveal_type(foo.m(2)) # E: Revealed type is 'builtins.int' -reveal_type(foo[3]) # E: Revealed type is 'builtins.int' -reveal_type(foo(4, 5, 6)) # E: Revealed type is 'builtins.int' +reveal_type(foo.m(2)) # N: Revealed type is 'builtins.int' +reveal_type(foo[3]) # N: Revealed type is 'builtins.int' +reveal_type(foo(4, 5, 6)) # N: Revealed type is 'builtins.int' foo[4] = 5 for x in foo: - reveal_type(x) # E: Revealed type is 'builtins.int*' + reveal_type(x) # N: Revealed type is 'builtins.int*' [file mypy.ini] [[mypy] @@ -454,9 +454,9 @@ class FullyQualifiedTestTypedDict(TypedDict): FullyQualifiedTestNamedTuple = NamedTuple('FullyQualifiedTestNamedTuple', [('foo', str)]) # Check the return types to ensure that the method signature hook is called in each case -reveal_type(FullyQualifiedTestClass.class_method()) # E: Revealed type is 'builtins.int' -reveal_type(FullyQualifiedTestClass().instance_method()) # E: Revealed type is 'builtins.int' -reveal_type(FullyQualifiedTestNamedTuple('')._asdict()) # E: Revealed type is 'builtins.int' +reveal_type(FullyQualifiedTestClass.class_method()) # N: Revealed type is 'builtins.int' +reveal_type(FullyQualifiedTestClass().instance_method()) # N: Revealed type is 'builtins.int' +reveal_type(FullyQualifiedTestNamedTuple('')._asdict()) # N: Revealed type is 'builtins.int' [file mypy.ini] [[mypy] @@ -474,8 +474,8 @@ class Model(Base): class Other: x: Column[int] -reveal_type(Model().x) # E: Revealed type is 'mod.Instr[builtins.int]' -reveal_type(Other().x) # E: Revealed type is 'mod.Column[builtins.int]' +reveal_type(Model().x) # N: Revealed type is 'mod.Instr[builtins.int]' +reveal_type(Other().x) # N: Revealed type is 'mod.Column[builtins.int]' [file mod.py] from typing import Generic, TypeVar def declarative_base(): ... @@ -544,7 +544,7 @@ python_version=3.6 plugins=/test-data/unit/plugins/common_api_incremental.py [out] [out2] -tmp/a.py:3: error: Revealed type is 'builtins.str' +tmp/a.py:3: note: Revealed type is 'builtins.str' tmp/a.py:4: error: "Type[Base]" has no attribute "__magic__" [case testArgKindsMethod] @@ -577,9 +577,9 @@ T = TypeVar("T") class Class(Generic[T]): def __init__(self, one: T): ... def __call__(self, two: T) -> int: ... -reveal_type(Class("hi")("there")) # E: Revealed type is 'builtins.str*' +reveal_type(Class("hi")("there")) # N: Revealed type is 'builtins.str*' instance = Class(3.14) -reveal_type(instance(2)) # E: Revealed type is 'builtins.float*' +reveal_type(instance(2)) # N: Revealed type is 'builtins.float*' [file mypy.ini] [[mypy] diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index 65cc4768143f..cac18b239d62 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -10,7 +10,7 @@ class Person: def summary(self): return "%s is %d years old." % (self.name, self.age) -reveal_type(Person) # E: Revealed type is 'def (name: builtins.str, age: builtins.int) -> __main__.Person' +reveal_type(Person) # N: Revealed type is 'def (name: builtins.str, age: builtins.int) -> __main__.Person' Person('John', 32) Person('Jonh', 21, None) # E: Too many arguments for "Person" @@ -31,7 +31,7 @@ class Person(Mammal): def summary(self): return "%s is %d years old." % (self.name, self.age) -reveal_type(Person) # E: Revealed type is 'def (age: builtins.int, name: builtins.str) -> __main__.Person' +reveal_type(Person) # N: Revealed type is 'def (age: builtins.int, name: builtins.str) -> __main__.Person' Mammal(10) Person(32, 'John') Person(21, 'Jonh', None) # E: Too many arguments for "Person" @@ -58,10 +58,10 @@ class C(B): class D(C): d: int -reveal_type(A) # E: Revealed type is 'def (a: builtins.int) -> __main__.A' -reveal_type(B) # E: Revealed type is 'def (a: builtins.int, b: builtins.int) -> __main__.B' -reveal_type(C) # E: Revealed type is 'def (a: builtins.int, b: builtins.int, c: builtins.int) -> __main__.C' -reveal_type(D) # E: Revealed type is 'def (a: builtins.int, b: builtins.int, c: builtins.int, d: builtins.int) -> __main__.D' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int) -> __main__.A' +reveal_type(B) # N: Revealed type is 'def (a: builtins.int, b: builtins.int) -> __main__.B' +reveal_type(C) # N: Revealed type is 'def (a: builtins.int, b: builtins.int, c: builtins.int) -> __main__.C' +reveal_type(D) # N: Revealed type is 'def (a: builtins.int, b: builtins.int, c: builtins.int, d: builtins.int) -> __main__.D' [builtins fixtures/list.pyi] @@ -88,9 +88,9 @@ class ExtraSpecialPerson(SpecialPerson): special_factor: float name: str -reveal_type(Person) # E: Revealed type is 'def (age: builtins.int, name: builtins.str) -> __main__.Person' -reveal_type(SpecialPerson) # E: Revealed type is 'def (age: builtins.int, name: builtins.str, special_factor: builtins.float) -> __main__.SpecialPerson' -reveal_type(ExtraSpecialPerson) # E: Revealed type is 'def (age: builtins.int, name: builtins.str, special_factor: builtins.float) -> __main__.ExtraSpecialPerson' +reveal_type(Person) # N: Revealed type is 'def (age: builtins.int, name: builtins.str) -> __main__.Person' +reveal_type(SpecialPerson) # N: Revealed type is 'def (age: builtins.int, name: builtins.str, special_factor: builtins.float) -> __main__.SpecialPerson' +reveal_type(ExtraSpecialPerson) # N: Revealed type is 'def (age: builtins.int, name: builtins.str, special_factor: builtins.float) -> __main__.ExtraSpecialPerson' Person(32, 'John') Person(21, 'John', None) # E: Too many arguments for "Person" SpecialPerson(21, 'John', 0.5) @@ -114,7 +114,7 @@ class Base: class C(Base): some_int: int -reveal_type(C) # E: Revealed type is 'def (some_int: builtins.int, some_str: builtins.str =) -> __main__.C' +reveal_type(C) # N: Revealed type is 'def (some_int: builtins.int, some_str: builtins.str =) -> __main__.C' [builtins fixtures/list.pyi] @@ -140,7 +140,7 @@ class Person: name: str age: int = field(default=0, init=False) -reveal_type(Person) # E: Revealed type is 'def (name: builtins.str) -> __main__.Person' +reveal_type(Person) # N: Revealed type is 'def (name: builtins.str) -> __main__.Person' john = Person('John') john.age = 'invalid' # E: Incompatible types in assignment (expression has type "str", variable has type "int") john.age = 24 @@ -173,7 +173,7 @@ class Person: friend_names: List[str] = field(init=True) enemy_names: List[str] -reveal_type(Person) # E: Revealed type is 'def (name: builtins.str, friend_names: builtins.list[builtins.str], enemy_names: builtins.list[builtins.str]) -> __main__.Person' +reveal_type(Person) # N: Revealed type is 'def (name: builtins.str, friend_names: builtins.list[builtins.str], enemy_names: builtins.list[builtins.str]) -> __main__.Person' [builtins fixtures/list.pyi] @@ -190,7 +190,7 @@ class Person: enemy_names: List[str] nickname: Optional[str] = None -reveal_type(Person) # E: Revealed type is 'def (name: builtins.str, friend_names: builtins.list[builtins.str], enemy_names: builtins.list[builtins.str], nickname: Union[builtins.str, None] =) -> __main__.Person' +reveal_type(Person) # N: Revealed type is 'def (name: builtins.str, friend_names: builtins.list[builtins.str], enemy_names: builtins.list[builtins.str], nickname: Union[builtins.str, None] =) -> __main__.Person' [builtins fixtures/list.pyi] @@ -203,7 +203,7 @@ class Application: name: str = 'Unnamed' rating: int = 0 -reveal_type(Application) # E: Revealed type is 'def (name: builtins.str =, rating: builtins.int =) -> __main__.Application' +reveal_type(Application) # N: Revealed type is 'def (name: builtins.str =, rating: builtins.int =) -> __main__.Application' app = Application() [builtins fixtures/list.pyi] @@ -283,12 +283,12 @@ class A: @classmethod def foo(cls, x: Union[int, str]) -> Union[int, str]: - reveal_type(cls) # E: Revealed type is 'Type[__main__.A]' - reveal_type(cls.other()) # E: Revealed type is 'builtins.str' + reveal_type(cls) # N: Revealed type is 'Type[__main__.A]' + reveal_type(cls.other()) # N: Revealed type is 'builtins.str' return x -reveal_type(A.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(A.foo("foo")) # E: Revealed type is 'builtins.str' +reveal_type(A.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(A.foo("foo")) # N: Revealed type is 'builtins.str' [builtins fixtures/classmethod.pyi] @@ -303,7 +303,7 @@ class Application: COUNTER: ClassVar[int] = 0 -reveal_type(Application) # E: Revealed type is 'def (name: builtins.str) -> __main__.Application' +reveal_type(Application) # N: Revealed type is 'def (name: builtins.str) -> __main__.Application' application = Application("example") application.COUNTER = 1 # E: Cannot assign to class variable "COUNTER" via instance Application.COUNTER = 1 @@ -418,7 +418,7 @@ class Application: class SpecializedApplication(Application): rating: int = 0 -reveal_type(SpecializedApplication) # E: Revealed type is 'def (id: Union[builtins.int, None], name: builtins.str, rating: builtins.int =) -> __main__.SpecializedApplication' +reveal_type(SpecializedApplication) # N: Revealed type is 'def (id: Union[builtins.int, None], name: builtins.str, rating: builtins.int =) -> __main__.SpecializedApplication' [builtins fixtures/list.pyi] @@ -444,13 +444,13 @@ class A(Generic[T]): def problem(self) -> T: return self.z # E: Incompatible return value type (got "List[T]", expected "T") -reveal_type(A) # E: Revealed type is 'def [T] (x: T`1, y: T`1, z: builtins.list[T`1]) -> __main__.A[T`1]' +reveal_type(A) # N: Revealed type is 'def [T] (x: T`1, y: T`1, z: builtins.list[T`1]) -> __main__.A[T`1]' A(1, 2, ["a", "b"]) # E: Cannot infer type argument 1 of "A" a = A(1, 2, [1, 2]) -reveal_type(a) # E: Revealed type is '__main__.A[builtins.int*]' -reveal_type(a.x) # E: Revealed type is 'builtins.int*' -reveal_type(a.y) # E: Revealed type is 'builtins.int*' -reveal_type(a.z) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(a) # N: Revealed type is '__main__.A[builtins.int*]' +reveal_type(a.x) # N: Revealed type is 'builtins.int*' +reveal_type(a.y) # N: Revealed type is 'builtins.int*' +reveal_type(a.z) # N: Revealed type is 'builtins.list[builtins.int*]' s: str = a.bar() # E: Incompatible types in assignment (expression has type "int", variable has type "str") [builtins fixtures/list.pyi] @@ -468,9 +468,9 @@ class A(Generic[T]): @classmethod def foo(cls) -> None: - reveal_type(cls) # E: Revealed type is 'Type[__main__.A[T`1]]' - reveal_type(cls(1)) # E: Revealed type is '__main__.A[builtins.int*]' - reveal_type(cls('wooooo')) # E: Revealed type is '__main__.A[builtins.str*]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.A[T`1]]' + reveal_type(cls(1)) # N: Revealed type is '__main__.A[builtins.int*]' + reveal_type(cls('wooooo')) # N: Revealed type is '__main__.A[builtins.str*]' [builtins fixtures/classmethod.pyi] @@ -485,7 +485,7 @@ class A: class B: x: int -reveal_type(A) # E: Revealed type is 'def (b: __main__.B) -> __main__.A' +reveal_type(A) # N: Revealed type is 'def (b: __main__.B) -> __main__.A' A(b=B(42)) A(b=42) # E: Argument "b" to "A" has incompatible type "int"; expected "B" @@ -500,7 +500,7 @@ class Application: name: str database_name: InitVar[str] -reveal_type(Application) # E: Revealed type is 'def (name: builtins.str, database_name: builtins.str) -> __main__.Application' +reveal_type(Application) # N: Revealed type is 'def (name: builtins.str, database_name: builtins.str) -> __main__.Application' app = Application("example", 42) # E: Argument 2 to "Application" has incompatible type "int"; expected "str" app = Application("example", "apps") app.name @@ -511,7 +511,7 @@ app.database_name # E: "Application" has no attribute "database_name" class SpecializedApplication(Application): rating: int -reveal_type(SpecializedApplication) # E: Revealed type is 'def (name: builtins.str, database_name: builtins.str, rating: builtins.int) -> __main__.SpecializedApplication' +reveal_type(SpecializedApplication) # N: Revealed type is 'def (name: builtins.str, database_name: builtins.str, rating: builtins.int) -> __main__.SpecializedApplication' app = SpecializedApplication("example", "apps", "five") # E: Argument 3 to "SpecializedApplication" has incompatible type "str"; expected "int" app = SpecializedApplication("example", "apps", 5) app.name @@ -531,7 +531,7 @@ class Application: name: str database_name: InitVar[str] -reveal_type(Application) # E: Revealed type is 'def (name: builtins.str, database_name: builtins.str) -> __main__.Application' +reveal_type(Application) # N: Revealed type is 'def (name: builtins.str, database_name: builtins.str) -> __main__.Application' app = Application("example", 42) # E: Argument 2 to "Application" has incompatible type "int"; expected "str" app = Application("example", "apps") app.name @@ -550,8 +550,8 @@ T = TypeVar('T', bound='A') class A: @classmethod def make(cls: Type[T]) -> T: - reveal_type(cls) # E: Revealed type is 'Type[T`-1]' - reveal_type(cls()) # E: Revealed type is 'T`-1' + reveal_type(cls) # N: Revealed type is 'Type[T`-1]' + reveal_type(cls()) # N: Revealed type is 'T`-1' return cls() [builtins fixtures/classmethod.pyi] @@ -591,7 +591,7 @@ class B: class C(List[C]): pass -reveal_type(B) # E: Revealed type is 'def (x: __main__.C) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (x: __main__.C) -> __main__.B' [builtins fixtures/list.pyi] [case testDisallowUntypedWorksForwardBad] @@ -603,7 +603,7 @@ class B: x: Undefined # E: Name 'Undefined' is not defined y = undefined() # E: Name 'undefined' is not defined -reveal_type(B) # E: Revealed type is 'def (x: Any) -> __main__.B' +reveal_type(B) # N: Revealed type is 'def (x: Any) -> __main__.B' [builtins fixtures/list.pyi] [case testMemberExprWorksAsField] diff --git a/test-data/unit/check-default-plugin.test b/test-data/unit/check-default-plugin.test index 1aae55ff46eb..e331ff73a8f1 100644 --- a/test-data/unit/check-default-plugin.test +++ b/test-data/unit/check-default-plugin.test @@ -13,10 +13,10 @@ T = TypeVar('T') def yield_id(item: T) -> Iterator[T]: yield item -reveal_type(yield_id) # E: Revealed type is 'def [T] (item: T`-1) -> contextlib.GeneratorContextManager[T`-1]' +reveal_type(yield_id) # N: Revealed type is 'def [T] (item: T`-1) -> contextlib.GeneratorContextManager[T`-1]' with yield_id(1) as x: - reveal_type(x) # E: Revealed type is 'builtins.int*' + reveal_type(x) # N: Revealed type is 'builtins.int*' f = yield_id def g(x, y): pass @@ -28,6 +28,6 @@ from contextlib import contextmanager from typing import Callable, Iterator c: Callable[..., Iterator[int]] -reveal_type(c) # E: Revealed type is 'def (*Any, **Any) -> typing.Iterator[builtins.int]' -reveal_type(contextmanager(c)) # E: Revealed type is 'def (*Any, **Any) -> contextlib.GeneratorContextManager[builtins.int*]' +reveal_type(c) # N: Revealed type is 'def (*Any, **Any) -> typing.Iterator[builtins.int]' +reveal_type(contextmanager(c)) # N: Revealed type is 'def (*Any, **Any) -> contextlib.GeneratorContextManager[builtins.int*]' [typing fixtures/typing-full.pyi] diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 26c7609d07df..431f0c9b241f 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -6,7 +6,7 @@ class Medal(Enum): gold = 1 silver = 2 bronze = 3 -reveal_type(Medal.bronze) # E: Revealed type is '__main__.Medal' +reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal' m = Medal.gold if int(): m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal") @@ -20,7 +20,7 @@ class Medal(metaclass=EnumMeta): # Without __init__ the definition fails at runtime, but we want to verify that mypy # uses `enum.EnumMeta` and not `enum.Enum` as the definition of what is enum. def __init__(self, *args): pass -reveal_type(Medal.bronze) # E: Revealed type is '__main__.Medal' +reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal' m = Medal.gold if int(): m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal") @@ -34,7 +34,7 @@ class Medal(Achievement): bronze = None # See comment in testEnumFromEnumMetaBasics def __init__(self, *args): pass -reveal_type(Medal.bronze) # E: Revealed type is '__main__.Medal' +reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal' m = Medal.gold if int(): m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal") @@ -53,8 +53,8 @@ class Truth(Enum): false = False x = '' x = Truth.true.name -reveal_type(Truth.true.name) # E: Revealed type is 'builtins.str' -reveal_type(Truth.false.value) # E: Revealed type is 'builtins.bool' +reveal_type(Truth.true.name) # N: Revealed type is 'builtins.str' +reveal_type(Truth.false.value) # N: Revealed type is 'builtins.bool' [builtins fixtures/bool.pyi] [case testEnumUnique] @@ -167,7 +167,7 @@ class E(IntEnum): x = None # type: int reveal_type(E(x)) [out] -main:5: error: Revealed type is '__main__.E' +main:5: note: Revealed type is '__main__.E' [case testEnumIndex] from enum import IntEnum @@ -176,7 +176,7 @@ class E(IntEnum): s = None # type: str reveal_type(E[s]) [out] -main:5: error: Revealed type is '__main__.E' +main:5: note: Revealed type is '__main__.E' [case testEnumIndexError] from enum import IntEnum @@ -191,16 +191,16 @@ from enum import Enum class E(Enum): a = 1 b = 2 -reveal_type(E['a']) # E: Revealed type is '__main__.E' +reveal_type(E['a']) # N: Revealed type is '__main__.E' E['a'] x = E['a'] -reveal_type(x) # E: Revealed type is '__main__.E' +reveal_type(x) # N: Revealed type is '__main__.E' def get_member(name: str) -> E: val = E[name] return val -reveal_type(get_member('a')) # E: Revealed type is '__main__.E' +reveal_type(get_member('a')) # N: Revealed type is '__main__.E' [case testGenericEnum] from enum import Enum @@ -212,7 +212,7 @@ class F(Generic[T], Enum): # E: Enum class cannot be generic x: T y: T -reveal_type(F[int].x) # E: Revealed type is '__main__.F[builtins.int*]' +reveal_type(F[int].x) # N: Revealed type is '__main__.F[builtins.int*]' [case testEnumFlag] from enum import Flag @@ -246,7 +246,7 @@ class A: a = A() reveal_type(a.x) [out] -main:8: error: Revealed type is '__main__.E@4' +main:8: note: Revealed type is '__main__.E@4' [case testEnumInClassBody] from enum import Enum @@ -270,10 +270,10 @@ reveal_type(E.bar.value) reveal_type(I.bar) reveal_type(I.baz.value) [out] -main:4: error: Revealed type is '__main__.E' -main:5: error: Revealed type is 'Any' -main:6: error: Revealed type is '__main__.I' -main:7: error: Revealed type is 'builtins.int' +main:4: note: Revealed type is '__main__.E' +main:5: note: Revealed type is 'Any' +main:6: note: Revealed type is '__main__.I' +main:7: note: Revealed type is 'builtins.int' [case testFunctionalEnumListOfStrings] from enum import Enum, IntEnum @@ -282,8 +282,8 @@ F = IntEnum('F', ['bar', 'baz']) reveal_type(E.foo) reveal_type(F.baz) [out] -main:4: error: Revealed type is '__main__.E' -main:5: error: Revealed type is '__main__.F' +main:4: note: Revealed type is '__main__.E' +main:5: note: Revealed type is '__main__.F' [case testFunctionalEnumListOfPairs] from enum import Enum, IntEnum @@ -294,10 +294,10 @@ reveal_type(F.baz) reveal_type(E.foo.value) reveal_type(F.bar.name) [out] -main:4: error: Revealed type is '__main__.E' -main:5: error: Revealed type is '__main__.F' -main:6: error: Revealed type is 'builtins.int' -main:7: error: Revealed type is 'builtins.str' +main:4: note: Revealed type is '__main__.E' +main:5: note: Revealed type is '__main__.F' +main:6: note: Revealed type is 'builtins.int' +main:7: note: Revealed type is 'builtins.str' [case testFunctionalEnumDict] from enum import Enum, IntEnum @@ -308,10 +308,10 @@ reveal_type(F.baz) reveal_type(E.foo.value) reveal_type(F.bar.name) [out] -main:4: error: Revealed type is '__main__.E' -main:5: error: Revealed type is '__main__.F' -main:6: error: Revealed type is 'builtins.int' -main:7: error: Revealed type is 'builtins.str' +main:4: note: Revealed type is '__main__.E' +main:5: note: Revealed type is '__main__.F' +main:6: note: Revealed type is 'builtins.int' +main:7: note: Revealed type is 'builtins.str' [case testFunctionalEnumErrors] from enum import Enum, IntEnum @@ -363,14 +363,14 @@ main:22: error: "Type[W]" has no attribute "c" from enum import Flag, IntFlag A = Flag('A', 'x y') B = IntFlag('B', 'a b') -reveal_type(A.x) # E: Revealed type is '__main__.A' -reveal_type(B.a) # E: Revealed type is '__main__.B' -reveal_type(A.x.name) # E: Revealed type is 'builtins.str' -reveal_type(B.a.name) # E: Revealed type is 'builtins.str' +reveal_type(A.x) # N: Revealed type is '__main__.A' +reveal_type(B.a) # N: Revealed type is '__main__.B' +reveal_type(A.x.name) # N: Revealed type is 'builtins.str' +reveal_type(B.a.name) # N: Revealed type is 'builtins.str' # TODO: The revealed type should be 'int' here -reveal_type(A.x.value) # E: Revealed type is 'Any' -reveal_type(B.a.value) # E: Revealed type is 'Any' +reveal_type(A.x.value) # N: Revealed type is 'Any' +reveal_type(B.a.value) # N: Revealed type is 'Any' [case testAnonymousFunctionalEnum] from enum import Enum @@ -381,7 +381,7 @@ class A: a = A() reveal_type(a.x) [out] -main:7: error: Revealed type is '__main__.A.E@4' +main:7: note: Revealed type is '__main__.A.E@4' [case testFunctionalEnumInClassBody] from enum import Enum @@ -397,10 +397,10 @@ if int(): [case testFunctionalEnumProtocols] from enum import IntEnum Color = IntEnum('Color', 'red green blue') -reveal_type(Color['green']) # E: Revealed type is '__main__.Color' +reveal_type(Color['green']) # N: Revealed type is '__main__.Color' for c in Color: - reveal_type(c) # E: Revealed type is '__main__.Color*' -reveal_type(list(Color)) # E: Revealed type is 'builtins.list[__main__.Color*]' + reveal_type(c) # N: Revealed type is '__main__.Color*' +reveal_type(list(Color)) # N: Revealed type is 'builtins.list[__main__.Color*]' [builtins fixtures/list.pyi] @@ -451,11 +451,11 @@ F = Enum('F', 'a b') [rechecked] [stale] [out1] -main:2: error: Revealed type is 'm.E' -main:3: error: Revealed type is 'm.F' +main:2: note: Revealed type is 'm.E' +main:3: note: Revealed type is 'm.F' [out2] -main:2: error: Revealed type is 'm.E' -main:3: error: Revealed type is 'm.F' +main:2: note: Revealed type is 'm.E' +main:3: note: Revealed type is 'm.F' [case testEnumAuto] from enum import Enum, auto @@ -463,7 +463,7 @@ class Test(Enum): a = auto() b = auto() -reveal_type(Test.a) # E: Revealed type is '__main__.Test' +reveal_type(Test.a) # N: Revealed type is '__main__.Test' [builtins fixtures/primitives.pyi] [case testEnumAttributeAccessMatrix] @@ -478,18 +478,18 @@ class A2(Enum): class A3(Enum): x = 1 -is_x(reveal_type(A1.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(A1.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(A1.x.value) # E: Revealed type is 'Any' -reveal_type(A1.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(A2.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(A2.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(A2.x.value) # E: Revealed type is 'Any' -reveal_type(A2.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(A3.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(A3.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(A3.x.value) # E: Revealed type is 'builtins.int' -reveal_type(A3.x._value_) # E: Revealed type is 'builtins.int' +is_x(reveal_type(A1.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(A1.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(A1.x.value) # N: Revealed type is 'Any' +reveal_type(A1.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(A2.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(A2.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(A2.x.value) # N: Revealed type is 'Any' +reveal_type(A2.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(A3.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(A3.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(A3.x.value) # N: Revealed type is 'builtins.int' +reveal_type(A3.x._value_) # N: Revealed type is 'builtins.int' B1 = IntEnum('B1', 'x') class B2(IntEnum): @@ -499,18 +499,18 @@ class B3(IntEnum): # TODO: getting B1.x._value_ and B2.x._value_ to have type 'int' requires a typeshed change -is_x(reveal_type(B1.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(B1.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(B1.x.value) # E: Revealed type is 'builtins.int' -reveal_type(B1.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(B2.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(B2.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(B2.x.value) # E: Revealed type is 'builtins.int' -reveal_type(B2.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(B3.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(B3.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(B3.x.value) # E: Revealed type is 'builtins.int' -reveal_type(B3.x._value_) # E: Revealed type is 'builtins.int' +is_x(reveal_type(B1.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(B1.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(B1.x.value) # N: Revealed type is 'builtins.int' +reveal_type(B1.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(B2.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(B2.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(B2.x.value) # N: Revealed type is 'builtins.int' +reveal_type(B2.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(B3.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(B3.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(B3.x.value) # N: Revealed type is 'builtins.int' +reveal_type(B3.x._value_) # N: Revealed type is 'builtins.int' # TODO: C1.x.value and C2.x.value should also be of type 'int' # This requires either a typeshed change or a plugin refinement @@ -521,18 +521,18 @@ class C2(IntFlag): class C3(IntFlag): x = 1 -is_x(reveal_type(C1.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(C1.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(C1.x.value) # E: Revealed type is 'Any' -reveal_type(C1.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(C2.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(C2.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(C2.x.value) # E: Revealed type is 'Any' -reveal_type(C2.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(C3.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(C3.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(C3.x.value) # E: Revealed type is 'builtins.int' -reveal_type(C3.x._value_) # E: Revealed type is 'builtins.int' +is_x(reveal_type(C1.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(C1.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(C1.x.value) # N: Revealed type is 'Any' +reveal_type(C1.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(C2.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(C2.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(C2.x.value) # N: Revealed type is 'Any' +reveal_type(C2.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(C3.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(C3.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(C3.x.value) # N: Revealed type is 'builtins.int' +reveal_type(C3.x._value_) # N: Revealed type is 'builtins.int' D1 = Flag('D1', 'x') class D2(Flag): @@ -540,18 +540,18 @@ class D2(Flag): class D3(Flag): x = 1 -is_x(reveal_type(D1.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(D1.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(D1.x.value) # E: Revealed type is 'Any' -reveal_type(D1.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(D2.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(D2.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(D2.x.value) # E: Revealed type is 'Any' -reveal_type(D2.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(D3.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(D3.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(D3.x.value) # E: Revealed type is 'builtins.int' -reveal_type(D3.x._value_) # E: Revealed type is 'builtins.int' +is_x(reveal_type(D1.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(D1.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(D1.x.value) # N: Revealed type is 'Any' +reveal_type(D1.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(D2.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(D2.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(D2.x.value) # N: Revealed type is 'Any' +reveal_type(D2.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(D3.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(D3.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(D3.x.value) # N: Revealed type is 'builtins.int' +reveal_type(D3.x._value_) # N: Revealed type is 'builtins.int' # TODO: Generalize our enum functional API logic to work with subclasses of Enum # See https://github.com/python/mypy/issues/6037 @@ -563,14 +563,14 @@ class E2(Parent): class E3(Parent): x = 1 -is_x(reveal_type(E2.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(E2.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(E2.x.value) # E: Revealed type is 'Any' -reveal_type(E2.x._value_) # E: Revealed type is 'Any' -is_x(reveal_type(E3.x.name)) # E: Revealed type is 'Literal['x']' -is_x(reveal_type(E3.x._name_)) # E: Revealed type is 'Literal['x']' -reveal_type(E3.x.value) # E: Revealed type is 'builtins.int' -reveal_type(E3.x._value_) # E: Revealed type is 'builtins.int' +is_x(reveal_type(E2.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(E2.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(E2.x.value) # N: Revealed type is 'Any' +reveal_type(E2.x._value_) # N: Revealed type is 'Any' +is_x(reveal_type(E3.x.name)) # N: Revealed type is 'Literal['x']' +is_x(reveal_type(E3.x._name_)) # N: Revealed type is 'Literal['x']' +reveal_type(E3.x.value) # N: Revealed type is 'builtins.int' +reveal_type(E3.x._value_) # N: Revealed type is 'builtins.int' # TODO: Figure out if we can construct enums using EnumMetas using the functional API. @@ -607,6 +607,6 @@ from enum import Enum class SomeEnum(Enum): a = "foo" [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' [out2] -main:2: error: Revealed type is 'builtins.str' +main:2: note: Revealed type is 'builtins.str' diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 6852cd1e5cc0..de869cf9dd1e 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -324,7 +324,7 @@ b = None # type: bool i = None # type: str j = not b and i if j: - reveal_type(j) # E: Revealed type is 'builtins.str' + reveal_type(j) # N: Revealed type is 'builtins.str' [builtins fixtures/bool.pyi] [case testRestrictedTypeOr] @@ -333,14 +333,14 @@ b = None # type: bool i = None # type: str j = b or i if not j: - reveal_type(j) # E: Revealed type is 'builtins.str' + reveal_type(j) # N: Revealed type is 'builtins.str' [builtins fixtures/bool.pyi] [case testAndOr] s = "" b = bool() -reveal_type(s and b or b) # E: Revealed type is 'builtins.bool' +reveal_type(s and b or b) # N: Revealed type is 'builtins.bool' [builtins fixtures/bool.pyi] [case testNonBooleanOr] @@ -746,17 +746,17 @@ i = 8 f = 8.0 d = Decimal(8) -reveal_type(divmod(i, i)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(divmod(f, i)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]' -reveal_type(divmod(d, i)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' +reveal_type(divmod(i, i)) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(divmod(f, i)) # N: Revealed type is 'Tuple[builtins.float, builtins.float]' +reveal_type(divmod(d, i)) # N: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' -reveal_type(divmod(i, f)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]' -reveal_type(divmod(f, f)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]' +reveal_type(divmod(i, f)) # N: Revealed type is 'Tuple[builtins.float, builtins.float]' +reveal_type(divmod(f, f)) # N: Revealed type is 'Tuple[builtins.float, builtins.float]' divmod(d, f) # E: Unsupported operand types for divmod ("Decimal" and "float") -reveal_type(divmod(i, d)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' +reveal_type(divmod(i, d)) # N: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' divmod(f, d) # E: Unsupported operand types for divmod ("float" and "Decimal") -reveal_type(divmod(d, d)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' +reveal_type(divmod(d, d)) # N: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]' # Now some bad calls divmod() # E: 'divmod' expects 2 arguments \ @@ -1523,10 +1523,10 @@ if int(): [case testConditionalExpressionUnion] from typing import Union -reveal_type(1 if bool() else 2) # E: Revealed type is 'builtins.int' -reveal_type(1 if bool() else '') # E: Revealed type is 'builtins.object' +reveal_type(1 if bool() else 2) # N: Revealed type is 'builtins.int' +reveal_type(1 if bool() else '') # N: Revealed type is 'builtins.object' x: Union[int, str] = reveal_type(1 if bool() else '') \ - # E: Revealed type is 'Union[builtins.int, builtins.str]' + # N: Revealed type is 'Union[builtins.int, builtins.str]' class A: pass class B(A): @@ -1539,18 +1539,18 @@ a = A() b = B() c = C() d = D() -reveal_type(a if bool() else b) # E: Revealed type is '__main__.A' -reveal_type(b if bool() else c) # E: Revealed type is 'builtins.object' -reveal_type(c if bool() else b) # E: Revealed type is 'builtins.object' -reveal_type(c if bool() else a) # E: Revealed type is 'builtins.object' -reveal_type(d if bool() else b) # E: Revealed type is '__main__.A' +reveal_type(a if bool() else b) # N: Revealed type is '__main__.A' +reveal_type(b if bool() else c) # N: Revealed type is 'builtins.object' +reveal_type(c if bool() else b) # N: Revealed type is 'builtins.object' +reveal_type(c if bool() else a) # N: Revealed type is 'builtins.object' +reveal_type(d if bool() else b) # N: Revealed type is '__main__.A' [builtins fixtures/bool.pyi] [case testConditionalExpressionUnionWithAny] from typing import Union, Any a: Any -x: Union[int, str] = reveal_type(a if int() else 1) # E: Revealed type is 'Union[Any, builtins.int]' -reveal_type(a if int() else 1) # E: Revealed type is 'Any' +x: Union[int, str] = reveal_type(a if int() else 1) # N: Revealed type is 'Union[Any, builtins.int]' +reveal_type(a if int() else 1) # N: Revealed type is 'Any' -- Special cases @@ -1822,7 +1822,7 @@ d() # E: "D[str, int]" not callable [builtins fixtures/dict.pyi] [case testRevealType] -reveal_type(1) # E: Revealed type is 'builtins.int' +reveal_type(1) # N: Revealed type is 'builtins.int' [case testRevealLocals] x = 1 @@ -1830,15 +1830,15 @@ y = 2 z = x + y reveal_locals() [out] -main:4: error: Revealed local types are: -main:4: error: x: builtins.int -main:4: error: y: builtins.int -main:4: error: z: builtins.int +main:4: note: Revealed local types are: +main:4: note: x: builtins.int +main:4: note: y: builtins.int +main:4: note: z: builtins.int [case testUndefinedRevealType] reveal_type(x) [out] -main:1: error: Revealed type is 'Any' +main:1: note: Revealed type is 'Any' main:1: error: Name 'x' is not defined [case testUserDefinedRevealType] @@ -1854,14 +1854,14 @@ def f() -> None: reveal_type(x) x = 1 + 1 [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' [case testRevealUncheckedFunction] def f(): x = 42 reveal_type(x) [out] -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' main:3: note: 'reveal_type' always outputs 'Any' in unchecked functions [case testRevealCheckUntypedDefs] @@ -1870,14 +1870,14 @@ def f(): x = 42 reveal_type(x) [out] -main:4: error: Revealed type is 'builtins.int' +main:4: note: Revealed type is 'builtins.int' [case testRevealTypedDef] def f() -> None: x = 42 reveal_type(x) [out] -main:3: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' [case testEqNone] None == None @@ -1950,15 +1950,15 @@ class B: ... [case testIntPow] a = 1 b = a + 2 -reveal_type(a**0) # E: Revealed type is 'builtins.int' -reveal_type(a**1) # E: Revealed type is 'builtins.int' -reveal_type(a**2) # E: Revealed type is 'builtins.int' -reveal_type(a**-0) # E: Revealed type is 'builtins.int' -reveal_type(a**-1) # E: Revealed type is 'builtins.float' -reveal_type(a**(-2)) # E: Revealed type is 'builtins.float' -reveal_type(a**b) # E: Revealed type is 'Any' -reveal_type(a.__pow__(2)) # E: Revealed type is 'builtins.int' -reveal_type(a.__pow__(a)) # E: Revealed type is 'Any' +reveal_type(a**0) # N: Revealed type is 'builtins.int' +reveal_type(a**1) # N: Revealed type is 'builtins.int' +reveal_type(a**2) # N: Revealed type is 'builtins.int' +reveal_type(a**-0) # N: Revealed type is 'builtins.int' +reveal_type(a**-1) # N: Revealed type is 'builtins.float' +reveal_type(a**(-2)) # N: Revealed type is 'builtins.float' +reveal_type(a**b) # N: Revealed type is 'Any' +reveal_type(a.__pow__(2)) # N: Revealed type is 'builtins.int' +reveal_type(a.__pow__(a)) # N: Revealed type is 'Any' a.__pow__() # E: Too few arguments for "__pow__" of "int" [builtins fixtures/ops.pyi] diff --git a/test-data/unit/check-fastparse.test b/test-data/unit/check-fastparse.test index 284508db0a4c..239109ecf70a 100644 --- a/test-data/unit/check-fastparse.test +++ b/test-data/unit/check-fastparse.test @@ -151,12 +151,12 @@ def f(a, # type: A e, # type: E **kwargs # type: F ): - reveal_type(a) # E: Revealed type is '__main__.A' - reveal_type(b) # E: Revealed type is 'Union[__main__.B, None]' - reveal_type(args) # E: Revealed type is 'builtins.tuple[__main__.C]' - reveal_type(d) # E: Revealed type is 'Union[__main__.D, None]' - reveal_type(e) # E: Revealed type is '__main__.E' - reveal_type(kwargs) # E: Revealed type is 'builtins.dict[builtins.str, __main__.F]' + reveal_type(a) # N: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' + reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' + reveal_type(d) # N: Revealed type is 'Union[__main__.D, None]' + reveal_type(e) # N: Revealed type is '__main__.E' + reveal_type(kwargs) # N: Revealed type is 'builtins.dict[builtins.str, __main__.F]' [builtins fixtures/dict.pyi] [out] @@ -176,12 +176,12 @@ def f(a, # type: A **kwargs # type: F ): # type: (...) -> int - reveal_type(a) # E: Revealed type is '__main__.A' - reveal_type(b) # E: Revealed type is 'Union[__main__.B, None]' - reveal_type(args) # E: Revealed type is 'builtins.tuple[__main__.C]' - reveal_type(d) # E: Revealed type is 'Union[__main__.D, None]' - reveal_type(e) # E: Revealed type is '__main__.E' - reveal_type(kwargs) # E: Revealed type is 'builtins.dict[builtins.str, __main__.F]' + reveal_type(a) # N: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' + reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' + reveal_type(d) # N: Revealed type is 'Union[__main__.D, None]' + reveal_type(e) # N: Revealed type is '__main__.E' + reveal_type(kwargs) # N: Revealed type is 'builtins.dict[builtins.str, __main__.F]' return "not an int" # E: Incompatible return value type (got "str", expected "int") [builtins fixtures/dict.pyi] [out] @@ -202,7 +202,7 @@ def f(*, x # type: str ): # type: (...) -> int - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' return "not an int" # E: Incompatible return value type (got "str", expected "int") [builtins fixtures/dict.pyi] [out] @@ -218,9 +218,9 @@ def f(a, # type: A *args # type: C # kwargs not tested due to lack of 2.7 dict fixtures ): - reveal_type(a) # E: Revealed type is '__main__.A' - reveal_type(b) # E: Revealed type is 'Union[__main__.B, None]' - reveal_type(args) # E: Revealed type is 'builtins.tuple[__main__.C]' + reveal_type(a) # N: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' + reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' [builtins fixtures/dict.pyi] [out] @@ -236,9 +236,9 @@ def f(a, # type: A # kwargs not tested due to lack of 2.7 dict fixtures ): # type: (...) -> int - reveal_type(a) # E: Revealed type is '__main__.A' - reveal_type(b) # E: Revealed type is 'Union[__main__.B, None]' - reveal_type(args) # E: Revealed type is 'builtins.tuple[__main__.C]' + reveal_type(a) # N: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' + reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' return "not an int" # E: Incompatible return value type (got "str", expected "int") [builtins fixtures/dict.pyi] [out] diff --git a/test-data/unit/check-final.test b/test-data/unit/check-final.test index 013909179c7c..f3fad1daf25f 100644 --- a/test-data/unit/check-final.test +++ b/test-data/unit/check-final.test @@ -11,9 +11,9 @@ y: Final[float] = int() z: Final[int] = int() bad: Final[str] = int() # E: Incompatible types in assignment (expression has type "int", variable has type "str") -reveal_type(x) # E: Revealed type is 'builtins.int' -reveal_type(y) # E: Revealed type is 'builtins.float' -reveal_type(z) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.float' +reveal_type(z) # N: Revealed type is 'builtins.int' [out] [case testFinalDefiningInstanceVar] @@ -26,12 +26,12 @@ class C: bad: Final[str] = int() # E: Incompatible types in assignment (expression has type "int", variable has type "str") class D(C): pass -reveal_type(D.x) # E: Revealed type is 'builtins.int' -reveal_type(D.y) # E: Revealed type is 'builtins.float' -reveal_type(D.z) # E: Revealed type is 'builtins.int' -reveal_type(D().x) # E: Revealed type is 'builtins.int' -reveal_type(D().y) # E: Revealed type is 'builtins.float' -reveal_type(D().z) # E: Revealed type is 'builtins.int' +reveal_type(D.x) # N: Revealed type is 'builtins.int' +reveal_type(D.y) # N: Revealed type is 'builtins.float' +reveal_type(D.z) # N: Revealed type is 'builtins.int' +reveal_type(D().x) # N: Revealed type is 'builtins.int' +reveal_type(D().y) # N: Revealed type is 'builtins.float' +reveal_type(D().z) # N: Revealed type is 'builtins.int' [out] [case testFinalDefiningInstanceVarImplicit] @@ -41,8 +41,8 @@ class C: def __init__(self, x: Tuple[int, Any]) -> None: self.x: Final = x self.y: Final[float] = 1 -reveal_type(C((1, 2)).x) # E: Revealed type is 'Tuple[builtins.int, Any]' -reveal_type(C((1, 2)).y) # E: Revealed type is 'builtins.float' +reveal_type(C((1, 2)).x) # N: Revealed type is 'Tuple[builtins.int, Any]' +reveal_type(C((1, 2)).y) # N: Revealed type is 'builtins.float' [out] [case testFinalBadDefinitionTooManyArgs] @@ -50,12 +50,12 @@ from typing import Final x: Final[int, str] # E: Final name must be initialized with a value \ # E: Final[...] takes at most one type argument -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' class C: def __init__(self) -> None: self.x: Final[float, float] = 1 # E: Final[...] takes at most one type argument -reveal_type(C().x) # E: Revealed type is 'builtins.float' +reveal_type(C().x) # N: Revealed type is 'builtins.float' [out] [case testFinalInvalidDefinitions] @@ -83,10 +83,10 @@ class C: def __init__(self) -> None: self.z: Final # E: Type in Final[...] can only be omitted if there is an initializer -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(C.x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(C.x) # N: Revealed type is 'Any' v: C -reveal_type(v.z) # E: Revealed type is 'Any' +reveal_type(v.z) # N: Revealed type is 'Any' [out] [case testFinalDefiningFunc] @@ -114,7 +114,7 @@ from typing import final class C: @final def f(self, x: int) -> None: ... -reveal_type(C().f) # E: Revealed type is 'def (x: builtins.int)' +reveal_type(C().f) # N: Revealed type is 'def (x: builtins.int)' [out] [case testFinalDefiningMethOverloaded] @@ -137,7 +137,7 @@ class C: def bad(self, x): pass -reveal_type(C().f) # E: Revealed type is 'Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)' +reveal_type(C().f) # N: Revealed type is 'Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)' [out] [case testFinalDefiningMethOverloadedStubs] @@ -161,7 +161,7 @@ class C: def bad(self, x: str) -> str: ... [out] tmp/mod.pyi:12: error: In a stub file @final must be applied only to the first overload -main:3: error: Revealed type is 'Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)' +main:3: note: Revealed type is 'Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)' [case testFinalDefiningProperty] from typing import final @@ -173,8 +173,8 @@ class C: @property @final def g(self) -> int: pass -reveal_type(C().f) # E: Revealed type is 'builtins.int' -reveal_type(C().g) # E: Revealed type is 'builtins.int' +reveal_type(C().f) # N: Revealed type is 'builtins.int' +reveal_type(C().g) # N: Revealed type is 'builtins.int' [builtins fixtures/property.pyi] [out] @@ -207,11 +207,11 @@ class C: y: Final[int] # E: Final name must be initialized with a value def __init__(self) -> None: self.z: Final # E: Type in Final[...] can only be omitted if there is an initializer -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(y) # E: Revealed type is 'builtins.int' -reveal_type(C().x) # E: Revealed type is 'Any' -reveal_type(C().y) # E: Revealed type is 'builtins.int' -reveal_type(C().z) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(y) # N: Revealed type is 'builtins.int' +reveal_type(C().x) # N: Revealed type is 'Any' +reveal_type(C().y) # N: Revealed type is 'builtins.int' +reveal_type(C().z) # N: Revealed type is 'Any' [out] [case testFinalDefiningNoRhsSubclass] @@ -246,7 +246,7 @@ class C(Generic[T]): self.x: Final = x self.y: Final = 1 -reveal_type(C((1, 2)).x) # E: Revealed type is 'Tuple[builtins.int*, builtins.int*]' +reveal_type(C((1, 2)).x) # N: Revealed type is 'Tuple[builtins.int*, builtins.int*]' C.x # E: Cannot access final instance attribute "x" on class object \ # E: Access to generic instance variables via class is ambiguous C.y # E: Cannot access final instance attribute "y" on class object diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index a2fc20d6952b..875c645b3ce5 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -173,10 +173,10 @@ def h() -> None: pass @TypedDecorator() def i() -> None: pass -reveal_type(f) # E: Revealed type is 'def (*Any, **Any) -> Any' -reveal_type(g) # E: Revealed type is 'Any' -reveal_type(h) # E: Revealed type is 'def (*Any, **Any) -> Any' -reveal_type(i) # E: Revealed type is 'Any' +reveal_type(f) # N: Revealed type is 'def (*Any, **Any) -> Any' +reveal_type(g) # N: Revealed type is 'Any' +reveal_type(h) # N: Revealed type is 'def (*Any, **Any) -> Any' +reveal_type(i) # N: Revealed type is 'Any' [case testDisallowUntypedDecoratorsNonCallableInstance] # flags: --disallow-untyped-decorators @@ -324,7 +324,7 @@ from mypy_extensions import NoReturn def no_return() -> NoReturn: pass def f() -> int: return 0 -reveal_type(f() or no_return()) # E: Revealed type is 'builtins.int' +reveal_type(f() or no_return()) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] [case testNoReturnVariable] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 9bcc09e28d8d..95b58d717549 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2191,7 +2191,7 @@ def f() -> None: def g(x: int) -> None: pass h = f if bool() else g -reveal_type(h) # E: Revealed type is 'builtins.function' +reveal_type(h) # N: Revealed type is 'builtins.function' h(7) # E: Cannot call function of unknown type [builtins fixtures/bool.pyi] @@ -2254,23 +2254,23 @@ from typing import Callable, TypeVar T = TypeVar('T') f: Callable[[T], T] -reveal_type(f) # E: Revealed type is 'def [T] (T`-1) -> T`-1' +reveal_type(f) # N: Revealed type is 'def [T] (T`-1) -> T`-1' def g(__x: T) -> T: pass f = g -reveal_type(f) # E: Revealed type is 'def [T] (T`-1) -> T`-1' +reveal_type(f) # N: Revealed type is 'def [T] (T`-1) -> T`-1' i = f(3) -reveal_type(i) # E: Revealed type is 'builtins.int*' +reveal_type(i) # N: Revealed type is 'builtins.int*' [case testFunctionReturningGenericFunction] from typing import Callable, TypeVar T = TypeVar('T') def deco() -> Callable[[T], T]: pass -reveal_type(deco) # E: Revealed type is 'def () -> def [T] (T`-1) -> T`-1' +reveal_type(deco) # N: Revealed type is 'def () -> def [T] (T`-1) -> T`-1' f = deco() -reveal_type(f) # E: Revealed type is 'def [T] (T`-1) -> T`-1' +reveal_type(f) # N: Revealed type is 'def [T] (T`-1) -> T`-1' i = f(3) -reveal_type(i) # E: Revealed type is 'builtins.int*' +reveal_type(i) # N: Revealed type is 'builtins.int*' [case testFunctionReturningGenericFunctionPartialBinding] from typing import Callable, TypeVar @@ -2279,11 +2279,11 @@ T = TypeVar('T') U = TypeVar('U') def deco(x: U) -> Callable[[T, U], T]: pass -reveal_type(deco) # E: Revealed type is 'def [U] (x: U`-1) -> def [T] (T`-2, U`-1) -> T`-2' +reveal_type(deco) # N: Revealed type is 'def [U] (x: U`-1) -> def [T] (T`-2, U`-1) -> T`-2' f = deco("foo") -reveal_type(f) # E: Revealed type is 'def [T] (T`-2, builtins.str*) -> T`-2' +reveal_type(f) # N: Revealed type is 'def [T] (T`-2, builtins.str*) -> T`-2' i = f(3, "eggs") -reveal_type(i) # E: Revealed type is 'builtins.int*' +reveal_type(i) # N: Revealed type is 'builtins.int*' [case testFunctionReturningGenericFunctionTwoLevelBinding] from typing import Callable, TypeVar @@ -2292,11 +2292,11 @@ T = TypeVar('T') R = TypeVar('R') def deco() -> Callable[[T], Callable[[T, R], R]]: pass f = deco() -reveal_type(f) # E: Revealed type is 'def [T] (T`-1) -> def [R] (T`-1, R`-2) -> R`-2' +reveal_type(f) # N: Revealed type is 'def [T] (T`-1) -> def [R] (T`-1, R`-2) -> R`-2' g = f(3) -reveal_type(g) # E: Revealed type is 'def [R] (builtins.int*, R`-2) -> R`-2' +reveal_type(g) # N: Revealed type is 'def [R] (builtins.int*, R`-2) -> R`-2' s = g(4, "foo") -reveal_type(s) # E: Revealed type is 'builtins.str*' +reveal_type(s) # N: Revealed type is 'builtins.str*' [case testGenericFunctionReturnAsDecorator] from typing import Callable, TypeVar @@ -2307,9 +2307,9 @@ def deco(__i: int) -> Callable[[T], T]: pass @deco(3) def lol(x: int) -> str: ... -reveal_type(lol) # E: Revealed type is 'def (x: builtins.int) -> builtins.str' +reveal_type(lol) # N: Revealed type is 'def (x: builtins.int) -> builtins.str' s = lol(4) -reveal_type(s) # E: Revealed type is 'builtins.str' +reveal_type(s) # N: Revealed type is 'builtins.str' [case testGenericFunctionOnReturnTypeOnly] from typing import TypeVar, List @@ -2434,7 +2434,7 @@ main:1: error: Unsupported operand types for + ("int" and "str") f = lambda: 5 reveal_type(f) [out] -main:2: error: Revealed type is 'def () -> builtins.int' +main:2: note: Revealed type is 'def () -> builtins.int' [case testRevealLocalsFunction] a = 1.0 @@ -2450,15 +2450,15 @@ def f(a: int, b: int) -> int: reveal_locals() [out] -main:6: error: Revealed local types are: -main:6: error: a: builtins.int -main:6: error: b: builtins.int -main:9: error: Revealed local types are: -main:9: error: a: builtins.int -main:9: error: b: builtins.int -main:9: error: c: builtins.int -main:12: error: Revealed local types are: -main:12: error: a: builtins.float +main:6: note: Revealed local types are: +main:6: note: a: builtins.int +main:6: note: b: builtins.int +main:9: note: Revealed local types are: +main:9: note: a: builtins.int +main:9: note: b: builtins.int +main:9: note: c: builtins.int +main:12: note: Revealed local types are: +main:12: note: a: builtins.float [case testNoComplainOverloadNone] # flags: --no-strict-optional @@ -2474,7 +2474,7 @@ def bar(x: Optional[int]) -> Optional[str]: return None return "number" -reveal_type(bar(None)) # E: Revealed type is 'None' +reveal_type(bar(None)) # N: Revealed type is 'None' [builtins fixtures/isinstance.pyi] [out] @@ -2492,7 +2492,7 @@ def bar(x: Optional[int]) -> Optional[str]: return None return "number" -reveal_type(bar(None)) # E: Revealed type is 'None' +reveal_type(bar(None)) # N: Revealed type is 'None' [builtins fixtures/isinstance.pyi] [out] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 582890508179..6a3f15da476e 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -463,8 +463,8 @@ class Dummy(Generic[T]): Dummy[int]().meth(1) Dummy[int]().meth('a') # E: Argument 1 to "meth" of "Dummy" has incompatible type "str"; expected "int" -reveal_type(Dummy[int]()) # E: Revealed type is '__main__.Dummy[builtins.int*]' -reveal_type(Dummy[int]().methout()) # E: Revealed type is 'builtins.int*' +reveal_type(Dummy[int]()) # N: Revealed type is '__main__.Dummy[builtins.int*]' +reveal_type(Dummy[int]().methout()) # N: Revealed type is 'builtins.int*' [out] [case testTypeApplicationArgTypesSubclasses] @@ -525,7 +525,7 @@ m1 = Node('x', 1) # type: IntNode # E: Argument 1 to "Node" has incompatible typ m2 = Node(1, 1) # type: IntNode[str] # E: Argument 2 to "Node" has incompatible type "int"; expected "str" s = Node(1, 1) # type: SameNode[int] -reveal_type(s) # E: Revealed type is '__main__.Node[builtins.int, builtins.int]' +reveal_type(s) # N: Revealed type is '__main__.Node[builtins.int, builtins.int]' s1 = Node(1, 'x') # type: SameNode[int] # E: Argument 2 to "Node" has incompatible type "str"; expected "int" [out] @@ -552,29 +552,29 @@ input(Node(1, 1)) # E: Argument 2 to "Node" has incompatible type "int"; expecte def output() -> IntNode[str]: return Node(1, 'x') -reveal_type(output()) # E: Revealed type is '__main__.Node[builtins.int, builtins.str]' +reveal_type(output()) # N: Revealed type is '__main__.Node[builtins.int, builtins.str]' 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]' +reveal_type(func) # N: 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(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*]' +reveal_type(func(Node(1, 'x'))) # N: Revealed type is '__main__.Node[builtins.int, builtins.str*]' def func2(x: SameNode[T]) -> SameNode[T]: return x -reveal_type(func2) # E: Revealed type is 'def [T] (x: __main__.Node[T`-1, T`-1]) -> __main__.Node[T`-1, T`-1]' +reveal_type(func2) # N: Revealed type is 'def [T] (x: __main__.Node[T`-1, T`-1]) -> __main__.Node[T`-1, T`-1]' func2(Node(1, 'x')) # E: Cannot infer type argument 1 of "func2" y = func2(Node('x', 'x')) -reveal_type(y) # E: Revealed type is '__main__.Node[builtins.str*, builtins.str*]' +reveal_type(y) # N: Revealed type is '__main__.Node[builtins.str*, builtins.str*]' def wrap(x: T) -> IntNode[T]: return Node(1, x) z = None # type: str -reveal_type(wrap(z)) # E: Revealed type is '__main__.Node[builtins.int, builtins.str*]' +reveal_type(wrap(z)) # N: Revealed type is '__main__.Node[builtins.int, builtins.str*]' [out] main:13: error: Argument 2 to "Node" has incompatible type "int"; expected "str" @@ -616,8 +616,8 @@ main:15:10: error: "list" expects 1 type argument, but 2 given main:16:19: error: "list" expects 1 type argument, but 2 given main:17:25: error: "Node" expects 2 type arguments, but 1 given main:19:5: error: Bad number of arguments for type alias, expected: 1, given: 2 -main:22:1: error: Revealed type is '__main__.Node[builtins.int, builtins.str]' -main:24:1: error: Revealed type is '__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]' +main:22:1: note: Revealed type is '__main__.Node[builtins.int, builtins.str]' +main:24:1: note: Revealed type is '__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]' main:26:5: error: Type variable "__main__.T" is invalid as target for type alias [case testGenericTypeAliasesForAliases] @@ -635,11 +635,11 @@ Third = Union[int, Second[str]] def f2(x: T) -> Second[T]: return Node([1], [x]) -reveal_type(f2('a')) # E: Revealed type is '__main__.Node[builtins.list[builtins.int], builtins.list[builtins.str*]]' +reveal_type(f2('a')) # N: Revealed type is '__main__.Node[builtins.list[builtins.int], builtins.list[builtins.str*]]' def f3() -> Third: return Node([1], ['x']) -reveal_type(f3()) # E: Revealed type is 'Union[builtins.int, __main__.Node[builtins.list[builtins.int], builtins.list[builtins.str]]]' +reveal_type(f3()) # N: Revealed type is 'Union[builtins.int, __main__.Node[builtins.list[builtins.int], builtins.list[builtins.str]]]' [builtins fixtures/list.pyi] @@ -666,7 +666,7 @@ y.y = 1 # Both are OK (implicit Any) y.y = 'x' z = Node(1, 'x') # type: AnyNode -reveal_type(z) # E: Revealed type is '__main__.Node[Any, Any]' +reveal_type(z) # N: Revealed type is '__main__.Node[Any, Any]' [out] @@ -683,7 +683,7 @@ ListedNode = Node[List[T]] l = None # type: ListedNode[int] l.x.append(1) l.meth().append(1) -reveal_type(l.meth()) # E: Revealed type is 'builtins.list*[builtins.int]' +reveal_type(l.meth()) # N: 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]") @@ -715,7 +715,7 @@ y = D(5) # type: D[int] # E: Argument 1 to "D" has incompatible type "int"; expe def f(x: T) -> D[T]: return D((x, x)) -reveal_type(f('a')) # E: Revealed type is '__main__.D[builtins.str*]' +reveal_type(f('a')) # N: Revealed type is '__main__.D[builtins.str*]' [builtins fixtures/list.pyi] [out] @@ -735,7 +735,7 @@ class C(TupledNode): ... # Same as TupledNode[Any] class D(TupledNode[T]): ... class E(Generic[T], UNode[T]): ... # E: Invalid base class -reveal_type(D((1, 1))) # E: Revealed type is '__main__.D[builtins.int*]' +reveal_type(D((1, 1))) # N: Revealed type is '__main__.D[builtins.int*]' [builtins fixtures/list.pyi] [case testGenericTypeAliasesUnion] @@ -763,7 +763,7 @@ def f(x: T) -> UNode[T]: else: return 1 -reveal_type(f(1)) # E: Revealed type is 'Union[builtins.int, __main__.Node[builtins.int*]]' +reveal_type(f(1)) # N: Revealed type is 'Union[builtins.int, __main__.Node[builtins.int*]]' TNode = Union[T, Node[int]] s = 1 # type: TNode[str] # E: Incompatible types in assignment (expression has type "int", variable has type "Union[str, Node[int]]") @@ -789,13 +789,13 @@ def f1(x: T) -> SameTP[T]: a, b, c = f1(1) # E: Need more than 2 values to unpack (3 expected) x, y = f1(1) -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' def f2(x: IntTP[T]) -> IntTP[T]: return x f2((1, 2, 3)) # E: Argument 1 to "f2" has incompatible type "Tuple[int, int, int]"; expected "Tuple[int, ]" -reveal_type(f2((1, 'x'))) # E: Revealed type is 'Tuple[builtins.int, builtins.str*]' +reveal_type(f2((1, 'x'))) # N: Revealed type is 'Tuple[builtins.int, builtins.str*]' [builtins fixtures/for.pyi] @@ -814,7 +814,7 @@ C2 = Callable[[T, T], Node[T]] def make_cb(x: T) -> C[T]: return lambda *args: x -reveal_type(make_cb(1)) # E: Revealed type is 'def (*Any, **Any) -> builtins.int*' +reveal_type(make_cb(1)) # N: Revealed type is 'def (*Any, **Any) -> builtins.int*' def use_cb(arg: T, cb: C2[T]) -> Node[T]: return cb(arg, arg) @@ -822,7 +822,7 @@ def use_cb(arg: T, cb: C2[T]) -> Node[T]: 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]]" -reveal_type(use_cb(1, my_cb)) # E: Revealed type is '__main__.Node[builtins.int]' +reveal_type(use_cb(1, my_cb)) # N: Revealed type is '__main__.Node[builtins.int]' [out] @@ -834,18 +834,18 @@ Vec = List[Tuple[T, T]] vec = [] # type: Vec[bool] vec.append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "Tuple[bool, bool]" -reveal_type(vec[0]) # E: Revealed type is 'Tuple[builtins.bool, builtins.bool]' +reveal_type(vec[0]) # N: Revealed type is 'Tuple[builtins.bool, builtins.bool]' def fun1(v: Vec[T]) -> T: return v[0][0] def fun2(v: Vec[T], scale: T) -> Vec[T]: return v -reveal_type(fun1([(1, 1)])) # E: Revealed type is 'builtins.int*' +reveal_type(fun1([(1, 1)])) # N: Revealed type is 'builtins.int*' fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected "List[Tuple[bool, bool]]" 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*]]' +reveal_type(fun2([(1, 1)], 1)) # N: Revealed type is 'builtins.list[Tuple[builtins.int*, builtins.int*]]' fun2([('x', 'x')], 'x') # E: Value of type variable "T" of "fun2" cannot be "str" [builtins fixtures/list.pyi] @@ -865,7 +865,7 @@ def f(x: Node[T, T]) -> TupledNode[T]: 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*]' +reveal_type(Node('x', 'x')) # N: Revealed type is 'a.Node[builtins.str*, builtins.str*]' [file a.py] from typing import TypeVar, Generic, Tuple @@ -890,7 +890,7 @@ def int_tf(m: int) -> Transform[int, str]: return transform var: Transform[int, str] -reveal_type(var) # E: Revealed type is 'def (builtins.int, builtins.int) -> Tuple[builtins.int, builtins.str]' +reveal_type(var) # N: Revealed type is 'def (builtins.int, builtins.int) -> Tuple[builtins.int, builtins.str]' [file lib.py] from typing import Callable, TypeVar, Tuple @@ -903,7 +903,7 @@ Transform = Callable[[T, int], Tuple[T, R]] [case testGenericTypeAliasesImportingWithoutTypeVarError] from a import Alias x: Alias[int, str] # E: Bad number of arguments for type alias, expected: 1, given: 2 -reveal_type(x) # E: Revealed type is 'builtins.list[builtins.list[Any]]' +reveal_type(x) # N: Revealed type is 'builtins.list[builtins.list[Any]]' [file a.py] from typing import TypeVar, List @@ -921,9 +921,9 @@ NewAlias = Alias[int, int, S, S] class C: pass x: NewAlias[str] -reveal_type(x) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.int, builtins.str, builtins.str]]' +reveal_type(x) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.int, builtins.str, builtins.str]]' y: Alias[int, str, C, C] -reveal_type(y) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str, __main__.C, __main__.C]]' +reveal_type(y) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str, __main__.C, __main__.C]]' [file mod.py] from typing import TypeVar, List, Tuple @@ -954,8 +954,8 @@ U = Union[int] x: O y: U -reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(y) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(y) # N: Revealed type is 'builtins.int' U[int] # E: Type application targets a non-generic function or class O[int] # E: Bad number of arguments for type alias, expected: 0, given: 1 # E: Type application is only supported for generic classes @@ -980,7 +980,7 @@ class C: def g(self, x: b) -> None: pass def h(self, x: c) -> None: pass # E: Invalid type "__main__.C.c" x: b - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' [out] [case testGenericTypeAliasesRuntimeExpressionsInstance] @@ -998,9 +998,9 @@ IntNode[int](1, 'a') # E: Argument 2 to "Node" has incompatible type "str"; exp SameNode = Node[T, T] ff = SameNode[T](1, 1) # E: Need type annotation for 'ff' a = SameNode(1, 'x') -reveal_type(a) # E: Revealed type is '__main__.Node[Any, Any]' +reveal_type(a) # N: Revealed type is '__main__.Node[Any, Any]' b = SameNode[int](1, 1) -reveal_type(b) # E: Revealed type is '__main__.Node[builtins.int*, builtins.int*]' +reveal_type(b) # N: Revealed type is '__main__.Node[builtins.int*, builtins.int*]' SameNode[int](1, 'x') # E: Argument 2 to "Node" has incompatible type "str"; expected "int" [out] @@ -1014,13 +1014,13 @@ TA = Tuple[T, int] UA = Union[T, int] cs = CA + 1 # E: The type alias to Callable is invalid in runtime context -reveal_type(cs) # E: Revealed type is 'Any' +reveal_type(cs) # N: Revealed type is 'Any' ts = TA() # E: The type alias to Tuple is invalid in runtime context -reveal_type(ts) # E: Revealed type is 'Any' +reveal_type(ts) # N: Revealed type is 'Any' us = UA.x # E: The type alias to Union is invalid in runtime context -reveal_type(us) # E: Revealed type is 'Any' +reveal_type(us) # N: Revealed type is 'Any' xx = CA[str] + 1 # E: Type application is only supported for generic classes yy = TA[str]() # E: Type application is only supported for generic classes @@ -1046,8 +1046,8 @@ class C(Generic[T]): a = None # type: SameA[T] b = SameB[T]([], []) -reveal_type(C[int]().a) # E: Revealed type is '__main__.A[builtins.int*, builtins.int*]' -reveal_type(C[str]().b) # E: Revealed type is '__main__.B[builtins.str*, builtins.str*]' +reveal_type(C[int]().a) # N: Revealed type is '__main__.A[builtins.int*, builtins.int*]' +reveal_type(C[str]().b) # N: Revealed type is '__main__.B[builtins.str*, builtins.str*]' [builtins fixtures/list.pyi] @@ -1076,7 +1076,7 @@ main:13: error: Value of type variable "S" of "A" cannot be "str" class A: ... Bad = A[int] # type: ignore -reveal_type(Bad) # E: Revealed type is 'Any' +reveal_type(Bad) # N: Revealed type is 'Any' [out] [case testNoSubscriptionOfBuiltinAliases] @@ -1088,7 +1088,7 @@ ListAlias = List def fun() -> ListAlias[int]: pass -reveal_type(fun()) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(fun()) # N: Revealed type is 'builtins.list[builtins.int]' BuiltinAlias = list BuiltinAlias[int]() # E: "list" is not subscriptable @@ -1097,8 +1097,8 @@ BuiltinAlias[int]() # E: "list" is not subscriptable T = TypeVar('T') BadGenList = list[T] # E: "list" is not subscriptable -reveal_type(BadGenList[int]()) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(BadGenList()) # E: Revealed type is 'builtins.list[Any]' +reveal_type(BadGenList[int]()) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(BadGenList()) # N: Revealed type is 'builtins.list[Any]' [builtins fixtures/list.pyi] [out] @@ -1107,11 +1107,11 @@ reveal_type(BadGenList()) # E: Revealed type is 'builtins.list[Any]' from m import Alias n = Alias[int]([1]) -reveal_type(n) # E: Revealed type is 'm.Node[builtins.list*[builtins.int]]' +reveal_type(n) # N: Revealed type is 'm.Node[builtins.list*[builtins.int]]' bad = Alias[str]([1]) # E: List item 0 has incompatible type "int"; expected "str" n2 = Alias([1]) # Same as Node[List[Any]] -reveal_type(n2) # E: Revealed type is 'm.Node[builtins.list*[Any]]' +reveal_type(n2) # N: Revealed type is 'm.Node[builtins.list*[Any]]' [file m.py] from typing import TypeVar, Generic, List T = TypeVar('T') @@ -1139,8 +1139,8 @@ class C(Generic[T]): class D(B[T], C[S]): ... -reveal_type(D[str, int]().b()) # E: Revealed type is 'builtins.str*' -reveal_type(D[str, int]().c()) # E: Revealed type is 'builtins.int*' +reveal_type(D[str, int]().b()) # N: Revealed type is 'builtins.str*' +reveal_type(D[str, int]().c()) # N: Revealed type is 'builtins.int*' [builtins fixtures/list.pyi] [out] @@ -1153,7 +1153,7 @@ class B(Generic[T]): class D(B[Callable[[T], S]]): ... -reveal_type(D[str, int]().b()) # E: Revealed type is 'def (builtins.str*) -> builtins.int*' +reveal_type(D[str, int]().b()) # N: Revealed type is 'def (builtins.str*) -> builtins.int*' [builtins fixtures/list.pyi] [out] @@ -1174,7 +1174,7 @@ class C(A[S, B[T, int]], B[U, A[int, T]]): pass c = C[object, int, str]() -reveal_type(c.m()) # E: Revealed type is 'Tuple[builtins.str*, __main__.A*[builtins.int, builtins.int*]]' +reveal_type(c.m()) # N: Revealed type is 'Tuple[builtins.str*, __main__.A*[builtins.int, builtins.int*]]' [builtins fixtures/tuple.pyi] [out] @@ -1192,8 +1192,8 @@ class C(Generic[T]): class D(B[T], C[S], Generic[S, T]): ... -reveal_type(D[str, int]().b()) # E: Revealed type is 'builtins.int*' -reveal_type(D[str, int]().c()) # E: Revealed type is 'builtins.str*' +reveal_type(D[str, int]().b()) # N: Revealed type is 'builtins.int*' +reveal_type(D[str, int]().c()) # N: Revealed type is 'builtins.str*' [builtins fixtures/list.pyi] [out] @@ -1462,10 +1462,10 @@ class A: class B(Generic[T]): def meth(self) -> T: ... B[int]() - reveal_type(B[int]().meth) # E: Revealed type is 'def () -> builtins.int*' + reveal_type(B[int]().meth) # N: Revealed type is 'def () -> builtins.int*' A.B[int]() -reveal_type(A.B[int]().meth) # E: Revealed type is 'def () -> builtins.int*' +reveal_type(A.B[int]().meth) # N: Revealed type is 'def () -> builtins.int*' [case testGenericClassInnerFunctionTypeVariable] from typing import TypeVar, Generic @@ -1654,7 +1654,7 @@ class A: def __mul__(cls, other: int) -> str: return "" T = TypeVar("T", bound=A) def f(x: T) -> str: - return reveal_type(x * 0) # E: Revealed type is 'builtins.str' + return reveal_type(x * 0) # N: Revealed type is 'builtins.str' [case testTypeVarReversibleOperatorTuple] from typing import TypeVar, Tuple @@ -1662,7 +1662,7 @@ class A(Tuple[int, int]): def __mul__(cls, other: Tuple[int, int]) -> str: return "" T = TypeVar("T", bound=A) def f(x: T) -> str: - return reveal_type(x * (1, 2) ) # E: Revealed type is 'builtins.str' + return reveal_type(x * (1, 2) ) # N: Revealed type is 'builtins.str' [builtins fixtures/tuple.pyi] @@ -1735,7 +1735,7 @@ g = f3 from typing import TypeVar, Container T = TypeVar('T') def f(x: Container[T]) -> T: ... -reveal_type(f((1, 2))) # E: Revealed type is 'builtins.int*' +reveal_type(f((1, 2))) # N: Revealed type is 'builtins.int*' [typing fixtures/typing-full.pyi] [case testClassMethodInGenericClassWithGenericConstructorArg] @@ -1807,7 +1807,7 @@ T = TypeVar('T') def f(c: Type[T]) -> T: ... x: Any -reveal_type(f(x)) # E: Revealed type is 'Any' +reveal_type(f(x)) # N: Revealed type is 'Any' [case testCallTypeTWithGenericBound] from typing import Generic, TypeVar, Type @@ -1829,8 +1829,8 @@ from typing import TypeVar T = TypeVar('T') def g(x: T) -> T: return x [out] -main:3: error: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' -main:4: error: Revealed type is 'def [T] (x: T`-1) -> T`-1' +main:3: note: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' +main:4: note: Revealed type is 'def [T] (x: T`-1) -> T`-1' [case testPartiallyQualifiedTypeVariableName] from p import b @@ -1843,8 +1843,8 @@ from typing import TypeVar T = TypeVar('T') def g(x: T) -> T: return x [out] -main:3: error: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' -main:4: error: Revealed type is 'def [T] (x: T`-1) -> T`-1' +main:3: note: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' +main:4: note: Revealed type is 'def [T] (x: T`-1) -> T`-1' [case testGenericClassMethodSimple] from typing import Generic, TypeVar @@ -1856,8 +1856,8 @@ class C(Generic[T]): class D(C[str]): ... -reveal_type(D.get()) # E: Revealed type is 'builtins.str*' -reveal_type(D().get()) # E: Revealed type is 'builtins.str*' +reveal_type(D.get()) # N: Revealed type is 'builtins.str*' +reveal_type(D().get()) # N: Revealed type is 'builtins.str*' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodExpansion] @@ -1870,8 +1870,8 @@ class C(Generic[T]): class D(C[Tuple[T, T]]): ... class E(D[str]): ... -reveal_type(E.get()) # E: Revealed type is 'Tuple[builtins.str*, builtins.str*]' -reveal_type(E().get()) # E: Revealed type is 'Tuple[builtins.str*, builtins.str*]' +reveal_type(E.get()) # N: Revealed type is 'Tuple[builtins.str*, builtins.str*]' +reveal_type(E().get()) # N: Revealed type is 'Tuple[builtins.str*, builtins.str*]' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodExpansionReplacingTypeVar] @@ -1886,8 +1886,8 @@ class C(Generic[T]): class D(C[S]): ... class E(D[int]): ... -reveal_type(E.get()) # E: Revealed type is 'builtins.int*' -reveal_type(E().get()) # E: Revealed type is 'builtins.int*' +reveal_type(E.get()) # N: Revealed type is 'builtins.int*' +reveal_type(E().get()) # N: Revealed type is 'builtins.int*' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodUnboundOnClass] @@ -1900,10 +1900,10 @@ class C(Generic[T]): @classmethod def make_one(cls, x: T) -> C[T]: ... -reveal_type(C.get) # E: Revealed type is 'def [T] () -> T`1' -reveal_type(C[int].get) # E: Revealed type is 'def () -> builtins.int*' -reveal_type(C.make_one) # E: Revealed type is 'def [T] (x: T`1) -> __main__.C[T`1]' -reveal_type(C[int].make_one) # E: Revealed type is 'def (x: builtins.int*) -> __main__.C[builtins.int*]' +reveal_type(C.get) # N: Revealed type is 'def [T] () -> T`1' +reveal_type(C[int].get) # N: Revealed type is 'def () -> builtins.int*' +reveal_type(C.make_one) # N: Revealed type is 'def [T] (x: T`1) -> __main__.C[T`1]' +reveal_type(C[int].make_one) # N: Revealed type is 'def (x: builtins.int*) -> __main__.C[builtins.int*]' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodUnboundOnSubClass] @@ -1919,10 +1919,10 @@ class C(Generic[T]): class D(C[Tuple[T, S]]): ... class E(D[S, str]): ... -reveal_type(D.make_one) # E: Revealed type is 'def [T, S] (x: Tuple[T`1, S`2]) -> __main__.C[Tuple[T`1, S`2]]' -reveal_type(D[int, str].make_one) # E: Revealed type is 'def (x: Tuple[builtins.int*, builtins.str*]) -> __main__.C[Tuple[builtins.int*, builtins.str*]]' -reveal_type(E.make_one) # E: Revealed type is 'def [S] (x: Tuple[S`1, builtins.str*]) -> __main__.C[Tuple[S`1, builtins.str*]]' -reveal_type(E[int].make_one) # E: Revealed type is 'def (x: Tuple[builtins.int*, builtins.str*]) -> __main__.C[Tuple[builtins.int*, builtins.str*]]' +reveal_type(D.make_one) # N: Revealed type is 'def [T, S] (x: Tuple[T`1, S`2]) -> __main__.C[Tuple[T`1, S`2]]' +reveal_type(D[int, str].make_one) # N: Revealed type is 'def (x: Tuple[builtins.int*, builtins.str*]) -> __main__.C[Tuple[builtins.int*, builtins.str*]]' +reveal_type(E.make_one) # N: Revealed type is 'def [S] (x: Tuple[S`1, builtins.str*]) -> __main__.C[Tuple[S`1, builtins.str*]]' +reveal_type(E[int].make_one) # N: Revealed type is 'def (x: Tuple[builtins.int*, builtins.str*]) -> __main__.C[Tuple[builtins.int*, builtins.str*]]' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodUnboundOnClassNonMatchingIdNonGeneric] @@ -1938,11 +1938,11 @@ class A(Generic[T]): class B(A[T], Generic[T, S]): def meth(self) -> None: - reveal_type(A[T].foo) # E: Revealed type is 'def () -> Tuple[T`1, __main__.A*[T`1]]' + reveal_type(A[T].foo) # N: Revealed type is 'def () -> Tuple[T`1, __main__.A*[T`1]]' @classmethod def other(cls) -> None: - reveal_type(cls.foo) # E: Revealed type is 'def [T, S] () -> Tuple[T`1, __main__.B*[T`1, S`2]]' -reveal_type(B.foo) # E: Revealed type is 'def [T, S] () -> Tuple[T`1, __main__.B*[T`1, S`2]]' + reveal_type(cls.foo) # N: Revealed type is 'def [T, S] () -> Tuple[T`1, __main__.B*[T`1, S`2]]' +reveal_type(B.foo) # N: Revealed type is 'def [T, S] () -> Tuple[T`1, __main__.B*[T`1, S`2]]' [builtins fixtures/classmethod.pyi] [case testGenericClassAttrUnboundOnClass] @@ -1956,9 +1956,9 @@ class C(Generic[T]): return cls.x # OK x = C.x # E: Access to generic instance variables via class is ambiguous -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' xi = C[int].x # E: Access to generic instance variables via class is ambiguous -reveal_type(xi) # E: Revealed type is 'builtins.int' +reveal_type(xi) # N: Revealed type is 'builtins.int' [builtins fixtures/classmethod.pyi] [case testGenericClassAttrUnboundOnSubClass] @@ -1972,7 +1972,7 @@ class E(C[int]): x = 42 x = D.x # E: Access to generic instance variables via class is ambiguous -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' E.x # OK [case testGenericClassMethodOverloaded] @@ -1992,8 +1992,8 @@ class C(Generic[T]): class D(C[str]): ... -reveal_type(D.get()) # E: Revealed type is 'builtins.str' -reveal_type(D.get(42)) # E: Revealed type is 'builtins.tuple[builtins.str]' +reveal_type(D.get()) # N: Revealed type is 'builtins.str' +reveal_type(D.get(42)) # N: Revealed type is 'builtins.tuple[builtins.str]' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodAnnotation] @@ -2012,14 +2012,14 @@ def f(o: Maker[T]) -> T: return o.x return o.get() b = f(B()) -reveal_type(b) # E: Revealed type is '__main__.B*' +reveal_type(b) # N: Revealed type is '__main__.B*' def g(t: Type[Maker[T]]) -> T: if bool(): return t.x return t.get() bb = g(B) -reveal_type(bb) # E: Revealed type is '__main__.B*' +reveal_type(bb) # N: Revealed type is '__main__.B*' [builtins fixtures/classmethod.pyi] [case testGenericClassMethodAnnotationDecorator] diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 3d6411031c71..6d3d1b097556 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -43,8 +43,8 @@ tmp/m.py:1: error: invalid syntax [case testIgnoreAppliesOnlyToMissing] import a # type: ignore import b # type: ignore -reveal_type(a.foo) # E: Revealed type is 'Any' -reveal_type(b.foo) # E: Revealed type is 'builtins.int' +reveal_type(a.foo) # N: Revealed type is 'Any' +reveal_type(b.foo) # N: Revealed type is 'builtins.int' a.bar() b.bar() # E: Module has no attribute "bar" diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 83374093aa0d..dfc9ca26bd8f 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -1175,10 +1175,10 @@ reveal_type(foo) [rechecked m, n] [stale] [out1] -tmp/n.py:2: error: Revealed type is 'builtins.str' +tmp/n.py:2: note: Revealed type is 'builtins.str' tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" [out2] -tmp/n.py:2: error: Revealed type is 'builtins.float' +tmp/n.py:2: note: Revealed type is 'builtins.float' tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "float"; expected "int" [case testIncrementalReplacingImports] @@ -1258,8 +1258,8 @@ reveal_type(x) y: Alias[int] reveal_type(y) [out2] -tmp/a.py:3: error: Revealed type is 'Union[builtins.int, builtins.str]' -tmp/a.py:5: error: Revealed type is 'Union[builtins.int, builtins.int]' +tmp/a.py:3: note: Revealed type is 'Union[builtins.int, builtins.str]' +tmp/a.py:5: note: Revealed type is 'Union[builtins.int, builtins.int]' [case testIncrementalSilentImportsWithBlatantError] # cmd: mypy -m main @@ -1279,7 +1279,7 @@ accept_int("not an int") [rechecked main] [stale] [out2] -tmp/main.py:2: error: Revealed type is 'Any' +tmp/main.py:2: note: Revealed type is 'Any' [case testIncrementalImportIsNewlySilenced] # cmd: mypy -m main foo @@ -1318,9 +1318,9 @@ bar = "str" [stale] [out1] tmp/main.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" -tmp/main.py:4: error: Revealed type is 'builtins.str' +tmp/main.py:4: note: Revealed type is 'builtins.str' [out2] -tmp/main.py:4: error: Revealed type is 'Any' +tmp/main.py:4: note: Revealed type is 'Any' [case testIncrementalFixedBugCausesPropagation] import mod1 @@ -1357,10 +1357,10 @@ class C: [stale mod3, mod2] [out1] tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") -tmp/mod1.py:3: error: Revealed type is 'builtins.int' +tmp/mod1.py:3: note: Revealed type is 'builtins.int' [out2] -tmp/mod1.py:3: error: Revealed type is 'builtins.int' +tmp/mod1.py:3: note: Revealed type is 'builtins.int' [case testIncrementalIncidentalChangeWithBugCausesPropagation] import mod1 @@ -1396,11 +1396,11 @@ class C: [stale mod4] [out1] tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") -tmp/mod1.py:3: error: Revealed type is 'builtins.int' +tmp/mod1.py:3: note: Revealed type is 'builtins.int' [out2] tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") -tmp/mod1.py:3: error: Revealed type is 'builtins.str' +tmp/mod1.py:3: note: Revealed type is 'builtins.str' [case testIncrementalIncidentalChangeWithBugFixCausesPropagation] import mod1 @@ -1441,10 +1441,10 @@ class C: [stale mod4, mod3, mod2] [out1] tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") -tmp/mod1.py:3: error: Revealed type is 'builtins.int' +tmp/mod1.py:3: note: Revealed type is 'builtins.int' [out2] -tmp/mod1.py:3: error: Revealed type is 'builtins.str' +tmp/mod1.py:3: note: Revealed type is 'builtins.str' [case testIncrementalSilentImportsWithInnerImports] # cmd: mypy -m main foo @@ -1468,7 +1468,7 @@ class MyClass: [rechecked main] [stale] [out2] -tmp/main.py:3: error: Revealed type is 'Any' +tmp/main.py:3: note: Revealed type is 'Any' [case testIncrementalSilentImportsWithInnerImportsAndNewFile] # cmd: mypy -m main foo @@ -1496,7 +1496,7 @@ def test() -> str: return "foo" [rechecked main, foo, unrelated] [stale foo, unrelated] [out2] -tmp/main.py:3: error: Revealed type is 'builtins.str' +tmp/main.py:3: note: Revealed type is 'builtins.str' [case testIncrementalWorksWithNestedClasses] import foo @@ -1771,9 +1771,9 @@ reveal_type(a.x) [file a.py.2] // [out] -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' [out2] -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' [case testIncrementalFollowImportsError] # flags: --follow-imports=error @@ -1802,9 +1802,9 @@ follow_imports = normal [[mypy] follow_imports = skip [out1] -main:3: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' [out2] -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' [case testIncrementalNamedTupleInMethod] from ntcrash import nope @@ -1924,15 +1924,15 @@ class D: self.a = A().b reveal_type(D().a) [out1] -tmp/crash.py:8: error: Revealed type is 'crash.A@5' -tmp/crash.py:17: error: Revealed type is 'crash.B@13[builtins.int*]' -main:2: error: Revealed type is 'crash.A@5' -main:3: error: Revealed type is 'crash.B@13[builtins.int*]' +tmp/crash.py:8: note: Revealed type is 'crash.A@5' +tmp/crash.py:17: note: Revealed type is 'crash.B@13[builtins.int*]' +main:2: note: Revealed type is 'crash.A@5' +main:3: note: Revealed type is 'crash.B@13[builtins.int*]' [out2] -tmp/crash.py:8: error: Revealed type is 'crash.A@5' -tmp/crash.py:17: error: Revealed type is 'crash.B@13[builtins.int*]' -main:2: error: Revealed type is 'crash.A@5' -main:3: error: Revealed type is 'crash.B@13[builtins.int*]' +tmp/crash.py:8: note: Revealed type is 'crash.A@5' +tmp/crash.py:17: note: Revealed type is 'crash.B@13[builtins.int*]' +main:2: note: Revealed type is 'crash.A@5' +main:3: note: Revealed type is 'crash.B@13[builtins.int*]' [case testGenericMethodRestoreMetaLevel] from typing import Dict @@ -2026,11 +2026,11 @@ A = TypedDict('A', {'x': int, 'y': str}) x: A [builtins fixtures/dict.pyi] [out1] -main:2: error: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' -main:4: error: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' +main:2: note: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' +main:4: note: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' [out2] -main:2: error: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' -main:4: error: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' +main:2: note: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' +main:4: note: Revealed type is 'TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})' [case testSerializeMetaclass] import b @@ -2045,11 +2045,11 @@ class M(type): class A(metaclass=M): pass a: Type[A] [out] -main:2: error: Revealed type is 'builtins.int' -main:4: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' +main:4: note: Revealed type is 'builtins.int' [out2] -main:2: error: Revealed type is 'builtins.int' -main:4: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' +main:4: note: Revealed type is 'builtins.int' [case testSerializeMetaclassInImportCycle1] import b @@ -2066,11 +2066,11 @@ a: Type[A] class M(type): def f(cls) -> int: return 0 [out] -main:3: error: Revealed type is 'builtins.int' -main:5: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' +main:5: note: Revealed type is 'builtins.int' [out2] -main:3: error: Revealed type is 'builtins.int' -main:5: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' +main:5: note: Revealed type is 'builtins.int' -- TODO: Add another test for metaclass in import cycle (reversed from the above test). -- This currently does not work. @@ -2322,8 +2322,8 @@ class C: [builtins fixtures/list.pyi] [out] [out2] -tmp/mod.py:4: error: Revealed type is 'builtins.list[builtins.int]' -tmp/mod.py:5: error: Revealed type is 'builtins.int' +tmp/mod.py:4: note: Revealed type is 'builtins.list[builtins.int]' +tmp/mod.py:5: note: Revealed type is 'builtins.int' [case testClassNamesResolutionCrashReveal] import mod @@ -2353,7 +2353,7 @@ foo = Foo() foo.bar(b"test") [out] [out2] -tmp/mod.py:7: error: Revealed type is 'builtins.bytes' +tmp/mod.py:7: note: Revealed type is 'builtins.bytes' [case testIncrementalWithSilentImports] # cmd: mypy -m a @@ -2884,10 +2884,10 @@ class A: [builtins fixtures/list.pyi] [out1] -main:6: error: Revealed type is 'def (x: builtins.int) -> __main__.B' +main:6: note: Revealed type is 'def (x: builtins.int) -> __main__.B' [out2] -main:6: error: Revealed type is 'def (x: builtins.int) -> __main__.B' +main:6: note: Revealed type is 'def (x: builtins.int) -> __main__.B' [case testAttrsIncrementalSubclassingCachedType] from a import A @@ -2905,9 +2905,9 @@ class A: [builtins fixtures/list.pyi] [out1] -main:6: error: Revealed type is 'def (x: builtins.int) -> __main__.B' +main:6: note: Revealed type is 'def (x: builtins.int) -> __main__.B' [out2] -main:6: error: Revealed type is 'def (x: builtins.int) -> __main__.B' +main:6: note: Revealed type is 'def (x: builtins.int) -> __main__.B' [case testAttrsIncrementalArguments] from a import Frozen, NoInit, NoCmp @@ -2957,13 +2957,13 @@ main:15: error: Unsupported left operand type for >= ("NoCmp") [case testAttrsIncrementalDunder] from a import A -reveal_type(A) # E: Revealed type is 'def (a: builtins.int) -> a.A' -reveal_type(A.__eq__) # E: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' -reveal_type(A.__ne__) # E: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' -reveal_type(A.__lt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__le__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__gt__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -reveal_type(A.__ge__) # E: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A) # N: Revealed type is 'def (a: builtins.int) -> a.A' +reveal_type(A.__eq__) # N: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' +reveal_type(A.__ne__) # N: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' +reveal_type(A.__lt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__le__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__gt__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +reveal_type(A.__ge__) # N: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' A(1) < A(2) A(1) <= A(2) @@ -2996,13 +2996,13 @@ class A: [rechecked] [stale] [out2] -main:2: error: Revealed type is 'def (a: builtins.int) -> a.A' -main:3: error: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' -main:4: error: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' -main:5: error: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -main:6: error: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -main:7: error: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' -main:8: error: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +main:2: note: Revealed type is 'def (a: builtins.int) -> a.A' +main:3: note: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' +main:4: note: Revealed type is 'def (self: a.A, other: builtins.object) -> builtins.bool' +main:5: note: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +main:6: note: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +main:7: note: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' +main:8: note: Revealed type is 'def [_AT] (self: _AT`-1, other: _AT`-1) -> builtins.bool' main:17: error: Unsupported operand types for < ("A" and "int") main:18: error: Unsupported operand types for <= ("A" and "int") main:19: error: Unsupported operand types for > ("A" and "int") @@ -3116,9 +3116,9 @@ class A: [builtins fixtures/list.pyi] [out1] -main:2: error: Revealed type is 'def (x: Union[builtins.int, None]) -> a.a.A' +main:2: note: Revealed type is 'def (x: Union[builtins.int, None]) -> a.a.A' [out2] -main:2: error: Revealed type is 'def (x: Union[builtins.int, None]) -> a.a.A' +main:2: note: Revealed type is 'def (x: Union[builtins.int, None]) -> a.a.A' [case testAttrsIncrementalConverterManyStyles] import a @@ -3276,9 +3276,9 @@ def foo() -> None: reveal_type(A) [builtins fixtures/list.pyi] [out1] -main:8: error: Revealed type is 'def (x: builtins.str) -> __main__.A@6' +main:8: note: Revealed type is 'def (x: builtins.str) -> __main__.A@6' [out2] -main:8: error: Revealed type is 'def (x: builtins.str) -> __main__.A@6' +main:8: note: Revealed type is 'def (x: builtins.str) -> __main__.A@6' [case testAttrsIncrementalConverterInSubmoduleForwardRef] # flags: --no-new-semantic-analyzer @@ -3299,9 +3299,9 @@ F = List[int] [builtins fixtures/list.pyi] [out1] -main:3: error: Revealed type is 'def (x: builtins.list[builtins.int]) -> a.a.A' +main:3: note: Revealed type is 'def (x: builtins.list[builtins.int]) -> a.a.A' [out2] -main:3: error: Revealed type is 'def (x: builtins.list[builtins.int]) -> a.a.A' +main:3: note: Revealed type is 'def (x: builtins.list[builtins.int]) -> a.a.A' [case testAttrsIncrementalConverterType] # flags: --no-new-semantic-analyzer @@ -3335,11 +3335,11 @@ class C: d: int = attr.ib(converter=parse) [builtins fixtures/attr.pyi] [out1] -main:6: error: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C' -main:10: error: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D' +main:6: note: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C' +main:10: note: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D' [out2] -main:6: error: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C' -main:10: error: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D' +main:6: note: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C' +main:10: note: Revealed type is 'def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D' [case testAttrsIncrementalThreeRuns] from a import A @@ -3563,7 +3563,7 @@ reveal_type(m.One.name) class Two: pass [out2] -tmp/m/two.py:2: error: Revealed type is 'builtins.str' +tmp/m/two.py:2: note: Revealed type is 'builtins.str' [case testImportUnusedIgnore1] # flags: --warn-unused-ignores @@ -3774,7 +3774,7 @@ class A: [builtins fixtures/list.pyi] [out1] [out2] -tmp/b.py:8: error: Revealed type is 'def (x: builtins.int) -> b.B' +tmp/b.py:8: note: Revealed type is 'def (x: builtins.int) -> b.B' [case testIncrementalDataclassesArguments] import b @@ -3872,13 +3872,13 @@ class A: [builtins fixtures/attr.pyi] [out1] [out2] -tmp/b.py:3: error: Revealed type is 'def (a: builtins.int) -> a.A' -tmp/b.py:4: error: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' -tmp/b.py:5: error: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' -tmp/b.py:6: error: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' -tmp/b.py:7: error: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' -tmp/b.py:8: error: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' -tmp/b.py:9: error: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' +tmp/b.py:3: note: Revealed type is 'def (a: builtins.int) -> a.A' +tmp/b.py:4: note: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' +tmp/b.py:5: note: Revealed type is 'def (builtins.object, builtins.object) -> builtins.bool' +tmp/b.py:6: note: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' +tmp/b.py:7: note: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' +tmp/b.py:8: note: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' +tmp/b.py:9: note: Revealed type is 'def [_DT] (self: _DT`-1, other: _DT`-1) -> builtins.bool' tmp/b.py:18: error: Unsupported operand types for < ("A" and "int") tmp/b.py:19: error: Unsupported operand types for <= ("A" and "int") tmp/b.py:20: error: Unsupported operand types for > ("A" and "int") @@ -4492,7 +4492,7 @@ B = List[A] [builtins fixtures/list.pyi] [out] [out2] -tmp/a.py:3: error: Revealed type is 'builtins.list[builtins.list[builtins.list[Any]]]' +tmp/a.py:3: note: Revealed type is 'builtins.list[builtins.list[builtins.list[Any]]]' [case testRecursiveAliasImported2] # flags: --new-semantic-analyzer @@ -4522,7 +4522,7 @@ tmp/other.pyi:2: error: Module 'lib' has no attribute 'A' tmp/other.pyi:3: error: Cannot resolve name "B" (possible cyclic definition) tmp/lib.pyi:2: error: Module 'other' has no attribute 'B' tmp/a.py:2: error: Cannot resolve name "lib.A" (possible cyclic definition) -tmp/a.py:3: error: Revealed type is 'Any' +tmp/a.py:3: note: Revealed type is 'Any' [case testRecursiveNamedTupleTypedDict] # flags: --no-new-semantic-analyzer @@ -4545,7 +4545,7 @@ B = TypedDict('B', {'x': A}) [builtins fixtures/dict.pyi] [out] [out2] -tmp/a.py:3: error: Revealed type is 'Tuple[TypedDict('other.B', {'x': Any}), fallback=lib.A]' +tmp/a.py:3: note: Revealed type is 'Tuple[TypedDict('other.B', {'x': Any}), fallback=lib.A]' [case testFollowImportSkipNotInvalidatedOnPresent] # flags: --follow-imports=skip @@ -4959,9 +4959,9 @@ a = 1 from typing_extensions import Literal a: Literal[2] = 2 [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' [out2] -main:2: error: Revealed type is 'Literal[2]' +main:2: note: Revealed type is 'Literal[2]' [case testAddedSubStarImport] # cmd: mypy -m a pack pack.mod b @@ -4992,7 +4992,7 @@ from typing import NamedTuple NT = NamedTuple('BadName', [('x', int)]) [out] [out2] -tmp/a.py:3: error: Revealed type is 'Tuple[builtins.int, fallback=b.BadName@2]' +tmp/a.py:3: note: Revealed type is 'Tuple[builtins.int, fallback=b.BadName@2]' [case testNewAnalyzerIncrementalBrokenNamedTupleNested] # flags: --new-semantic-analyzer @@ -5031,7 +5031,7 @@ class C: Hidden = NamedTuple('Hidden', [('x', int)]) [out] [out2] -tmp/a.py:3: error: Revealed type is 'Tuple[builtins.int, fallback=b.C.Hidden@5]' +tmp/a.py:3: note: Revealed type is 'Tuple[builtins.int, fallback=b.C.Hidden@5]' [case testIncrementalNodeCreatedFromGetattr] import a @@ -5048,7 +5048,7 @@ c: C reveal_type(c) [out] [out2] -tmp/a.py:3: error: Revealed type is 'Any' +tmp/a.py:3: note: Revealed type is 'Any' [case testNewAnalyzerIncrementalNestedEnum] # flags: --new-semantic-analyzer diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 58d561ffafb7..048abc483e57 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -617,18 +617,18 @@ class B: pass [case testInferLambdaTypeUsingContext] x : str = (lambda x: x + 1)(1) # E: Incompatible types in assignment (expression has type "int", variable has type "str") -reveal_type((lambda x, y: x + y)(1, 2)) # E: Revealed type is 'builtins.int' +reveal_type((lambda x, y: x + y)(1, 2)) # N: Revealed type is 'builtins.int' (lambda x, y: x + y)(1, "") # E: Unsupported operand types for + ("int" and "str") (lambda *, x, y: x + y)(x=1, y="") # E: Unsupported operand types for + ("int" and "str") -reveal_type((lambda s, i: s)(i=0, s='x')) # E: Revealed type is 'builtins.str' -reveal_type((lambda s, i: i)(i=0, s='x')) # E: Revealed type is 'builtins.int' -reveal_type((lambda x, s, i: x)(1.0, i=0, s='x')) # E: Revealed type is 'builtins.float' +reveal_type((lambda s, i: s)(i=0, s='x')) # N: Revealed type is 'builtins.str' +reveal_type((lambda s, i: i)(i=0, s='x')) # N: Revealed type is 'builtins.int' +reveal_type((lambda x, s, i: x)(1.0, i=0, s='x')) # N: Revealed type is 'builtins.float' (lambda x, s, i: x)() # E: Too few arguments (lambda: 0)(1) # E: Too many arguments -- varargs are not handled, but it should not crash -reveal_type((lambda *k, s, i: i)(type, i=0, s='x')) # E: Revealed type is 'Any' -reveal_type((lambda s, *k, i: i)(i=0, s='x')) # E: Revealed type is 'Any' -reveal_type((lambda s, i, **k: i)(i=0, s='x')) # E: Revealed type is 'Any' +reveal_type((lambda *k, s, i: i)(type, i=0, s='x')) # N: Revealed type is 'Any' +reveal_type((lambda s, *k, i: i)(i=0, s='x')) # N: Revealed type is 'Any' +reveal_type((lambda s, i, **k: i)(i=0, s='x')) # N: Revealed type is 'Any' [builtins fixtures/dict.pyi] [case testInferLambdaAsGenericFunctionArgument] @@ -642,8 +642,8 @@ f(list_a, lambda a: a.x) [builtins fixtures/list.pyi] [case testLambdaWithoutContext] -reveal_type(lambda x: x) # E: Revealed type is 'def (x: Any) -> Any' -reveal_type(lambda x: 1) # E: Revealed type is 'def (x: Any) -> builtins.int' +reveal_type(lambda x: x) # N: Revealed type is 'def (x: Any) -> Any' +reveal_type(lambda x: 1) # N: Revealed type is 'def (x: Any) -> builtins.int' [case testLambdaContextVararg] from typing import Callable @@ -902,8 +902,8 @@ from typing import TypeVar, Callable, Generic T = TypeVar('T') class A(Generic[T]): pass -reveal_type(A()) # E: Revealed type is '__main__.A[]' -b = reveal_type(A()) # type: A[int] # E: Revealed type is '__main__.A[builtins.int]' +reveal_type(A()) # N: Revealed type is '__main__.A[]' +b = reveal_type(A()) # type: A[int] # N: Revealed type is '__main__.A[builtins.int]' [case testUnionWithGenericTypeItemContext] from typing import TypeVar, Union, List @@ -911,9 +911,9 @@ from typing import TypeVar, Union, List T = TypeVar('T') def f(x: Union[T, List[int]]) -> Union[T, List[int]]: pass -reveal_type(f(1)) # E: Revealed type is 'Union[builtins.int*, builtins.list[builtins.int]]' -reveal_type(f([])) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(f(None)) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(1)) # N: Revealed type is 'Union[builtins.int*, builtins.list[builtins.int]]' +reveal_type(f([])) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(None)) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testUnionWithGenericTypeItemContextAndStrictOptional] @@ -923,9 +923,9 @@ from typing import TypeVar, Union, List T = TypeVar('T') def f(x: Union[T, List[int]]) -> Union[T, List[int]]: pass -reveal_type(f(1)) # E: Revealed type is 'Union[builtins.int*, builtins.list[builtins.int]]' -reveal_type(f([])) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(f(None)) # E: Revealed type is 'Union[None, builtins.list[builtins.int]]' +reveal_type(f(1)) # N: Revealed type is 'Union[builtins.int*, builtins.list[builtins.int]]' +reveal_type(f([])) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(None)) # N: Revealed type is 'Union[None, builtins.list[builtins.int]]' [builtins fixtures/list.pyi] [case testUnionWithGenericTypeItemContextInMethod] @@ -938,10 +938,10 @@ class C(Generic[T]): def f(self, x: Union[T, S]) -> Union[T, S]: pass c = C[List[int]]() -reveal_type(c.f('')) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.str*]' -reveal_type(c.f([1])) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(c.f([])) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(c.f(None)) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(c.f('')) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.str*]' +reveal_type(c.f([1])) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(c.f([])) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(c.f(None)) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testGenericMethodCalledInGenericContext] @@ -989,7 +989,7 @@ class D(C): ... def f(x: Sequence[T], y: Sequence[T]) -> List[T]: ... -reveal_type(f([C()], [D()])) # E: Revealed type is 'builtins.list[__main__.C*]' +reveal_type(f([C()], [D()])) # N: Revealed type is 'builtins.list[__main__.C*]' [builtins fixtures/list.pyi] [case testInferTypeVariableFromTwoGenericTypes2] @@ -1021,7 +1021,7 @@ def f(x: A[T], y: A[T]) -> B[T]: ... c: B[C] d: B[D] -reveal_type(f(c, d)) # E: Revealed type is '__main__.B[__main__.D*]' +reveal_type(f(c, d)) # N: Revealed type is '__main__.B[__main__.D*]' [case testInferTypeVariableFromTwoGenericTypes4] from typing import Generic, TypeVar, Callable, List @@ -1041,7 +1041,7 @@ def f(x: Callable[[B[T]], None], def gc(x: A[C]) -> None: pass # B[C] def gd(x: A[D]) -> None: pass # B[C] -reveal_type(f(gc, gd)) # E: Revealed type is 'builtins.list[__main__.C*]' +reveal_type(f(gc, gd)) # N: Revealed type is 'builtins.list[__main__.C*]' [builtins fixtures/list.pyi] [case testWideOuterContextSubClassBound] @@ -1300,7 +1300,7 @@ T = TypeVar('T') def f(i: Iterable[T], c: Callable[[T], str]) -> Optional[T]: ... def g(l: List[C], x: str) -> Optional[C]: - return f(l, lambda c: reveal_type(c).x) # E: Revealed type is '__main__.C' + return f(l, lambda c: reveal_type(c).x) # N: Revealed type is '__main__.C' [builtins fixtures/list.pyi] [case testWideOuterContextEmpty] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 3309896b09ba..cdd23f3e6cca 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -440,7 +440,7 @@ a = None # type: A def ff() -> None: x = f() # E: Need type annotation for 'x' - reveal_type(x) # E: Revealed type is 'Any' \ + reveal_type(x) # N: Revealed type is 'Any' \ # E: Cannot determine type of 'x' g(None) # Ok @@ -697,7 +697,7 @@ def f(x: Callable[..., T]) -> T: return x() class A: pass x = None # type: Type[A] y = f(x) -reveal_type(y) # E: Revealed type is '__main__.A*' +reveal_type(y) # N: Revealed type is '__main__.A*' -- Generic function inference with unions -- -------------------------------------- @@ -769,7 +769,7 @@ c: Callable[[A], int] d: Callable[[B], int] lst = [c, d] -reveal_type(lst) # E: Revealed type is 'builtins.list[def (__main__.B) -> builtins.int]' +reveal_type(lst) # N: Revealed type is 'builtins.list[def (__main__.B) -> builtins.int]' T = TypeVar('T') def meet_test(x: Callable[[T], int], y: Callable[[T], int]) -> T: ... @@ -779,7 +779,7 @@ CB = Callable[[B], B] ca: Callable[[CA], int] cb: Callable[[CB], int] -reveal_type(meet_test(ca, cb)) # E: Revealed type is 'def (__main__.A) -> __main__.B' +reveal_type(meet_test(ca, cb)) # N: Revealed type is 'def (__main__.A) -> __main__.B' [builtins fixtures/list.pyi] [out] @@ -852,7 +852,7 @@ class V(T[_T], U[_T]): pass def wait_for(fut: Union[T[_T], U[_T]]) -> _T: ... -reveal_type(wait_for(V[str]())) # E: Revealed type is 'builtins.str*' +reveal_type(wait_for(V[str]())) # N: Revealed type is 'builtins.str*' [case testAmbiguousUnionContextAndMultipleInheritance2] from typing import TypeVar, Union, Generic @@ -867,7 +867,7 @@ class V(T[_T, _S], U[_T, _S]): pass def wait_for(fut: Union[T[_T, _S], U[_T, _S]]) -> T[_T, _S]: ... reveal_type(wait_for(V[int, str]())) \ - # E: Revealed type is '__main__.T[builtins.int*, builtins.str*]' + # N: Revealed type is '__main__.T[builtins.int*, builtins.str*]' -- Literal expressions @@ -905,8 +905,8 @@ if int(): [case testSetWithStarExpr] s = {1, 2, *(3, 4)} t = {1, 2, *s} -reveal_type(s) # E: Revealed type is 'builtins.set[builtins.int*]' -reveal_type(t) # E: Revealed type is 'builtins.set[builtins.int*]' +reveal_type(s) # N: Revealed type is 'builtins.set[builtins.int*]' +reveal_type(t) # N: Revealed type is 'builtins.set[builtins.int*]' [builtins fixtures/set.pyi] [case testListLiteralWithFunctionsErasesNames] @@ -916,8 +916,8 @@ def h1(x: int) -> int: ... list_1 = [f1, g1] list_2 = [f1, h1] -reveal_type(list_1) # E: Revealed type is 'builtins.list[def (builtins.int) -> builtins.int]' -reveal_type(list_2) # E: Revealed type is 'builtins.list[def (x: builtins.int) -> builtins.int]' +reveal_type(list_1) # N: Revealed type is 'builtins.list[def (builtins.int) -> builtins.int]' +reveal_type(list_2) # N: Revealed type is 'builtins.list[def (x: builtins.int) -> builtins.int]' def f2(x: int, z: str) -> int: ... def g2(y: int, z: str) -> int: ... @@ -925,8 +925,8 @@ def h2(x: int, z: str) -> int: ... list_3 = [f2, g2] list_4 = [f2, h2] -reveal_type(list_3) # E: Revealed type is 'builtins.list[def (builtins.int, z: builtins.str) -> builtins.int]' -reveal_type(list_4) # E: Revealed type is 'builtins.list[def (x: builtins.int, z: builtins.str) -> builtins.int]' +reveal_type(list_3) # N: Revealed type is 'builtins.list[def (builtins.int, z: builtins.str) -> builtins.int]' +reveal_type(list_4) # N: Revealed type is 'builtins.list[def (x: builtins.int, z: builtins.str) -> builtins.int]' [builtins fixtures/list.pyi] [case testListLiteralWithSimilarFunctionsErasesName] @@ -943,8 +943,8 @@ def h(x: Union[B, D], y: A) -> B: ... list_1 = [f, g] list_2 = [f, h] -reveal_type(list_1) # E: Revealed type is 'builtins.list[def (__main__.B, y: __main__.B) -> __main__.A]' -reveal_type(list_2) # E: Revealed type is 'builtins.list[def (x: __main__.B, y: __main__.B) -> __main__.A]' +reveal_type(list_1) # N: Revealed type is 'builtins.list[def (__main__.B, y: __main__.B) -> __main__.A]' +reveal_type(list_2) # N: Revealed type is 'builtins.list[def (x: __main__.B, y: __main__.B) -> __main__.A]' [builtins fixtures/list.pyi] [case testListLiteralWithNameOnlyArgsDoesNotEraseNames] @@ -970,7 +970,7 @@ for x in [A()]: for y in []: # E: Need type annotation for 'y' a = y # E: Cannot determine type of 'y' - reveal_type(y) # E: Revealed type is 'Any' \ + reveal_type(y) # N: Revealed type is 'Any' \ # E: Cannot determine type of 'y' class A: pass @@ -1017,9 +1017,9 @@ for x, y in [[A()]]: for e, f in [[]]: # E: Need type annotation for 'e' \ # E: Need type annotation for 'f' - reveal_type(e) # E: Revealed type is 'Any' \ + reveal_type(e) # N: Revealed type is 'Any' \ # E: Cannot determine type of 'e' - reveal_type(f) # E: Revealed type is 'Any' \ + reveal_type(f) # N: Revealed type is 'Any' \ # E: Cannot determine type of 'f' class A: pass @@ -1146,7 +1146,7 @@ AnyStr = TypeVar('AnyStr', str, bytes) def f(x: AnyStr) -> Tuple[AnyStr]: pass x = None (x,) = f('') -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' -- Inferring attribute types @@ -1653,7 +1653,7 @@ if object(): [case testPartiallyInitializedVariableDoesNotEscapeScope1] def f() -> None: x = None - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' x = 1 [out] @@ -1945,7 +1945,7 @@ A.g # E: Cannot determine type of 'g' class A: @classmethod def f(cls) -> None: - reveal_type(cls.g) # E: Revealed type is 'def (x: builtins.str)' + reveal_type(cls.g) # N: Revealed type is 'def (x: builtins.str)' @classmethod @dec() @@ -1954,9 +1954,9 @@ class A: @classmethod def h(cls) -> None: - reveal_type(cls.g) # E: Revealed type is 'def (x: builtins.str)' + reveal_type(cls.g) # N: Revealed type is 'def (x: builtins.str)' -reveal_type(A.g) # E: Revealed type is 'def (x: builtins.str)' +reveal_type(A.g) # N: Revealed type is 'def (x: builtins.str)' [builtins fixtures/classmethod.pyi] @@ -2088,7 +2088,7 @@ def f(x: T) -> Tuple[T]: ... x = None (x,) = f('') -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [out] [case testNoCrashOnPartialVariable2] @@ -2110,7 +2110,7 @@ def f(x: T) -> Tuple[T, T]: ... x = None (x, x) = f('') -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [out] [case testInferenceNestedTuplesFromGenericIterable] @@ -2123,8 +2123,8 @@ def make_tuple(elem: T) -> Tuple[T]: def main() -> None: ((a, b),) = make_tuple((1, 2)) - reveal_type(a) # E: Revealed type is 'builtins.int' - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(a) # N: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' [builtins fixtures/tuple.pyi] [out] @@ -2191,7 +2191,7 @@ def f() -> None: x = 1 # TODO: "Any" could be a better type here to avoid multiple error messages -reveal_type(x) # E: Revealed type is 'None' +reveal_type(x) # N: Revealed type is 'None' [case testLocalPartialTypesWithGlobalInitializedToNone2] # flags: --local-partial-types @@ -2202,7 +2202,7 @@ def f(): x = 1 # TODO: "Any" could be a better type here to avoid multiple error messages -reveal_type(x) # E: Revealed type is 'None' +reveal_type(x) # N: Revealed type is 'None' [case testLocalPartialTypesWithGlobalInitializedToNone3] # flags: --local-partial-types --no-strict-optional @@ -2213,7 +2213,7 @@ def f() -> None: x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str") x = '' -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [case testLocalPartialTypesWithGlobalInitializedToNoneStrictOptional] # flags: --local-partial-types --strict-optional @@ -2225,20 +2225,20 @@ def f() -> None: x = '' def g() -> None: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, None]' [case testLocalPartialTypesWithGlobalInitializedToNone4] # flags: --local-partial-types --no-strict-optional a = None def f() -> None: - reveal_type(a) # E: Revealed type is 'builtins.str' + reveal_type(a) # N: Revealed type is 'builtins.str' # TODO: This should probably be 'builtins.str', since there could be a # call that causes a non-None value to be assigned -reveal_type(a) # E: Revealed type is 'None' +reveal_type(a) # N: Revealed type is 'None' a = '' -reveal_type(a) # E: Revealed type is 'builtins.str' +reveal_type(a) # N: Revealed type is 'builtins.str' [builtins fixtures/list.pyi] [case testLocalPartialTypesWithClassAttributeInitializedToNone] @@ -2257,8 +2257,8 @@ class A: def f(self) -> None: self.x[0] = '' -reveal_type(A().x) # E: Revealed type is 'builtins.dict[Any, Any]' -reveal_type(A.x) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(A().x) # N: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(A.x) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyList] @@ -2267,10 +2267,10 @@ a = [] def f() -> None: a[0] - reveal_type(a) # E: Revealed type is 'builtins.list[builtins.int]' + reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int]' a.append(1) -reveal_type(a) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyList2] @@ -2279,9 +2279,9 @@ a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") def f() -> None: a.append(1) - reveal_type(a) # E: Revealed type is 'builtins.list[Any]' + reveal_type(a) # N: Revealed type is 'builtins.list[Any]' -reveal_type(a) # E: Revealed type is 'builtins.list[Any]' +reveal_type(a) # N: Revealed type is 'builtins.list[Any]' [builtins fixtures/list.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyList3] @@ -2291,7 +2291,7 @@ a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") def f(): a.append(1) -reveal_type(a) # E: Revealed type is 'builtins.list[Any]' +reveal_type(a) # N: Revealed type is 'builtins.list[Any]' [builtins fixtures/list.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyDict] @@ -2300,10 +2300,10 @@ a = {} def f() -> None: a[0] - reveal_type(a) # E: Revealed type is 'builtins.dict[builtins.int, builtins.str]' + reveal_type(a) # N: Revealed type is 'builtins.dict[builtins.int, builtins.str]' a[0] = '' -reveal_type(a) # E: Revealed type is 'builtins.dict[builtins.int, builtins.str]' +reveal_type(a) # N: Revealed type is 'builtins.dict[builtins.int, builtins.str]' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyDict2] @@ -2312,9 +2312,9 @@ a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") def f() -> None: a[0] = '' - reveal_type(a) # E: Revealed type is 'builtins.dict[Any, Any]' + reveal_type(a) # N: Revealed type is 'builtins.dict[Any, Any]' -reveal_type(a) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(a) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithGlobalInitializedToEmptyDict3] @@ -2324,7 +2324,7 @@ a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") def f(): a[0] = '' -reveal_type(a) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(a) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithNestedFunction] @@ -2333,7 +2333,7 @@ def f() -> None: a = {} def g() -> None: a[0] = '' - reveal_type(a) # E: Revealed type is 'builtins.dict[builtins.int, builtins.str]' + reveal_type(a) # N: Revealed type is 'builtins.dict[builtins.int, builtins.str]' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithNestedFunction2] @@ -2342,7 +2342,7 @@ def f() -> None: a = [] def g() -> None: a.append(1) - reveal_type(a) # E: Revealed type is 'builtins.list[builtins.int]' + reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testLocalPartialTypesWithNestedFunction3] @@ -2352,7 +2352,7 @@ def f() -> None: def g() -> None: nonlocal a a = '' - reveal_type(a) # E: Revealed type is 'builtins.str' + reveal_type(a) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [case testLocalPartialTypesWithInheritance] @@ -2365,7 +2365,7 @@ class A: class B(A): x = None -reveal_type(B.x) # E: Revealed type is 'None' +reveal_type(B.x) # N: Revealed type is 'None' [case testLocalPartialTypesWithInheritance2] # flags: --local-partial-types --strict-optional @@ -2401,8 +2401,8 @@ class C(B): x = None # TODO: Inferring None below is unsafe (https://github.com/python/mypy/issues/3208) -reveal_type(B.x) # E: Revealed type is 'None' -reveal_type(C.x) # E: Revealed type is 'None' +reveal_type(B.x) # N: Revealed type is 'None' +reveal_type(C.x) # N: Revealed type is 'None' [case testLocalPartialTypesWithInheritance2-skip] # flags: --local-partial-types @@ -2468,14 +2468,14 @@ _ = '' # E: Incompatible types in assignment (expression has type "str", variabl class C: _, _ = 0, 0 _ = '' -reveal_type(C._) # E: Revealed type is 'builtins.str' +reveal_type(C._) # N: Revealed type is 'builtins.str' [case testUnusedTargetNotClass2] # flags: --disallow-redefinition class C: _, _ = 0, 0 _ = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -reveal_type(C._) # E: Revealed type is 'builtins.int' +reveal_type(C._) # N: Revealed type is 'builtins.int' [case testUnusedTargetTupleUnpacking] def foo() -> None: @@ -2590,9 +2590,9 @@ class B(A): class C(A): x = '12' -reveal_type(A.x) # E: Revealed type is 'Union[Any, None]' -reveal_type(B.x) # E: Revealed type is 'builtins.int' -reveal_type(C.x) # E: Revealed type is 'builtins.str' +reveal_type(A.x) # N: Revealed type is 'Union[Any, None]' +reveal_type(B.x) # N: Revealed type is 'builtins.int' +reveal_type(C.x) # N: Revealed type is 'builtins.str' [case testPermissiveAttributeOverride2] # flags: --allow-untyped-globals @@ -2606,9 +2606,9 @@ class B(A): class C(A): x = ['12'] -reveal_type(A.x) # E: Revealed type is 'builtins.list[Any]' -reveal_type(B.x) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(C.x) # E: Revealed type is 'builtins.list[builtins.str]' +reveal_type(A.x) # N: Revealed type is 'builtins.list[Any]' +reveal_type(B.x) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(C.x) # N: Revealed type is 'builtins.list[builtins.str]' [builtins fixtures/list.pyi] @@ -2618,7 +2618,7 @@ reveal_type(C.x) # E: Revealed type is 'builtins.list[builtins.str]' class A: x = [] def f(self) -> None: - reveal_type(self.x) # E: Revealed type is 'builtins.list[Any]' + reveal_type(self.x) # N: Revealed type is 'builtins.list[Any]' [builtins fixtures/list.pyi] @@ -2632,13 +2632,13 @@ x = [] y = {} def foo() -> None: - reveal_type(x) # E: Revealed type is 'builtins.list[Any]' - reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' + reveal_type(x) # N: Revealed type is 'builtins.list[Any]' + reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [file a.py] from b import x, y -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' -reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' +reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] @@ -2652,13 +2652,13 @@ x = [] y = {} def foo() -> None: - reveal_type(x) # E: Revealed type is 'builtins.list[Any]' - reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' + reveal_type(x) # N: Revealed type is 'builtins.list[Any]' + reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [file a.py] from b import x, y -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' -reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' +reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] @@ -2675,8 +2675,8 @@ z = y [file a.py] from b import x, y -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' -reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' +reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] [case testPermissiveGlobalContainer4] @@ -2692,8 +2692,8 @@ z = y [file a.py] from b import x, y -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' -reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' +reveal_type(y) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] @@ -2705,7 +2705,7 @@ class A: class B(A): x = None x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [case testIncompatibleInheritedAttributeNoStrictOptional] # flags: --no-strict-optional diff --git a/test-data/unit/check-isinstance.test b/test-data/unit/check-isinstance.test index 2bf884f41837..0b80a74c0110 100644 --- a/test-data/unit/check-isinstance.test +++ b/test-data/unit/check-isinstance.test @@ -36,16 +36,16 @@ from typing import Union, List, Tuple, Dict def f(x: Union[int, str, List]) -> None: if isinstance(x, (str, (int,))): - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' x[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # E: Revealed type is 'builtins.list[Any]' + reveal_type(x) # N: Revealed type is 'builtins.list[Any]' x[1] - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' if isinstance(x, (str, (list,))): - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.list[Any]]' x[1] - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' [builtins fixtures/isinstancelist.pyi] [case testClassAttributeInitialization-skip] @@ -420,7 +420,7 @@ def f(x: Union[List[int], List[str], int]) -> None: a + 'x' # E: Unsupported operand types for + ("int" and "str") # type of a? - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' x + 1 # E: Unsupported operand types for + ("List[int]" and "int") \ # E: Unsupported operand types for + ("List[str]" and "int") \ # N: Left operand is of type "Union[List[int], List[str]]" @@ -588,11 +588,11 @@ class C: pass a = A() # type: A assert isinstance(a, (A, B)) -reveal_type(a) # E: Revealed type is '__main__.A' +reveal_type(a) # N: Revealed type is '__main__.A' b = A() # type: Union[A, B] assert isinstance(b, (A, B, C)) -reveal_type(b) # E: Revealed type is 'Union[__main__.A, __main__.B]' +reveal_type(b) # N: Revealed type is 'Union[__main__.A, __main__.B]' [builtins fixtures/isinstance.pyi] [case testMemberAssignmentChanges-skip] @@ -1014,8 +1014,8 @@ while isinstance(x, int): continue x = 'a' else: - reveal_type(x) # E: Revealed type is 'builtins.str' -reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstance.pyi] [case testWhileExitCondition2] @@ -1026,8 +1026,8 @@ while isinstance(x, int): break x = 'a' else: - reveal_type(x) # E: Revealed type is 'builtins.str' -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/isinstance.pyi] [case testWhileLinkedList] @@ -1267,7 +1267,7 @@ from typing import Optional def f(a: bool, x: object) -> Optional[int]: if a or not isinstance(x, int): return None - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' return x [builtins fixtures/isinstance.pyi] @@ -1277,7 +1277,7 @@ from typing import Optional def g(a: bool, x: object) -> Optional[int]: if not isinstance(x, int) or a: return None - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' return x [builtins fixtures/isinstance.pyi] @@ -1323,14 +1323,14 @@ class IntLike(FloatLike): pass def f1(x: Union[float, int]) -> None: # We ignore promotions in isinstance checks if isinstance(x, float): - reveal_type(x) # E: Revealed type is 'builtins.float' + reveal_type(x) # N: Revealed type is 'builtins.float' else: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' def f2(x: Union[FloatLike, IntLike]) -> None: # ...but not regular subtyping relationships if isinstance(x, FloatLike): - reveal_type(x) # E: Revealed type is 'Union[__main__.FloatLike, __main__.IntLike]' + reveal_type(x) # N: Revealed type is 'Union[__main__.FloatLike, __main__.IntLike]' [builtins fixtures/isinstance.pyi] [case testIsinstanceOfSuperclass] @@ -1339,11 +1339,11 @@ class B(A): pass x = B() if isinstance(x, A): - reveal_type(x) # E: Revealed type is '__main__.B' + reveal_type(x) # N: Revealed type is '__main__.B' if not isinstance(x, A): reveal_type(x) # unreachable x = A() -reveal_type(x) # E: Revealed type is '__main__.B' +reveal_type(x) # N: Revealed type is '__main__.B' [builtins fixtures/isinstance.pyi] [case testIsinstanceOfNonoverlapping] @@ -1354,8 +1354,8 @@ x = B() if isinstance(x, A): reveal_type(x) # unreachable else: - reveal_type(x) # E: Revealed type is '__main__.B' -reveal_type(x) # E: Revealed type is '__main__.B' + reveal_type(x) # N: Revealed type is '__main__.B' +reveal_type(x) # N: Revealed type is '__main__.B' [builtins fixtures/isinstance.pyi] [case testAssertIsinstance] @@ -1389,8 +1389,8 @@ def f(x: Union[List[int], str]) -> None: if isinstance(x, list): x[0]() # E: "int" not callable else: - reveal_type(x) # E: Revealed type is 'builtins.str' - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.str]' [builtins fixtures/isinstancelist.pyi] [case testIsinstanceOrIsinstance] @@ -1404,20 +1404,20 @@ class C(A): x1 = A() if isinstance(x1, B) or isinstance(x1, C): - reveal_type(x1) # E: Revealed type is 'Union[__main__.B, __main__.C]' + reveal_type(x1) # N: Revealed type is 'Union[__main__.B, __main__.C]' f = x1.flag # type: int else: - reveal_type(x1) # E: Revealed type is '__main__.A' + reveal_type(x1) # N: Revealed type is '__main__.A' f = 0 -reveal_type(x1) # E: Revealed type is '__main__.A' +reveal_type(x1) # N: Revealed type is '__main__.A' x2 = A() if isinstance(x2, A) or isinstance(x2, C): - reveal_type(x2) # E: Revealed type is '__main__.A' + reveal_type(x2) # N: Revealed type is '__main__.A' f = x2.flag # E: "A" has no attribute "flag" else: # unreachable 1() -reveal_type(x2) # E: Revealed type is '__main__.A' +reveal_type(x2) # N: Revealed type is '__main__.A' [builtins fixtures/isinstance.pyi] [case testComprehensionIsInstance] @@ -1426,9 +1426,9 @@ a = [] # type: List[Union[int, str]] l = [x for x in a if isinstance(x, int)] g = (x for x in a if isinstance(x, int)) d = {0: x for x in a if isinstance(x, int)} -reveal_type(l) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(g) # E: Revealed type is 'typing.Generator[builtins.int*, None, None]' -reveal_type(d) # E: Revealed type is 'builtins.dict[builtins.int*, builtins.int*]' +reveal_type(l) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(g) # N: Revealed type is 'typing.Generator[builtins.int*, None, None]' +reveal_type(d) # N: Revealed type is 'builtins.dict[builtins.int*, builtins.int*]' [builtins fixtures/isinstancelist.pyi] [case testIsinstanceInWrongOrderInBooleanOp] @@ -1446,7 +1446,7 @@ class A: def f(x: object) -> None: b = isinstance(x, A) and x.a or A() - reveal_type(b) # E: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is '__main__.A' [builtins fixtures/isinstance.pyi] [case testIsInstanceWithUnknownType] @@ -1456,10 +1456,10 @@ def f(x: Union[int, str], typ: type) -> None: if isinstance(x, (typ, int)): x + 1 # E: Unsupported operand types for + ("str" and "int") \ # N: Left operand is of type "Union[int, str]" - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' else: - reveal_type(x) # E: Revealed type is 'builtins.str' - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithBoundedType] @@ -1469,10 +1469,10 @@ class A: pass def f(x: Union[int, A], a: Type[A]) -> None: if isinstance(x, (a, int)): - reveal_type(x) # E: Revealed type is 'Union[builtins.int, __main__.A]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, __main__.A]' else: - reveal_type(x) # E: Revealed type is '__main__.A' - reveal_type(x) # E: Revealed type is 'Union[builtins.int, __main__.A]' + reveal_type(x) # N: Revealed type is '__main__.A' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, __main__.A]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithEmtpy2ndArg] @@ -1480,9 +1480,9 @@ from typing import Union def f(x: Union[int, str]) -> None: if isinstance(x, ()): - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithTypeObject] @@ -1492,12 +1492,12 @@ class A: pass def f(x: Union[int, A], a: Type[A]) -> None: if isinstance(x, a): - reveal_type(x) # E: Revealed type is '__main__.A' + reveal_type(x) # N: Revealed type is '__main__.A' elif isinstance(x, int): - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' else: - reveal_type(x) # E: Revealed type is '__main__.A' - reveal_type(x) # E: Revealed type is 'Union[builtins.int, __main__.A]' + reveal_type(x) # N: Revealed type is '__main__.A' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, __main__.A]' [builtins fixtures/isinstancelist.pyi] [case testIssubclassUnreachable] @@ -1513,7 +1513,7 @@ class Z(X): pass a: Union[Type[Y], Type[Z]] if issubclass(a, X): - reveal_type(a) # E: Revealed type is 'Union[Type[__main__.Y], Type[__main__.Z]]' + reveal_type(a) # N: Revealed type is 'Union[Type[__main__.Y], Type[__main__.Z]]' else: reveal_type(a) # unreachable block [builtins fixtures/isinstancelist.pyi] @@ -1522,21 +1522,21 @@ else: from typing import Union, List, Tuple, Dict, Type def f(x: Union[Type[int], Type[str], Type[List]]) -> None: if issubclass(x, (str, (int,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str]' x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # E: Revealed type is 'Type[builtins.list[Any]]' - reveal_type(x()) # E: Revealed type is 'builtins.list[Any]' + reveal_type(x) # N: Revealed type is 'Type[builtins.list[Any]]' + reveal_type(x()) # N: Revealed type is 'builtins.list[Any]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' if issubclass(x, (str, (list,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.str, builtins.list[Any]]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' [builtins fixtures/isinstancelist.pyi] [case testIssubclasDestructuringUnions2] @@ -1544,45 +1544,45 @@ from typing import Union, List, Tuple, Dict, Type def f(x: Type[Union[int, str, List]]) -> None: if issubclass(x, (str, (int,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str]' x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # E: Revealed type is 'Type[builtins.list[Any]]' - reveal_type(x()) # E: Revealed type is 'builtins.list[Any]' + reveal_type(x) # N: Revealed type is 'Type[builtins.list[Any]]' + reveal_type(x()) # N: Revealed type is 'builtins.list[Any]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' if issubclass(x, (str, (list,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.str, builtins.list[Any]]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' [builtins fixtures/isinstancelist.pyi] [case testIssubclasDestructuringUnions3] from typing import Union, List, Tuple, Dict, Type def f(x: Type[Union[int, str, List]]) -> None: - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' if issubclass(x, (str, (int,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str]' x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # E: Revealed type is 'Type[builtins.list[Any]]' - reveal_type(x()) # E: Revealed type is 'builtins.list[Any]' + reveal_type(x) # N: Revealed type is 'Type[builtins.list[Any]]' + reveal_type(x()) # N: Revealed type is 'builtins.list[Any]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' if issubclass(x, (str, (list,))): - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.str, builtins.list[Any]]' x()[1] - reveal_type(x) # E: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' - reveal_type(x()) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' + reveal_type(x) # N: Revealed type is 'Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]' + reveal_type(x()) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]' [builtins fixtures/isinstancelist.pyi] [case testIssubclass] @@ -1596,7 +1596,7 @@ class GoblinAmbusher(Goblin): def test_issubclass(cls: Type[Goblin]) -> None: if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.level cls.job ga = cls() @@ -1604,7 +1604,7 @@ def test_issubclass(cls: Type[Goblin]) -> None: ga.job ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Goblin]' cls.level cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() @@ -1625,14 +1625,14 @@ class GoblinAmbusher(Goblin): def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, Goblin): - reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Goblin]' cls.level cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.level cls.job g = cls() @@ -1640,14 +1640,14 @@ def test_issubclass(cls: Type[Mob]) -> None: g.job g.job = 'Warrior' # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Mob]' 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" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.job cls.level ga = cls() @@ -1656,7 +1656,7 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = 'Warrior' # E: Cannot assign to class variable "job" via instance if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.level cls.job ga = cls() @@ -1681,7 +1681,7 @@ class GoblinDigger(Goblin): def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, (Goblin, GoblinAmbusher)): - reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Goblin]' cls.level cls.job # E: "Type[Goblin]" has no attribute "job" g = cls() @@ -1689,21 +1689,21 @@ def test_issubclass(cls: Type[Mob]) -> None: g.job # E: "Goblin" has no attribute "job" if issubclass(cls, GoblinAmbusher): cls.level - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.job ga = cls() ga.level = 15 ga.job ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Mob]' 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" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.GoblinAmbusher]' cls.job cls.level ga = cls() @@ -1712,7 +1712,7 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance if issubclass(cls, (GoblinDigger, GoblinAmbusher)): - reveal_type(cls) # E: Revealed type is 'Union[Type[__main__.GoblinDigger], Type[__main__.GoblinAmbusher]]' + reveal_type(cls) # N: Revealed type is 'Union[Type[__main__.GoblinDigger], Type[__main__.GoblinAmbusher]]' cls.level cls.job g = cls() @@ -1729,14 +1729,14 @@ class MyIntList(List[int]): pass def f(cls: Type[object]) -> None: if issubclass(cls, MyList): - reveal_type(cls) # E: Revealed type is 'Type[__main__.MyList]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.MyList]' cls()[0] else: - reveal_type(cls) # E: Revealed type is 'Type[builtins.object]' + reveal_type(cls) # N: Revealed type is 'Type[builtins.object]' cls()[0] # E: Value of type "object" is not indexable if issubclass(cls, MyIntList): - reveal_type(cls) # E: Revealed type is 'Type[__main__.MyIntList]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.MyIntList]' cls()[0] + 1 [builtins fixtures/isinstancelist.pyi] @@ -1788,20 +1788,20 @@ T = TypeVar('T', bound=A) def f(x: T) -> None: if isinstance(x, B): - reveal_type(x) # E: Revealed type is '__main__.B' + reveal_type(x) # N: Revealed type is '__main__.B' else: - reveal_type(x) # E: Revealed type is 'T`-1' - reveal_type(x) # E: Revealed type is 'T`-1' + reveal_type(x) # N: Revealed type is 'T`-1' + reveal_type(x) # N: Revealed type is 'T`-1' [builtins fixtures/isinstance.pyi] [case testIsinstanceAndTypeType] from typing import Type def f(x: Type[int]) -> None: if isinstance(x, type): - reveal_type(x) # E: Revealed type is 'Type[builtins.int]' + reveal_type(x) # N: Revealed type is 'Type[builtins.int]' else: reveal_type(x) # Unreachable - reveal_type(x) # E: Revealed type is 'Type[builtins.int]' + reveal_type(x) # N: Revealed type is 'Type[builtins.int]' [builtins fixtures/isinstance.pyi] [case testIsinstanceVariableSubstitution] @@ -1810,13 +1810,13 @@ U = (list, T) x: object = None if isinstance(x, T): - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' if isinstance(x, U): - reveal_type(x) # E: Revealed type is 'Union[builtins.list[Any], builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[Any], builtins.int, builtins.str]' if isinstance(x, (set, (list, T))): - reveal_type(x) # E: Revealed type is 'Union[builtins.set[Any], builtins.list[Any], builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.set[Any], builtins.list[Any], builtins.int, builtins.str]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceTooFewArgs] @@ -1824,10 +1824,10 @@ isinstance() # E: Too few arguments for "isinstance" x: object if isinstance(): # E: Too few arguments for "isinstance" x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' if isinstance(x): # E: Too few arguments for "isinstance" x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/isinstancelist.pyi] [case testIsSubclassTooFewArgs] @@ -1836,9 +1836,9 @@ from typing import Type issubclass() # E: Too few arguments for "issubclass" y: Type[object] if issubclass(): # E: Too few arguments for "issubclass" - reveal_type(y) # E: Revealed type is 'Type[builtins.object]' + reveal_type(y) # N: Revealed type is 'Type[builtins.object]' if issubclass(y): # E: Too few arguments for "issubclass" - reveal_type(y) # E: Revealed type is 'Type[builtins.object]' + reveal_type(y) # N: Revealed type is 'Type[builtins.object]' [builtins fixtures/isinstancelist.pyi] @@ -1847,9 +1847,9 @@ isinstance(1, 1, 1) # E: Too many arguments for "isinstance" \ # E: Argument 2 to "isinstance" has incompatible type "int"; expected "Union[type, Tuple[Any, ...]]" x: object if isinstance(x, str, 1): # E: Too many arguments for "isinstance" - reveal_type(x) # E: Revealed type is 'builtins.object' + reveal_type(x) # N: Revealed type is 'builtins.object' x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/isinstancelist.pyi] [case testIsinstanceNarrowAny] @@ -1859,9 +1859,9 @@ def narrow_any_to_str_then_reassign_to_int() -> None: v = 1 # type: Any if isinstance(v, str): - reveal_type(v) # E: Revealed type is 'builtins.str' + reveal_type(v) # N: Revealed type is 'builtins.str' v = 2 - reveal_type(v) # E: Revealed type is 'Any' + reveal_type(v) # N: Revealed type is 'Any' [builtins fixtures/isinstance.pyi] @@ -1873,13 +1873,13 @@ x: List[int] y: Optional[int] if y in x: - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' if y not in x: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] [out] @@ -1891,9 +1891,9 @@ x: List[Optional[int]] y: Optional[int] if y not in x: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/list.pyi] [out] @@ -1905,9 +1905,9 @@ x: List[str] y: Optional[int] if y in x: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/list.pyi] [out] @@ -1920,9 +1920,9 @@ lst: Optional[List[int]] nested_any: List[List[Any]] if lst in nested_any: - reveal_type(lst) # E: Revealed type is 'builtins.list[builtins.int]' + reveal_type(lst) # N: Revealed type is 'builtins.list[builtins.int]' if x in nested_any: - reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/list.pyi] [out] @@ -1935,9 +1935,9 @@ class C(A): pass y: Optional[B] if y in (B(), C()): - reveal_type(y) # E: Revealed type is '__main__.B' + reveal_type(y) # N: Revealed type is '__main__.B' else: - reveal_type(y) # E: Revealed type is 'Union[__main__.B, None]' + reveal_type(y) # N: Revealed type is 'Union[__main__.B, None]' [builtins fixtures/tuple.pyi] [out] @@ -1951,9 +1951,9 @@ nt: NT y: Optional[int] if y not in nt: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' [builtins fixtures/tuple.pyi] [out] @@ -1964,13 +1964,13 @@ x: Dict[str, int] y: Optional[str] if y in x: - reveal_type(y) # E: Revealed type is 'builtins.str' + reveal_type(y) # N: Revealed type is 'builtins.str' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.str, None]' if y not in x: - reveal_type(y) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.str, None]' else: - reveal_type(y) # E: Revealed type is 'builtins.str' + reveal_type(y) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [out] @@ -1983,13 +1983,13 @@ y = None # type: Optional[int] # TODO: Fix running tests on Python 2: "Iterator[int]" has no attribute "next" if y in x: # type: ignore - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' if y not in x: # type: ignore - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' [builtins_py2 fixtures/python2.pyi] [out] @@ -2002,14 +2002,14 @@ z: List[object] y: Optional[int] if y in x: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' if y not in z: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [typing fixtures/typing-full.pyi] [builtins fixtures/list.pyi] [out] @@ -2025,13 +2025,13 @@ class C(Container[int]): y: Optional[int] # We never trust user defined types if y in C(): - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' if y not in C(): - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [typing fixtures/typing-full.pyi] [builtins fixtures/list.pyi] [out] @@ -2043,13 +2043,13 @@ s: Set[str] y: Optional[str] if y in {'a', 'b', 'c'}: - reveal_type(y) # E: Revealed type is 'builtins.str' + reveal_type(y) # N: Revealed type is 'builtins.str' else: - reveal_type(y) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.str, None]' if y not in s: - reveal_type(y) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(y) # N: Revealed type is 'Union[builtins.str, None]' else: - reveal_type(y) # E: Revealed type is 'builtins.str' + reveal_type(y) # N: Revealed type is 'builtins.str' [builtins fixtures/set.pyi] [out] @@ -2066,7 +2066,7 @@ def f() -> None: x: Optional[str] if x not in td: return - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [typing fixtures/typing-full.pyi] [builtins fixtures/dict.pyi] [out] @@ -2079,7 +2079,7 @@ x: A x.foo() # E: "A" has no attribute "foo" assert isinstance(x, B) x.foo() -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' [builtins fixtures/isinstance.pyi] [case testIsinstanceWidensUnionWithAnyArg] @@ -2087,9 +2087,9 @@ from typing import Any, Union class A: ... B: Any x: Union[A, B] -reveal_type(x) # E: Revealed type is 'Union[__main__.A, Any]' +reveal_type(x) # N: Revealed type is 'Union[__main__.A, Any]' assert isinstance(x, B) -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' [builtins fixtures/isinstance.pyi] [case testIsinstanceIgnoredImport] @@ -2109,19 +2109,19 @@ class A: pass def foo1(x: Union[A, str, None]) -> None: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' elif isinstance(x, A): - reveal_type(x) # E: Revealed type is '__main__.A' + reveal_type(x) # N: Revealed type is '__main__.A' else: - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' def foo2(x: Optional[str]) -> None: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' elif isinstance(x, A): reveal_type(x) else: - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstance.pyi] [case testIsInstanceInitialNoneCheckSkipsImpossibleCasesInNoStrictOptional] @@ -2132,21 +2132,21 @@ class A: pass def foo1(x: Union[A, str, None]) -> None: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' elif isinstance(x, A): # Note that Union[None, A] == A in no-strict-optional - reveal_type(x) # E: Revealed type is '__main__.A' + reveal_type(x) # N: Revealed type is '__main__.A' else: - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' def foo2(x: Optional[str]) -> None: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' elif isinstance(x, A): # Mypy should, however, be able to skip impossible cases reveal_type(x) else: - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstance.pyi] [case testNoneCheckDoesNotNarrowWhenUsingTypeVars] @@ -2191,14 +2191,14 @@ from typing import Union, Optional, List # correctly ignores 'None' in unions. def foo(x: Optional[List[str]]) -> None: - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], None]' assert isinstance(x, list) - reveal_type(x) # E: Revealed type is 'builtins.list[builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.list[builtins.str]' def bar(x: Union[List[str], List[int], None]) -> None: - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int], None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int], None]' assert isinstance(x, list) - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int]]' [builtins fixtures/isinstancelist.pyi] [case testNoneAndGenericTypesOverlapStrictOptional] @@ -2210,34 +2210,34 @@ from typing import Union, Optional, List # of completeness. def foo(x: Optional[List[str]]) -> None: - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], None]' assert isinstance(x, list) - reveal_type(x) # E: Revealed type is 'builtins.list[builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.list[builtins.str]' def bar(x: Union[List[str], List[int], None]) -> None: - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int], None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int], None]' assert isinstance(x, list) - reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int]]' + reveal_type(x) # N: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int]]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithStarExpression] from typing import Union, List, Tuple def f(var: Union[List[str], Tuple[str, str], str]) -> None: - reveal_type(var) # E: Revealed type is 'Union[builtins.list[builtins.str], Tuple[builtins.str, builtins.str], builtins.str]' + reveal_type(var) # N: Revealed type is 'Union[builtins.list[builtins.str], Tuple[builtins.str, builtins.str], builtins.str]' if isinstance(var, (list, *(str, int))): - reveal_type(var) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.str]' + reveal_type(var) # N: Revealed type is 'Union[builtins.list[builtins.str], builtins.str]' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithStarExpressionAndVariable] from typing import Union def f(var: Union[int, str]) -> None: - reveal_type(var) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(var) # N: Revealed type is 'Union[builtins.int, builtins.str]' some_types = (str, tuple) another_type = list if isinstance(var, (*some_types, another_type)): - reveal_type(var) # E: Revealed type is 'builtins.str' + reveal_type(var) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstancelist.pyi] [case testIsInstanceWithWrongStarExpression] diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index 72a8073ef53d..84c4684d46ab 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -265,7 +265,7 @@ class Formatter: formatter = Formatter() formatter("test", bold=True) -reveal_type(formatter.__call__) # E: Revealed type is 'def (message: builtins.str, bold: builtins.bool =) -> builtins.str' +reveal_type(formatter.__call__) # N: Revealed type is 'def (message: builtins.str, bold: builtins.bool =) -> builtins.str' [builtins fixtures/bool.pyi] [out] @@ -276,7 +276,7 @@ class Formatter: formatter = Formatter() formatter("test", bold=True) -reveal_type(formatter.__call__) # E: Revealed type is 'def (message: builtins.str, *, bold: builtins.bool =) -> builtins.str' +reveal_type(formatter.__call__) # N: Revealed type is 'def (message: builtins.str, *, bold: builtins.bool =) -> builtins.str' [builtins fixtures/bool.pyi] [out] diff --git a/test-data/unit/check-lists.test b/test-data/unit/check-lists.test index a62293a5d7c0..1b75d59f6112 100644 --- a/test-data/unit/check-lists.test +++ b/test-data/unit/check-lists.test @@ -71,9 +71,9 @@ class C: pass [case testListWithStarExpr] (x, *a) = [1, 2, 3] a = [1, *[2, 3]] -reveal_type(a) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int*]' b = [0, *a] -reveal_type(b) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(b) # N: Revealed type is 'builtins.list[builtins.int*]' c = [*a, 0] -reveal_type(c) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(c) # N: Revealed type is 'builtins.list[builtins.int*]' [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index 8f3783c163c7..d0ce118907c3 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -7,13 +7,13 @@ from typing_extensions import Literal def f1(x: 'A[') -> None: pass # E: Invalid type comment or annotation def g1(x: Literal['A[']) -> None: pass -reveal_type(f1) # E: Revealed type is 'def (x: Any)' -reveal_type(g1) # E: Revealed type is 'def (x: Literal['A['])' +reveal_type(f1) # N: Revealed type is 'def (x: Any)' +reveal_type(g1) # N: Revealed type is 'def (x: Literal['A['])' def f2(x: 'A B') -> None: pass # E: Invalid type comment or annotation def g2(x: Literal['A B']) -> None: pass -reveal_type(f2) # E: Revealed type is 'def (x: Any)' -reveal_type(g2) # E: Revealed type is 'def (x: Literal['A B'])' +reveal_type(f2) # N: Revealed type is 'def (x: Any)' +reveal_type(g2) # N: Revealed type is 'def (x: Literal['A B'])' [out] [case testLiteralInvalidTypeComment] @@ -32,8 +32,8 @@ def g(x): # type: (Literal["A["]) -> None pass -reveal_type(f) # E: Revealed type is 'def (x: Any)' -reveal_type(g) # E: Revealed type is 'def (x: Literal['A['])' +reveal_type(f) # N: Revealed type is 'def (x: Any)' +reveal_type(g) # N: Revealed type is 'def (x: Literal['A['])' [out] [case testLiteralParsingPython2] @@ -52,8 +52,8 @@ def g(x): x = None # type: Optional[1] # E: Invalid type: try using Literal[1] instead? y = None # type: Optional[Literal[1]] -reveal_type(x) # E: Revealed type is 'Union[Any, None]' -reveal_type(y) # E: Revealed type is 'Union[Literal[1], None]' +reveal_type(x) # N: Revealed type is 'Union[Any, None]' +reveal_type(y) # N: Revealed type is 'Union[Literal[1], None]' [out] [case testLiteralInsideOtherTypes] @@ -65,9 +65,9 @@ def foo(x: Tuple[1]) -> None: ... # E: Invalid type: try using Literal[1] inst y: Tuple[Literal[2]] def bar(x: Tuple[Literal[2]]) -> None: ... -reveal_type(x) # E: Revealed type is 'Tuple[Any]' -reveal_type(y) # E: Revealed type is 'Tuple[Literal[2]]' -reveal_type(bar) # E: Revealed type is 'def (x: Tuple[Literal[2]])' +reveal_type(x) # N: Revealed type is 'Tuple[Any]' +reveal_type(y) # N: Revealed type is 'Tuple[Literal[2]]' +reveal_type(bar) # N: Revealed type is 'def (x: Tuple[Literal[2]])' [out] [case testLiteralInsideOtherTypesPython2] @@ -84,9 +84,9 @@ y = None # type: Optional[Tuple[Literal[2]]] def bar(x): # type: (Tuple[Literal[2]]) -> None pass -reveal_type(x) # E: Revealed type is 'Union[Tuple[Any], None]' -reveal_type(y) # E: Revealed type is 'Union[Tuple[Literal[2]], None]' -reveal_type(bar) # E: Revealed type is 'def (x: Tuple[Literal[2]])' +reveal_type(x) # N: Revealed type is 'Union[Tuple[Any], None]' +reveal_type(y) # N: Revealed type is 'Union[Tuple[Literal[2]], None]' +reveal_type(bar) # N: Revealed type is 'def (x: Tuple[Literal[2]])' [out] [case testLiteralInsideOtherTypesTypeCommentsPython3] @@ -103,9 +103,9 @@ y = None # type: Optional[Tuple[Literal[2]]] def bar(x): # type: (Tuple[Literal[2]]) -> None pass -reveal_type(x) # E: Revealed type is 'Union[Tuple[Any], None]' -reveal_type(y) # E: Revealed type is 'Union[Tuple[Literal[2]], None]' -reveal_type(bar) # E: Revealed type is 'def (x: Tuple[Literal[2]])' +reveal_type(x) # N: Revealed type is 'Union[Tuple[Any], None]' +reveal_type(y) # N: Revealed type is 'Union[Tuple[Literal[2]], None]' +reveal_type(bar) # N: Revealed type is 'def (x: Tuple[Literal[2]])' [out] [case testLiteralValidExpressionsInStringsPython3] @@ -126,12 +126,12 @@ expr_of_alias_3: alias_3 expr_of_alias_4: alias_4 expr_of_alias_5: alias_5 expr_of_alias_6: alias_6 -reveal_type(expr_of_alias_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_of_alias_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_of_alias_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_of_alias_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_of_alias_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_of_alias_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_of_alias_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_of_alias_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_of_alias_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_of_alias_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_of_alias_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_of_alias_6) # N: Revealed type is 'Literal['"foo"']' expr_ann_1: Literal['a+b'] expr_ann_2: Literal['1+2'] @@ -139,12 +139,12 @@ expr_ann_3: Literal['3'] expr_ann_4: Literal['True'] expr_ann_5: Literal['None'] expr_ann_6: Literal['"foo"'] -reveal_type(expr_ann_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_ann_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_ann_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_ann_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_ann_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_ann_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_ann_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_ann_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_ann_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_ann_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_ann_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_ann_6) # N: Revealed type is 'Literal['"foo"']' expr_str_1: "Literal['a+b']" expr_str_2: "Literal['1+2']" @@ -152,12 +152,12 @@ expr_str_3: "Literal['3']" expr_str_4: "Literal['True']" expr_str_5: "Literal['None']" expr_str_6: "Literal['\"foo\"']" -reveal_type(expr_str_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_str_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_str_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_str_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_str_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_str_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_str_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_str_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_str_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_str_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_str_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_str_6) # N: Revealed type is 'Literal['"foo"']' expr_com_1 = ... # type: Literal['a+b'] expr_com_2 = ... # type: Literal['1+2'] @@ -165,12 +165,12 @@ expr_com_3 = ... # type: Literal['3'] expr_com_4 = ... # type: Literal['True'] expr_com_5 = ... # type: Literal['None'] expr_com_6 = ... # type: Literal['"foo"'] -reveal_type(expr_com_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_com_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_com_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_com_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_com_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_com_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_com_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_com_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_com_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_com_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_com_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_com_6) # N: Revealed type is 'Literal['"foo"']' [builtins fixtures/bool.pyi] [out] @@ -193,12 +193,12 @@ expr_of_alias_3: alias_3 expr_of_alias_4: alias_4 expr_of_alias_5: alias_5 expr_of_alias_6: alias_6 -reveal_type(expr_of_alias_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_of_alias_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_of_alias_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_of_alias_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_of_alias_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_of_alias_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_of_alias_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_of_alias_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_of_alias_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_of_alias_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_of_alias_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_of_alias_6) # N: Revealed type is 'Literal['"foo"']' expr_com_1 = ... # type: Literal['a+b'] expr_com_2 = ... # type: Literal['1+2'] @@ -206,12 +206,12 @@ expr_com_3 = ... # type: Literal['3'] expr_com_4 = ... # type: Literal['True'] expr_com_5 = ... # type: Literal['None'] expr_com_6 = ... # type: Literal['"foo"'] -reveal_type(expr_com_1) # E: Revealed type is 'Literal['a+b']' -reveal_type(expr_com_2) # E: Revealed type is 'Literal['1+2']' -reveal_type(expr_com_3) # E: Revealed type is 'Literal['3']' -reveal_type(expr_com_4) # E: Revealed type is 'Literal['True']' -reveal_type(expr_com_5) # E: Revealed type is 'Literal['None']' -reveal_type(expr_com_6) # E: Revealed type is 'Literal['"foo"']' +reveal_type(expr_com_1) # N: Revealed type is 'Literal['a+b']' +reveal_type(expr_com_2) # N: Revealed type is 'Literal['1+2']' +reveal_type(expr_com_3) # N: Revealed type is 'Literal['3']' +reveal_type(expr_com_4) # N: Revealed type is 'Literal['True']' +reveal_type(expr_com_5) # N: Revealed type is 'Literal['None']' +reveal_type(expr_com_6) # N: Revealed type is 'Literal['"foo"']' [builtins fixtures/bool.pyi] [out] @@ -237,15 +237,15 @@ def accepts_str_1(x: Literal[u"foo"]) -> None: pass def accepts_str_2(x: Literal["foo"]) -> None: pass def accepts_bytes(x: Literal[b"foo"]) -> None: pass -reveal_type(a_ann) # E: Revealed type is 'Literal['foo']' -reveal_type(b_ann) # E: Revealed type is 'Literal['foo']' -reveal_type(c_ann) # E: Revealed type is 'Literal[b'foo']' -reveal_type(a_hint) # E: Revealed type is 'Literal['foo']' -reveal_type(b_hint) # E: Revealed type is 'Literal['foo']' -reveal_type(c_hint) # E: Revealed type is 'Literal[b'foo']' -reveal_type(a_alias) # E: Revealed type is 'Literal['foo']' -reveal_type(b_alias) # E: Revealed type is 'Literal['foo']' -reveal_type(c_alias) # E: Revealed type is 'Literal[b'foo']' +reveal_type(a_ann) # N: Revealed type is 'Literal['foo']' +reveal_type(b_ann) # N: Revealed type is 'Literal['foo']' +reveal_type(c_ann) # N: Revealed type is 'Literal[b'foo']' +reveal_type(a_hint) # N: Revealed type is 'Literal['foo']' +reveal_type(b_hint) # N: Revealed type is 'Literal['foo']' +reveal_type(c_hint) # N: Revealed type is 'Literal[b'foo']' +reveal_type(a_alias) # N: Revealed type is 'Literal['foo']' +reveal_type(b_alias) # N: Revealed type is 'Literal['foo']' +reveal_type(c_alias) # N: Revealed type is 'Literal[b'foo']' accepts_str_1(a_ann) accepts_str_1(b_ann) @@ -303,12 +303,12 @@ def accepts_bytes_2(x): # type: (Literal[b"foo"]) -> None pass -reveal_type(a_hint) # E: Revealed type is 'Literal[u'foo']' -reveal_type(b_hint) # E: Revealed type is 'Literal['foo']' -reveal_type(c_hint) # E: Revealed type is 'Literal['foo']' -reveal_type(a_alias) # E: Revealed type is 'Literal[u'foo']' -reveal_type(b_alias) # E: Revealed type is 'Literal['foo']' -reveal_type(c_alias) # E: Revealed type is 'Literal['foo']' +reveal_type(a_hint) # N: Revealed type is 'Literal[u'foo']' +reveal_type(b_hint) # N: Revealed type is 'Literal['foo']' +reveal_type(c_hint) # N: Revealed type is 'Literal['foo']' +reveal_type(a_alias) # N: Revealed type is 'Literal[u'foo']' +reveal_type(b_alias) # N: Revealed type is 'Literal['foo']' +reveal_type(c_alias) # N: Revealed type is 'Literal['foo']' accepts_unicode(a_hint) accepts_unicode(b_hint) # E: Argument 1 to "accepts_unicode" has incompatible type "Literal['foo']"; expected "Literal[u'foo']" @@ -359,12 +359,12 @@ def accepts_bytes(x): # type: (Literal[b"foo"]) -> None pass -reveal_type(a_hint) # E: Revealed type is 'Literal[u'foo']' -reveal_type(b_hint) # E: Revealed type is 'Literal[u'foo']' -reveal_type(c_hint) # E: Revealed type is 'Literal['foo']' -reveal_type(a_alias) # E: Revealed type is 'Literal[u'foo']' -reveal_type(b_alias) # E: Revealed type is 'Literal[u'foo']' -reveal_type(c_alias) # E: Revealed type is 'Literal['foo']' +reveal_type(a_hint) # N: Revealed type is 'Literal[u'foo']' +reveal_type(b_hint) # N: Revealed type is 'Literal[u'foo']' +reveal_type(c_hint) # N: Revealed type is 'Literal['foo']' +reveal_type(a_alias) # N: Revealed type is 'Literal[u'foo']' +reveal_type(b_alias) # N: Revealed type is 'Literal[u'foo']' +reveal_type(c_alias) # N: Revealed type is 'Literal['foo']' accepts_unicode_1(a_hint) accepts_unicode_1(b_hint) @@ -406,13 +406,13 @@ a_bytes_wrapper: b"Literal[u'foo']" # E: Invalid type comment or annotation b_bytes_wrapper: b"Literal['foo']" # E: Invalid type comment or annotation c_bytes_wrapper: b"Literal[b'foo']" # E: Invalid type comment or annotation -reveal_type(a_unicode_wrapper) # E: Revealed type is 'Literal['foo']' -reveal_type(b_unicode_wrapper) # E: Revealed type is 'Literal['foo']' -reveal_type(c_unicode_wrapper) # E: Revealed type is 'Literal[b'foo']' +reveal_type(a_unicode_wrapper) # N: Revealed type is 'Literal['foo']' +reveal_type(b_unicode_wrapper) # N: Revealed type is 'Literal['foo']' +reveal_type(c_unicode_wrapper) # N: Revealed type is 'Literal[b'foo']' -reveal_type(a_str_wrapper) # E: Revealed type is 'Literal['foo']' -reveal_type(b_str_wrapper) # E: Revealed type is 'Literal['foo']' -reveal_type(c_str_wrapper) # E: Revealed type is 'Literal[b'foo']' +reveal_type(a_str_wrapper) # N: Revealed type is 'Literal['foo']' +reveal_type(b_str_wrapper) # N: Revealed type is 'Literal['foo']' +reveal_type(c_str_wrapper) # N: Revealed type is 'Literal[b'foo']' T = TypeVar('T') class Wrap(Generic[T]): pass @@ -440,17 +440,17 @@ c_bytes_wrapper_alias: CBytesWrapperAlias # In Python 3, we assume that Literal['foo'] and Literal[u'foo'] are always # equivalent, no matter what. -reveal_type(a_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(b_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[b'foo']]' +reveal_type(a_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(b_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[b'foo']]' -reveal_type(a_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(b_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[b'foo']]' +reveal_type(a_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(b_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[b'foo']]' -reveal_type(a_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(b_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[b'foo']]' +reveal_type(a_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(b_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[b'foo']]' [out] [case testLiteralMixingUnicodeAndBytesPython2ForwardStrings] @@ -485,19 +485,19 @@ c_bytes_wrapper_alias = Wrap() # type: CBytesWrapperAlias # Unlike Python 3, the exact meaning of Literal['foo'] is "inherited" from the "outer" # string. For example, the "outer" string is unicode in the first example here. So # we treat Literal['foo'] as the same as Literal[u'foo']. -reveal_type(a_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(c_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(c_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' # However, for both of these examples, the "outer" string is bytes, so we don't treat # Literal['foo'] as a unicode Literal. -reveal_type(a_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(a_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' [out] [case testLiteralMixingUnicodeAndBytesPython2ForwardStringsUnicodeLiterals] @@ -533,19 +533,19 @@ c_bytes_wrapper_alias = Wrap() # type: CBytesWrapperAlias # This example is almost identical to the previous one, except that we're using # unicode literals. The first and last examples remain the same, but the middle # one changes: -reveal_type(a_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(c_unicode_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(c_unicode_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' # Since unicode_literals is enabled, the "outer" string in Wrap["Literal['foo']"] is now # a unicode string, so we end up treating Literal['foo'] as the same as Literal[u'foo']. -reveal_type(a_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(c_str_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(c_str_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(a_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal[u'foo']]' -reveal_type(b_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' -reveal_type(c_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(a_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal[u'foo']]' +reveal_type(b_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' +reveal_type(c_bytes_wrapper_alias) # N: Revealed type is '__main__.Wrap[Literal['foo']]' [out] [case testLiteralMixingUnicodeAndBytesInconsistentUnicodeLiterals] @@ -553,10 +553,10 @@ reveal_type(c_bytes_wrapper_alias) # E: Revealed type is '__main__.Wrap[Liter import mod_unicode as u import mod_bytes as b -reveal_type(u.func) # E: Revealed type is 'def (x: Literal[u'foo'])' -reveal_type(u.var) # E: Revealed type is 'Literal[u'foo']' -reveal_type(b.func) # E: Revealed type is 'def (x: Literal['foo'])' -reveal_type(b.var) # E: Revealed type is 'Literal['foo']' +reveal_type(u.func) # N: Revealed type is 'def (x: Literal[u'foo'])' +reveal_type(u.var) # N: Revealed type is 'Literal[u'foo']' +reveal_type(b.func) # N: Revealed type is 'def (x: Literal['foo'])' +reveal_type(b.var) # N: Revealed type is 'Literal['foo']' from_u = u"foo" # type: u.Alias from_b = "foo" # type: b.Alias @@ -621,23 +621,23 @@ c3 = blah # type: Literal["¬b ∧ λ(p)"] d3 = blah # type: Literal["\U0001F600"] e3 = blah # type: Literal["😀"] -reveal_type(a1) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(b1) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(c1) # E: Revealed type is 'Literal['¬b ∧ λ(p)']' -reveal_type(d1) # E: Revealed type is 'Literal['😀']' -reveal_type(e1) # E: Revealed type is 'Literal['😀']' +reveal_type(a1) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(b1) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(c1) # N: Revealed type is 'Literal['¬b ∧ λ(p)']' +reveal_type(d1) # N: Revealed type is 'Literal['😀']' +reveal_type(e1) # N: Revealed type is 'Literal['😀']' -reveal_type(a2) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(b2) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(c2) # E: Revealed type is 'Literal['¬b ∧ λ(p)']' -reveal_type(d2) # E: Revealed type is 'Literal['😀']' -reveal_type(e2) # E: Revealed type is 'Literal['😀']' +reveal_type(a2) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(b2) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(c2) # N: Revealed type is 'Literal['¬b ∧ λ(p)']' +reveal_type(d2) # N: Revealed type is 'Literal['😀']' +reveal_type(e2) # N: Revealed type is 'Literal['😀']' -reveal_type(a3) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(b3) # E: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' -reveal_type(c3) # E: Revealed type is 'Literal['¬b ∧ λ(p)']' -reveal_type(d3) # E: Revealed type is 'Literal['😀']' -reveal_type(e3) # E: Revealed type is 'Literal['😀']' +reveal_type(a3) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(b3) # N: Revealed type is 'Literal['\x00¬b ∧ λ(p)']' +reveal_type(c3) # N: Revealed type is 'Literal['¬b ∧ λ(p)']' +reveal_type(d3) # N: Revealed type is 'Literal['😀']' +reveal_type(e3) # N: Revealed type is 'Literal['😀']' a1 = b1 a1 = c1 # E: Incompatible types in assignment (expression has type "Literal['¬b ∧ λ(p)']", variable has type "Literal['\x00¬b ∧ λ(p)']") @@ -654,10 +654,10 @@ a1 = c3 # E: Incompatible types in assignment (expression has type "Literal['¬ from typing_extensions import Literal as Foo x: Foo[3] -reveal_type(x) # E: Revealed type is 'Literal[3]' +reveal_type(x) # N: Revealed type is 'Literal[3]' y: Foo["hello"] -reveal_type(y) # E: Revealed type is 'Literal['hello']' +reveal_type(y) # N: Revealed type is 'Literal['hello']' [out] [case testLiteralRenamingImportViaAnotherImportWorks] @@ -666,8 +666,8 @@ from other_module import Foo, Bar x: Foo[3] y: Bar -reveal_type(x) # E: Revealed type is 'Literal[3]' -reveal_type(y) # E: Revealed type is 'Literal[4]' +reveal_type(x) # N: Revealed type is 'Literal[3]' +reveal_type(y) # N: Revealed type is 'Literal[4]' [file other_module.py] from typing_extensions import Literal as Foo @@ -678,7 +678,7 @@ Bar = Foo[4] from typing_extensions import Literal as Foo x: Foo["Foo"] -reveal_type(x) # E: Revealed type is 'Literal['Foo']' +reveal_type(x) # N: Revealed type is 'Literal['Foo']' y: Foo[Foo] # E: Literal[...] must have at least one parameter [out] @@ -708,9 +708,9 @@ a1: Literal[4] b1: Literal[0x2a] c1: Literal[-300] -reveal_type(a1) # E: Revealed type is 'Literal[4]' -reveal_type(b1) # E: Revealed type is 'Literal[42]' -reveal_type(c1) # E: Revealed type is 'Literal[-300]' +reveal_type(a1) # N: Revealed type is 'Literal[4]' +reveal_type(b1) # N: Revealed type is 'Literal[42]' +reveal_type(c1) # N: Revealed type is 'Literal[-300]' a2t = Literal[4] b2t = Literal[0x2a] @@ -719,17 +719,17 @@ a2: a2t b2: b2t c2: c2t -reveal_type(a2) # E: Revealed type is 'Literal[4]' -reveal_type(b2) # E: Revealed type is 'Literal[42]' -reveal_type(c2) # E: Revealed type is 'Literal[-300]' +reveal_type(a2) # N: Revealed type is 'Literal[4]' +reveal_type(b2) # N: Revealed type is 'Literal[42]' +reveal_type(c2) # N: Revealed type is 'Literal[-300]' def f1(x: Literal[4]) -> Literal[4]: pass def f2(x: Literal[0x2a]) -> Literal[0x2a]: pass def f3(x: Literal[-300]) -> Literal[-300]: pass -reveal_type(f1) # E: Revealed type is 'def (x: Literal[4]) -> Literal[4]' -reveal_type(f2) # E: Revealed type is 'def (x: Literal[42]) -> Literal[42]' -reveal_type(f3) # E: Revealed type is 'def (x: Literal[-300]) -> Literal[-300]' +reveal_type(f1) # N: Revealed type is 'def (x: Literal[4]) -> Literal[4]' +reveal_type(f2) # N: Revealed type is 'def (x: Literal[42]) -> Literal[42]' +reveal_type(f3) # N: Revealed type is 'def (x: Literal[-300]) -> Literal[-300]' [out] [case testLiteralBasicBoolUsage] @@ -738,22 +738,22 @@ from typing_extensions import Literal a1: Literal[True] b1: Literal[False] -reveal_type(a1) # E: Revealed type is 'Literal[True]' -reveal_type(b1) # E: Revealed type is 'Literal[False]' +reveal_type(a1) # N: Revealed type is 'Literal[True]' +reveal_type(b1) # N: Revealed type is 'Literal[False]' a2t = Literal[True] b2t = Literal[False] a2: a2t b2: b2t -reveal_type(a2) # E: Revealed type is 'Literal[True]' -reveal_type(b2) # E: Revealed type is 'Literal[False]' +reveal_type(a2) # N: Revealed type is 'Literal[True]' +reveal_type(b2) # N: Revealed type is 'Literal[False]' def f1(x: Literal[True]) -> Literal[True]: pass def f2(x: Literal[False]) -> Literal[False]: pass -reveal_type(f1) # E: Revealed type is 'def (x: Literal[True]) -> Literal[True]' -reveal_type(f2) # E: Revealed type is 'def (x: Literal[False]) -> Literal[False]' +reveal_type(f1) # N: Revealed type is 'def (x: Literal[True]) -> Literal[True]' +reveal_type(f2) # N: Revealed type is 'def (x: Literal[False]) -> Literal[False]' [builtins fixtures/bool.pyi] [out] @@ -766,11 +766,11 @@ c: Literal[' foo bar '] d: Literal["foo"] e: Literal['foo'] -reveal_type(a) # E: Revealed type is 'Literal['']' -reveal_type(b) # E: Revealed type is 'Literal[' foo bar ']' -reveal_type(c) # E: Revealed type is 'Literal[' foo bar ']' -reveal_type(d) # E: Revealed type is 'Literal['foo']' -reveal_type(e) # E: Revealed type is 'Literal['foo']' +reveal_type(a) # N: Revealed type is 'Literal['']' +reveal_type(b) # N: Revealed type is 'Literal[' foo bar ']' +reveal_type(c) # N: Revealed type is 'Literal[' foo bar ']' +reveal_type(d) # N: Revealed type is 'Literal['foo']' +reveal_type(e) # N: Revealed type is 'Literal['foo']' def f1(x: Literal[""]) -> Literal[""]: pass def f2(x: Literal[" foo bar "]) -> Literal[" foo bar "]: pass @@ -778,11 +778,11 @@ def f3(x: Literal[' foo bar ']) -> Literal[' foo bar ']: pass def f4(x: Literal["foo"]) -> Literal["foo"]: pass def f5(x: Literal['foo']) -> Literal['foo']: pass -reveal_type(f1) # E: Revealed type is 'def (x: Literal['']) -> Literal['']' -reveal_type(f2) # E: Revealed type is 'def (x: Literal[' foo bar ']) -> Literal[' foo bar ']' -reveal_type(f3) # E: Revealed type is 'def (x: Literal[' foo bar ']) -> Literal[' foo bar ']' -reveal_type(f4) # E: Revealed type is 'def (x: Literal['foo']) -> Literal['foo']' -reveal_type(f5) # E: Revealed type is 'def (x: Literal['foo']) -> Literal['foo']' +reveal_type(f1) # N: Revealed type is 'def (x: Literal['']) -> Literal['']' +reveal_type(f2) # N: Revealed type is 'def (x: Literal[' foo bar ']) -> Literal[' foo bar ']' +reveal_type(f3) # N: Revealed type is 'def (x: Literal[' foo bar ']) -> Literal[' foo bar ']' +reveal_type(f4) # N: Revealed type is 'def (x: Literal['foo']) -> Literal['foo']' +reveal_type(f5) # N: Revealed type is 'def (x: Literal['foo']) -> Literal['foo']' [out] [case testLiteralBasicStrUsageSlashes] @@ -794,22 +794,22 @@ b: Literal["foo\nbar"] reveal_type(a) reveal_type(b) [out skip-path-normalization] -main:6: error: Revealed type is 'Literal['foo\\nbar']' -main:7: error: Revealed type is 'Literal['foo\nbar']' +main:6: note: Revealed type is 'Literal['foo\\nbar']' +main:7: note: Revealed type is 'Literal['foo\nbar']' [case testLiteralBasicNoneUsage] # Note: Literal[None] and None are equivalent from typing_extensions import Literal a: Literal[None] -reveal_type(a) # E: Revealed type is 'None' +reveal_type(a) # N: Revealed type is 'None' def f1(x: Literal[None]) -> None: pass def f2(x: None) -> Literal[None]: pass def f3(x: Literal[None]) -> Literal[None]: pass -reveal_type(f1) # E: Revealed type is 'def (x: None)' -reveal_type(f2) # E: Revealed type is 'def (x: None)' -reveal_type(f3) # E: Revealed type is 'def (x: None)' +reveal_type(f1) # N: Revealed type is 'def (x: None)' +reveal_type(f2) # N: Revealed type is 'def (x: None)' +reveal_type(f3) # N: Revealed type is 'def (x: None)' [out] [case testLiteralCallingUnionFunction] @@ -846,8 +846,8 @@ from missing_module import BadAlias # E: Cannot find module named 'missing_m a: Literal[Any] # E: Parameter 1 of Literal[...] cannot be of type "Any" b: Literal[BadAlias] # E: Parameter 1 of Literal[...] cannot be of type "Any" -reveal_type(a) # E: Revealed type is 'Any' -reveal_type(b) # E: Revealed type is 'Any' +reveal_type(a) # N: Revealed type is 'Any' +reveal_type(b) # N: Revealed type is 'Any' [out] [case testLiteralDisallowActualTypes] @@ -858,10 +858,10 @@ b: Literal[float] # E: Parameter 1 of Literal[...] is invalid c: Literal[bool] # E: Parameter 1 of Literal[...] is invalid d: Literal[str] # E: Parameter 1 of Literal[...] is invalid -reveal_type(a) # E: Revealed type is 'Any' -reveal_type(b) # E: Revealed type is 'Any' -reveal_type(c) # E: Revealed type is 'Any' -reveal_type(d) # E: Revealed type is 'Any' +reveal_type(a) # N: Revealed type is 'Any' +reveal_type(b) # N: Revealed type is 'Any' +reveal_type(c) # N: Revealed type is 'Any' +reveal_type(d) # N: Revealed type is 'Any' [builtins fixtures/primitives.pyi] [out] @@ -878,10 +878,10 @@ c2t = Literal[3j] # E: Parameter 1 of Literal[...] cannot be of type "complex d2t = 3j a2: a2t -reveal_type(a2) # E: Revealed type is 'Any' +reveal_type(a2) # N: Revealed type is 'Any' b2: b2t # E: Invalid type "__main__.b2t" c2: c2t -reveal_type(c2) # E: Revealed type is 'Any' +reveal_type(c2) # N: Revealed type is 'Any' d2: d2t # E: Invalid type "__main__.d2t" [builtins fixtures/complex_tuple.pyi] [out] @@ -954,14 +954,14 @@ b: Literal["a", "b", "c"] c: Literal[1, "b", True, None] d: Literal[1, 1, 1] e: Literal[None, None, None] -reveal_type(a) # E: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' -reveal_type(b) # E: Revealed type is 'Union[Literal['a'], Literal['b'], Literal['c']]' -reveal_type(c) # E: Revealed type is 'Union[Literal[1], Literal['b'], Literal[True], None]' +reveal_type(a) # N: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' +reveal_type(b) # N: Revealed type is 'Union[Literal['a'], Literal['b'], Literal['c']]' +reveal_type(c) # N: Revealed type is 'Union[Literal[1], Literal['b'], Literal[True], None]' # Note: I was thinking these should be simplified, but it seems like # mypy doesn't simplify unions with duplicate values with other types. -reveal_type(d) # E: Revealed type is 'Union[Literal[1], Literal[1], Literal[1]]' -reveal_type(e) # E: Revealed type is 'Union[None, None, None]' +reveal_type(d) # N: Revealed type is 'Union[Literal[1], Literal[1], Literal[1]]' +reveal_type(e) # N: Revealed type is 'Union[None, None, None]' [builtins fixtures/bool.pyi] [out] @@ -971,8 +971,8 @@ from typing_extensions import Literal # Literal[1, 2, 3]. So we treat the two as being equivalent for now. a: Literal[1, 2, 3] b: Literal[(1, 2, 3)] -reveal_type(a) # E: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' -reveal_type(b) # E: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' +reveal_type(a) # N: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' +reveal_type(b) # N: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]]' [out] [case testLiteralNestedUsage] @@ -980,35 +980,35 @@ reveal_type(b) # E: Revealed type is 'Union[Literal[1], Literal[2], Literal[3]] from typing_extensions import Literal a: Literal[Literal[3], 4, Literal["foo"]] -reveal_type(a) # E: Revealed type is 'Union[Literal[3], Literal[4], Literal['foo']]' +reveal_type(a) # N: Revealed type is 'Union[Literal[3], Literal[4], Literal['foo']]' alias_for_literal = Literal[5] b: Literal[alias_for_literal] -reveal_type(b) # E: Revealed type is 'Literal[5]' +reveal_type(b) # N: Revealed type is 'Literal[5]' another_alias = Literal[1, None] c: Literal[alias_for_literal, another_alias, "r"] -reveal_type(c) # E: Revealed type is 'Union[Literal[5], Literal[1], None, Literal['r']]' +reveal_type(c) # N: Revealed type is 'Union[Literal[5], Literal[1], None, Literal['r']]' basic_mode = Literal["r", "w", "a"] basic_with_plus = Literal["r+", "w+", "a+"] combined: Literal[basic_mode, basic_with_plus] -reveal_type(combined) # E: Revealed type is 'Union[Literal['r'], Literal['w'], Literal['a'], Literal['r+'], Literal['w+'], Literal['a+']]' +reveal_type(combined) # N: Revealed type is 'Union[Literal['r'], Literal['w'], Literal['a'], Literal['r+'], Literal['w+'], Literal['a+']]' [out] [case testLiteralBiasTowardsAssumingForwardReference] from typing_extensions import Literal a: "Foo" -reveal_type(a) # E: Revealed type is '__main__.Foo' +reveal_type(a) # N: Revealed type is '__main__.Foo' b: Literal["Foo"] -reveal_type(b) # E: Revealed type is 'Literal['Foo']' +reveal_type(b) # N: Revealed type is 'Literal['Foo']' c: "Literal[Foo]" # E: Parameter 1 of Literal[...] is invalid d: "Literal['Foo']" -reveal_type(d) # E: Revealed type is 'Literal['Foo']' +reveal_type(d) # N: Revealed type is 'Literal['Foo']' class Foo: pass [out] @@ -1017,19 +1017,19 @@ class Foo: pass from typing_extensions import Literal a: "Foo" -reveal_type(a) # E: Revealed type is 'Literal[5]' +reveal_type(a) # N: Revealed type is 'Literal[5]' b: Literal["Foo"] -reveal_type(b) # E: Revealed type is 'Literal['Foo']' +reveal_type(b) # N: Revealed type is 'Literal['Foo']' c: "Literal[Foo]" -reveal_type(c) # E: Revealed type is 'Literal[5]' +reveal_type(c) # N: Revealed type is 'Literal[5]' d: "Literal['Foo']" -reveal_type(d) # E: Revealed type is 'Literal['Foo']' +reveal_type(d) # N: Revealed type is 'Literal['Foo']' e: Literal[Foo, 'Foo'] -reveal_type(e) # E: Revealed type is 'Union[Literal[5], Literal['Foo']]' +reveal_type(e) # N: Revealed type is 'Union[Literal[5], Literal['Foo']]' Foo = Literal[5] [out] @@ -1038,13 +1038,13 @@ Foo = Literal[5] from typing_extensions import Literal a = None # type: Foo -reveal_type(a) # E: Revealed type is '__main__.Foo' +reveal_type(a) # N: Revealed type is '__main__.Foo' b = None # type: "Foo" -reveal_type(b) # E: Revealed type is '__main__.Foo' +reveal_type(b) # N: Revealed type is '__main__.Foo' c = None # type: Literal["Foo"] -reveal_type(c) # E: Revealed type is 'Literal['Foo']' +reveal_type(c) # N: Revealed type is 'Literal['Foo']' d = None # type: Literal[Foo] # E: Parameter 1 of Literal[...] is invalid @@ -1173,9 +1173,9 @@ b: Literal[2] c: int d: Literal[3] -reveal_type(foo(a)) # E: Revealed type is '__main__.IOLike[builtins.int]' -reveal_type(foo(b)) # E: Revealed type is '__main__.IOLike[builtins.str]' -reveal_type(foo(c)) # E: Revealed type is '__main__.IOLike[Any]' +reveal_type(foo(a)) # N: Revealed type is '__main__.IOLike[builtins.int]' +reveal_type(foo(b)) # N: Revealed type is '__main__.IOLike[builtins.str]' +reveal_type(foo(c)) # N: Revealed type is '__main__.IOLike[Any]' foo(d) [builtins fixtures/ops.pyi] [out] @@ -1274,18 +1274,18 @@ none1: Literal[None] = None none2 = None none3: None = None -reveal_type(int1) # E: Revealed type is 'Literal[1]' -reveal_type(int2) # E: Revealed type is 'builtins.int' -reveal_type(int3) # E: Revealed type is 'builtins.int' -reveal_type(str1) # E: Revealed type is 'Literal['foo']' -reveal_type(str2) # E: Revealed type is 'builtins.str' -reveal_type(str3) # E: Revealed type is 'builtins.str' -reveal_type(bool1) # E: Revealed type is 'Literal[True]' -reveal_type(bool2) # E: Revealed type is 'builtins.bool' -reveal_type(bool3) # E: Revealed type is 'builtins.bool' -reveal_type(none1) # E: Revealed type is 'None' -reveal_type(none2) # E: Revealed type is 'None' -reveal_type(none3) # E: Revealed type is 'None' +reveal_type(int1) # N: Revealed type is 'Literal[1]' +reveal_type(int2) # N: Revealed type is 'builtins.int' +reveal_type(int3) # N: Revealed type is 'builtins.int' +reveal_type(str1) # N: Revealed type is 'Literal['foo']' +reveal_type(str2) # N: Revealed type is 'builtins.str' +reveal_type(str3) # N: Revealed type is 'builtins.str' +reveal_type(bool1) # N: Revealed type is 'Literal[True]' +reveal_type(bool2) # N: Revealed type is 'builtins.bool' +reveal_type(bool3) # N: Revealed type is 'builtins.bool' +reveal_type(none1) # N: Revealed type is 'None' +reveal_type(none2) # N: Revealed type is 'None' +reveal_type(none3) # N: Revealed type is 'None' [builtins fixtures/primitives.pyi] [out] @@ -1423,14 +1423,14 @@ f = [1, "x"] g: List[List[List[Literal[1, 2, 3]]]] = [[[1, 2, 3], [3]]] h: List[Literal[1]] = [] -reveal_type(a) # E: Revealed type is 'builtins.list[Literal[1]]' -reveal_type(b) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(c) # E: Revealed type is 'builtins.list[Union[Literal[1], Literal[2], Literal[3]]]' -reveal_type(d) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(e) # E: Revealed type is 'builtins.list[Union[Literal[1], Literal['x']]]' -reveal_type(f) # E: Revealed type is 'builtins.list[builtins.object*]' -reveal_type(g) # E: Revealed type is 'builtins.list[builtins.list[builtins.list[Union[Literal[1], Literal[2], Literal[3]]]]]' -reveal_type(h) # E: Revealed type is 'builtins.list[Literal[1]]' +reveal_type(a) # N: Revealed type is 'builtins.list[Literal[1]]' +reveal_type(b) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(c) # N: Revealed type is 'builtins.list[Union[Literal[1], Literal[2], Literal[3]]]' +reveal_type(d) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(e) # N: Revealed type is 'builtins.list[Union[Literal[1], Literal['x']]]' +reveal_type(f) # N: Revealed type is 'builtins.list[builtins.object*]' +reveal_type(g) # N: Revealed type is 'builtins.list[builtins.list[builtins.list[Union[Literal[1], Literal[2], Literal[3]]]]]' +reveal_type(h) # N: Revealed type is 'builtins.list[Literal[1]]' lit1: Literal[1] lit2: Literal[2] @@ -1442,11 +1442,11 @@ arr3 = [lit1, 4, 5] arr4 = [lit1, lit2, lit3] arr5 = [object(), lit1] -reveal_type(arr1) # E: Revealed type is 'builtins.list[Literal[1]]' -reveal_type(arr2) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(arr3) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(arr4) # E: Revealed type is 'builtins.list[builtins.object*]' -reveal_type(arr5) # E: Revealed type is 'builtins.list[builtins.object*]' +reveal_type(arr1) # N: Revealed type is 'builtins.list[Literal[1]]' +reveal_type(arr2) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(arr3) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(arr4) # N: Revealed type is 'builtins.list[builtins.object*]' +reveal_type(arr5) # N: Revealed type is 'builtins.list[builtins.object*]' bad: List[Literal[1, 2]] = [1, 2, 3] # E: List item 2 has incompatible type "Literal[3]"; expected "Union[Literal[1], Literal[2]]" @@ -1464,7 +1464,7 @@ b: Tuple[int, Literal[1, 2], Literal[3], Tuple[Literal["foo"]]] = (1, 2, 3, ("fo c: Tuple[Literal[1], Literal[2]] = (2, 1) # E: Incompatible types in assignment (expression has type "Tuple[Literal[2], Literal[1]]", variable has type "Tuple[Literal[1], Literal[2]]") d = (1, 2) -reveal_type(d) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(d) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' [builtins fixtures/tuple.pyi] [out] @@ -1477,7 +1477,7 @@ a = {"x": 1, "y": 2} b: Dict[str, Literal[1, 2]] = {"x": 1, "y": 2} c: Dict[Literal["x", "y"], int] = {"x": 1, "y": 2} -reveal_type(a) # E: Revealed type is 'builtins.dict[builtins.str*, builtins.int*]' +reveal_type(a) # N: Revealed type is 'builtins.dict[builtins.str*, builtins.int*]' [builtins fixtures/dict.pyi] [out] @@ -1498,16 +1498,16 @@ a: Literal[1] b: Literal[2] c: Literal[1, 2] -reveal_type(func(1)) # E: Revealed type is 'builtins.str' -reveal_type(func(2)) # E: Revealed type is 'builtins.int' -reveal_type(func(3)) # E: Revealed type is 'builtins.object' -reveal_type(func(a)) # E: Revealed type is 'builtins.str' -reveal_type(func(b)) # E: Revealed type is 'builtins.int' +reveal_type(func(1)) # N: Revealed type is 'builtins.str' +reveal_type(func(2)) # N: Revealed type is 'builtins.int' +reveal_type(func(3)) # N: Revealed type is 'builtins.object' +reveal_type(func(a)) # N: Revealed type is 'builtins.str' +reveal_type(func(b)) # N: Revealed type is 'builtins.int' # Note: the fact that we don't do union math here is consistent # with the output we would have gotten if we replaced int and the # Literal types here with regular classes/subclasses. -reveal_type(func(c)) # E: Revealed type is 'builtins.object' +reveal_type(func(c)) # N: Revealed type is 'builtins.object' [out] [case testLiteralOverloadProhibitUnsafeOverlaps] @@ -1557,20 +1557,20 @@ d: Literal[6, 7] e: int f: Literal[7, "bar"] -reveal_type(func(a)) # E: Revealed type is 'Union[__main__.A, __main__.C]' -reveal_type(func(b)) # E: Revealed type is '__main__.B' -reveal_type(func(c)) # E: Revealed type is 'Union[__main__.B, __main__.A]' -reveal_type(func(d)) # E: Revealed type is '__main__.B' \ +reveal_type(func(a)) # N: Revealed type is 'Union[__main__.A, __main__.C]' +reveal_type(func(b)) # N: Revealed type is '__main__.B' +reveal_type(func(c)) # N: Revealed type is 'Union[__main__.B, __main__.A]' +reveal_type(func(d)) # N: Revealed type is '__main__.B' \ # E: Argument 1 to "func" has incompatible type "Union[Literal[6], Literal[7]]"; expected "Union[Literal[3], Literal[4], Literal[5], Literal[6]]" -reveal_type(func(e)) # E: Revealed type is 'Any' \ +reveal_type(func(e)) # N: Revealed type is 'Any' \ # E: No overload variant of "func" matches argument type "int" \ # N: Possible overload variants: \ # N: def func(x: Literal[-40]) -> A \ # N: def func(x: Union[Literal[3], Literal[4], Literal[5], Literal[6]]) -> B \ # N: def func(x: Literal['foo']) -> C -reveal_type(func(f)) # E: Revealed type is 'Any' \ +reveal_type(func(f)) # N: Revealed type is 'Any' \ # E: No overload variant of "func" matches argument type "Union[Literal[7], Literal['bar']]" \ # N: Possible overload variants: \ # N: def func(x: Literal[-40]) -> A \ @@ -1593,11 +1593,11 @@ def f(x): x: Literal[1, 2] y: Literal[1, 2, 3] z: Literal[1, 2, "three"] -reveal_type(f(x)) # E: Revealed type is 'builtins.int' -reveal_type(f(1)) # E: Revealed type is 'builtins.int' -reveal_type(f(2)) # E: Revealed type is 'builtins.int' -reveal_type(f(y)) # E: Revealed type is 'builtins.object' -reveal_type(f(z)) # E: Revealed type is 'builtins.int' \ +reveal_type(f(x)) # N: Revealed type is 'builtins.int' +reveal_type(f(1)) # N: Revealed type is 'builtins.int' +reveal_type(f(2)) # N: Revealed type is 'builtins.int' +reveal_type(f(y)) # N: Revealed type is 'builtins.object' +reveal_type(f(z)) # N: Revealed type is 'builtins.int' \ # E: Argument 1 to "f" has incompatible type "Union[Literal[1], Literal[2], Literal['three']]"; expected "Union[Literal[1], Literal[2]]" [out] @@ -1614,8 +1614,8 @@ def f1(x: T, y: str) -> Union[T, str]: ... def f1(x, y): pass a: Literal[1] -reveal_type(f1(1, 1)) # E: Revealed type is 'builtins.int*' -reveal_type(f1(a, 1)) # E: Revealed type is 'Literal[1]' +reveal_type(f1(1, 1)) # N: Revealed type is 'builtins.int*' +reveal_type(f1(a, 1)) # N: Revealed type is 'Literal[1]' @overload def f2(x: T, y: Literal[3]) -> T: ... @@ -1623,8 +1623,8 @@ def f2(x: T, y: Literal[3]) -> T: ... def f2(x: T, y: str) -> Union[T]: ... def f2(x, y): pass -reveal_type(f2(1, 3)) # E: Revealed type is 'builtins.int*' -reveal_type(f2(a, 3)) # E: Revealed type is 'Literal[1]' +reveal_type(f2(1, 3)) # N: Revealed type is 'builtins.int*' +reveal_type(f2(a, 3)) # N: Revealed type is 'Literal[1]' @overload def f3(x: Literal[3]) -> Literal[3]: ... @@ -1632,8 +1632,8 @@ def f3(x: Literal[3]) -> Literal[3]: ... def f3(x: T) -> T: ... def f3(x): pass -reveal_type(f3(1)) # E: Revealed type is 'builtins.int*' -reveal_type(f3(a)) # E: Revealed type is 'Literal[1]' +reveal_type(f3(1)) # N: Revealed type is 'builtins.int*' +reveal_type(f3(a)) # N: Revealed type is 'Literal[1]' @overload def f4(x: str) -> str: ... @@ -1642,13 +1642,13 @@ def f4(x: T) -> T: ... def f4(x): pass b: Literal['foo'] -reveal_type(f4(1)) # E: Revealed type is 'builtins.int*' -reveal_type(f4(a)) # E: Revealed type is 'Literal[1]' -reveal_type(f4("foo")) # E: Revealed type is 'builtins.str' +reveal_type(f4(1)) # N: Revealed type is 'builtins.int*' +reveal_type(f4(a)) # N: Revealed type is 'Literal[1]' +reveal_type(f4("foo")) # N: Revealed type is 'builtins.str' # Note: first overload is selected and prevents the typevar from # ever inferring a Literal["something"]. -reveal_type(f4(b)) # E: Revealed type is 'builtins.str' +reveal_type(f4(b)) # N: Revealed type is 'builtins.str' [out] [case testLiteralInferredInOverloadContextUnionMathTrickyOverload] @@ -1683,27 +1683,27 @@ c: Literal[4] d: Literal['foo'] e: str -reveal_type(a + a) # E: Revealed type is 'builtins.int' -reveal_type(a + b) # E: Revealed type is 'builtins.int' -reveal_type(b + a) # E: Revealed type is 'builtins.int' -reveal_type(a + 1) # E: Revealed type is 'builtins.int' -reveal_type(1 + a) # E: Revealed type is 'builtins.int' -reveal_type(a + c) # E: Revealed type is 'builtins.int' -reveal_type(c + a) # E: Revealed type is 'builtins.int' +reveal_type(a + a) # N: Revealed type is 'builtins.int' +reveal_type(a + b) # N: Revealed type is 'builtins.int' +reveal_type(b + a) # N: Revealed type is 'builtins.int' +reveal_type(a + 1) # N: Revealed type is 'builtins.int' +reveal_type(1 + a) # N: Revealed type is 'builtins.int' +reveal_type(a + c) # N: Revealed type is 'builtins.int' +reveal_type(c + a) # N: Revealed type is 'builtins.int' -reveal_type(d + d) # E: Revealed type is 'builtins.str' -reveal_type(d + e) # E: Revealed type is 'builtins.str' -reveal_type(e + d) # E: Revealed type is 'builtins.str' -reveal_type(d + 'foo') # E: Revealed type is 'builtins.str' -reveal_type('foo' + d) # E: Revealed type is 'builtins.str' +reveal_type(d + d) # N: Revealed type is 'builtins.str' +reveal_type(d + e) # N: Revealed type is 'builtins.str' +reveal_type(e + d) # N: Revealed type is 'builtins.str' +reveal_type(d + 'foo') # N: Revealed type is 'builtins.str' +reveal_type('foo' + d) # N: Revealed type is 'builtins.str' -reveal_type(a.__add__(b)) # E: Revealed type is 'builtins.int' -reveal_type(b.__add__(a)) # E: Revealed type is 'builtins.int' +reveal_type(a.__add__(b)) # N: Revealed type is 'builtins.int' +reveal_type(b.__add__(a)) # N: Revealed type is 'builtins.int' a *= b # E: Incompatible types in assignment (expression has type "int", variable has type "Literal[3]") b *= a -reveal_type(b) # E: Revealed type is 'builtins.int' +reveal_type(b) # N: Revealed type is 'builtins.int' [out] [case testLiteralFallbackInheritedMethodsWorkCorrectly] @@ -1711,10 +1711,10 @@ from typing_extensions import Literal a: Literal['foo'] b: str -reveal_type(a.startswith(a)) # E: Revealed type is 'builtins.bool' -reveal_type(b.startswith(a)) # E: Revealed type is 'builtins.bool' -reveal_type(a.startswith(b)) # E: Revealed type is 'builtins.bool' -reveal_type(a.strip()) # E: Revealed type is 'builtins.str' +reveal_type(a.startswith(a)) # N: Revealed type is 'builtins.bool' +reveal_type(b.startswith(a)) # N: Revealed type is 'builtins.bool' +reveal_type(a.startswith(b)) # N: Revealed type is 'builtins.bool' +reveal_type(a.strip()) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -1815,8 +1815,8 @@ def expects_literal(x: Literal[3]) -> None: pass def expects_int(x: int) -> None: pass a: Literal[3] -reveal_type(foo(3)) # E: Revealed type is 'builtins.int*' -reveal_type(foo(a)) # E: Revealed type is 'Literal[3]' +reveal_type(foo(3)) # N: Revealed type is 'builtins.int*' +reveal_type(foo(a)) # N: Revealed type is 'Literal[3]' expects_literal(3) expects_literal(foo(3)) @@ -1878,9 +1878,9 @@ def expects_literal(a: Literal[3]) -> None: pass def expects_literal_wrapper(x: Wrapper[Literal[3]]) -> None: pass a: Literal[3] -reveal_type(Wrapper(3)) # E: Revealed type is '__main__.Wrapper[builtins.int*]' -reveal_type(Wrapper[Literal[3]](3)) # E: Revealed type is '__main__.Wrapper[Literal[3]]' -reveal_type(Wrapper(a)) # E: Revealed type is '__main__.Wrapper[Literal[3]]' +reveal_type(Wrapper(3)) # N: Revealed type is '__main__.Wrapper[builtins.int*]' +reveal_type(Wrapper[Literal[3]](3)) # N: Revealed type is '__main__.Wrapper[Literal[3]]' +reveal_type(Wrapper(a)) # N: Revealed type is '__main__.Wrapper[Literal[3]]' expects_literal(Wrapper(a).inner()) @@ -1920,22 +1920,22 @@ a: Literal[3] b: Literal[4] c: int -reveal_type(func1) # E: Revealed type is 'def [TLiteral <: Literal[3]] (x: TLiteral`-1) -> TLiteral`-1' +reveal_type(func1) # N: Revealed type is 'def [TLiteral <: Literal[3]] (x: TLiteral`-1) -> TLiteral`-1' -reveal_type(func1(3)) # E: Revealed type is 'Literal[3]' -reveal_type(func1(a)) # E: Revealed type is 'Literal[3]' -reveal_type(func1(4)) # E: Revealed type is 'Literal[4]' \ +reveal_type(func1(3)) # N: Revealed type is 'Literal[3]' +reveal_type(func1(a)) # N: Revealed type is 'Literal[3]' +reveal_type(func1(4)) # N: Revealed type is 'Literal[4]' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]" -reveal_type(func1(b)) # E: Revealed type is 'Literal[4]' \ +reveal_type(func1(b)) # N: Revealed type is 'Literal[4]' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]" -reveal_type(func1(c)) # E: Revealed type is 'builtins.int*' \ +reveal_type(func1(c)) # N: Revealed type is 'builtins.int*' \ # E: Value of type variable "TLiteral" of "func1" cannot be "int" -reveal_type(func2(3)) # E: Revealed type is 'builtins.int*' -reveal_type(func2(a)) # E: Revealed type is 'Literal[3]' -reveal_type(func2(4)) # E: Revealed type is 'builtins.int*' -reveal_type(func2(b)) # E: Revealed type is 'Literal[4]' -reveal_type(func2(c)) # E: Revealed type is 'builtins.int*' +reveal_type(func2(3)) # N: Revealed type is 'builtins.int*' +reveal_type(func2(a)) # N: Revealed type is 'Literal[3]' +reveal_type(func2(4)) # N: Revealed type is 'builtins.int*' +reveal_type(func2(b)) # N: Revealed type is 'Literal[4]' +reveal_type(func2(c)) # N: Revealed type is 'builtins.int*' [out] [case testLiteralAndGenericsRespectsValueRestriction] @@ -1965,34 +1965,34 @@ s1: Literal['foo'] s2: Literal['bar'] s: str -reveal_type(func1) # E: Revealed type is 'def [TLiteral in (Literal[3], Literal['foo'])] (x: TLiteral`-1) -> TLiteral`-1' +reveal_type(func1) # N: Revealed type is 'def [TLiteral in (Literal[3], Literal['foo'])] (x: TLiteral`-1) -> TLiteral`-1' -reveal_type(func1(3)) # E: Revealed type is 'Literal[3]' -reveal_type(func1(i1)) # E: Revealed type is 'Literal[3]' -reveal_type(func1(4)) # E: Revealed type is 'Literal[4]' \ +reveal_type(func1(3)) # N: Revealed type is 'Literal[3]' +reveal_type(func1(i1)) # N: Revealed type is 'Literal[3]' +reveal_type(func1(4)) # N: Revealed type is 'Literal[4]' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]" -reveal_type(func1(i2)) # E: Revealed type is 'Literal[4]' \ +reveal_type(func1(i2)) # N: Revealed type is 'Literal[4]' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]" -reveal_type(func1(i)) # E: Revealed type is 'builtins.int*' \ +reveal_type(func1(i)) # N: Revealed type is 'builtins.int*' \ # E: Value of type variable "TLiteral" of "func1" cannot be "int" -reveal_type(func1("foo")) # E: Revealed type is 'Literal['foo']' -reveal_type(func1(s1)) # E: Revealed type is 'Literal['foo']' -reveal_type(func1("bar")) # E: Revealed type is 'Literal['bar']' \ +reveal_type(func1("foo")) # N: Revealed type is 'Literal['foo']' +reveal_type(func1(s1)) # N: Revealed type is 'Literal['foo']' +reveal_type(func1("bar")) # N: Revealed type is 'Literal['bar']' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal['bar']" -reveal_type(func1(s2)) # E: Revealed type is 'Literal['bar']' \ +reveal_type(func1(s2)) # N: Revealed type is 'Literal['bar']' \ # E: Value of type variable "TLiteral" of "func1" cannot be "Literal['bar']" -reveal_type(func1(s)) # E: Revealed type is 'builtins.str*' \ +reveal_type(func1(s)) # N: Revealed type is 'builtins.str*' \ # E: Value of type variable "TLiteral" of "func1" cannot be "str" -reveal_type(func2(3)) # E: Revealed type is 'builtins.int*' -reveal_type(func2(i1)) # E: Revealed type is 'builtins.int*' -reveal_type(func2(4)) # E: Revealed type is 'builtins.int*' -reveal_type(func2(i2)) # E: Revealed type is 'builtins.int*' -reveal_type(func2("foo")) # E: Revealed type is 'builtins.str*' -reveal_type(func2(s1)) # E: Revealed type is 'builtins.str*' -reveal_type(func2("bar")) # E: Revealed type is 'builtins.str*' -reveal_type(func2(s2)) # E: Revealed type is 'builtins.str*' +reveal_type(func2(3)) # N: Revealed type is 'builtins.int*' +reveal_type(func2(i1)) # N: Revealed type is 'builtins.int*' +reveal_type(func2(4)) # N: Revealed type is 'builtins.int*' +reveal_type(func2(i2)) # N: Revealed type is 'builtins.int*' +reveal_type(func2("foo")) # N: Revealed type is 'builtins.str*' +reveal_type(func2(s1)) # N: Revealed type is 'builtins.str*' +reveal_type(func2("bar")) # N: Revealed type is 'builtins.str*' +reveal_type(func2(s2)) # N: Revealed type is 'builtins.str*' [out] [case testLiteralAndGenericsWithOverloads] @@ -2011,10 +2011,10 @@ def identity(x: T) -> T: pass a: Literal[4] b: Literal[5] -reveal_type(func1(identity(4))) # E: Revealed type is 'Literal[19]' -reveal_type(func1(identity(5))) # E: Revealed type is 'builtins.int' -reveal_type(func1(identity(a))) # E: Revealed type is 'Literal[19]' -reveal_type(func1(identity(b))) # E: Revealed type is 'builtins.int' +reveal_type(func1(identity(4))) # N: Revealed type is 'Literal[19]' +reveal_type(func1(identity(5))) # N: Revealed type is 'builtins.int' +reveal_type(func1(identity(a))) # N: Revealed type is 'Literal[19]' +reveal_type(func1(identity(b))) # N: Revealed type is 'builtins.int' -- -- Interactions with meets @@ -2036,15 +2036,15 @@ arr3 = [a, c] arr4 = [a, d] arr5 = [a, e] -reveal_type(arr1) # E: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.int]' -reveal_type(arr2) # E: Revealed type is 'builtins.list[builtins.function*]' -reveal_type(arr3) # E: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' -reveal_type(arr4) # E: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' -reveal_type(arr5) # E: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' +reveal_type(arr1) # N: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.int]' +reveal_type(arr2) # N: Revealed type is 'builtins.list[builtins.function*]' +reveal_type(arr3) # N: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' +reveal_type(arr4) # N: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' +reveal_type(arr5) # N: Revealed type is 'builtins.list[def (Literal[1]) -> builtins.object]' # Inspect just only one interesting one lit: Literal[1] -reveal_type(arr2[0](lit)) # E: Revealed type is 'Any' \ +reveal_type(arr2[0](lit)) # N: Revealed type is 'Any' \ # E: Cannot call function of unknown type T = TypeVar('T') @@ -2056,11 +2056,11 @@ def f3(x: Literal[1], y: int) -> None: pass def f4(x: Literal[1], y: object) -> None: pass def f5(x: Literal[1], y: Union[Literal[1], Literal[2]]) -> None: pass -reveal_type(unify(f1)) # E: Revealed type is 'Literal[1]' -reveal_type(unify(f2)) # E: Revealed type is 'None' -reveal_type(unify(f3)) # E: Revealed type is 'Literal[1]' -reveal_type(unify(f4)) # E: Revealed type is 'Literal[1]' -reveal_type(unify(f5)) # E: Revealed type is 'Literal[1]' +reveal_type(unify(f1)) # N: Revealed type is 'Literal[1]' +reveal_type(unify(f2)) # N: Revealed type is 'None' +reveal_type(unify(f3)) # N: Revealed type is 'Literal[1]' +reveal_type(unify(f4)) # N: Revealed type is 'Literal[1]' +reveal_type(unify(f5)) # N: Revealed type is 'Literal[1]' [builtins fixtures/list.pyi] [out] @@ -2074,15 +2074,15 @@ b: Callable[[Literal[2]], str] lit: Literal[1] arr = [a, b] -reveal_type(arr) # E: Revealed type is 'builtins.list[builtins.function*]' -reveal_type(arr[0](lit)) # E: Revealed type is 'Any' \ +reveal_type(arr) # N: Revealed type is 'builtins.list[builtins.function*]' +reveal_type(arr[0](lit)) # N: Revealed type is 'Any' \ # E: Cannot call function of unknown type T = TypeVar('T') def unify(func: Callable[[T, T], None]) -> T: pass def func(x: Literal[1], y: Literal[2]) -> None: pass -reveal_type(unify(func)) # E: Revealed type is '' +reveal_type(unify(func)) # N: Revealed type is '' [builtins fixtures/list.pyi] [out] @@ -2110,27 +2110,27 @@ idx5: Literal[5] idx_neg1: Literal[-1] tup1: Tuple[A, B, C, D, E] -reveal_type(tup1[idx0]) # E: Revealed type is '__main__.A' -reveal_type(tup1[idx1]) # E: Revealed type is '__main__.B' -reveal_type(tup1[idx2]) # E: Revealed type is '__main__.C' -reveal_type(tup1[idx3]) # E: Revealed type is '__main__.D' -reveal_type(tup1[idx4]) # E: Revealed type is '__main__.E' -reveal_type(tup1[idx_neg1]) # E: Revealed type is '__main__.E' +reveal_type(tup1[idx0]) # N: Revealed type is '__main__.A' +reveal_type(tup1[idx1]) # N: Revealed type is '__main__.B' +reveal_type(tup1[idx2]) # N: Revealed type is '__main__.C' +reveal_type(tup1[idx3]) # N: Revealed type is '__main__.D' +reveal_type(tup1[idx4]) # N: Revealed type is '__main__.E' +reveal_type(tup1[idx_neg1]) # N: Revealed type is '__main__.E' tup1[idx5] # E: Tuple index out of range -reveal_type(tup1[idx2:idx4]) # E: Revealed type is 'Tuple[__main__.C, __main__.D]' -reveal_type(tup1[::idx2]) # E: Revealed type is 'Tuple[__main__.A, __main__.C, __main__.E]' +reveal_type(tup1[idx2:idx4]) # N: Revealed type is 'Tuple[__main__.C, __main__.D]' +reveal_type(tup1[::idx2]) # N: Revealed type is 'Tuple[__main__.A, __main__.C, __main__.E]' Tup2Class = NamedTuple('Tup2Class', [('a', A), ('b', B), ('c', C), ('d', D), ('e', E)]) tup2: Tup2Class -reveal_type(tup2[idx0]) # E: Revealed type is '__main__.A' -reveal_type(tup2[idx1]) # E: Revealed type is '__main__.B' -reveal_type(tup2[idx2]) # E: Revealed type is '__main__.C' -reveal_type(tup2[idx3]) # E: Revealed type is '__main__.D' -reveal_type(tup2[idx4]) # E: Revealed type is '__main__.E' -reveal_type(tup2[idx_neg1]) # E: Revealed type is '__main__.E' +reveal_type(tup2[idx0]) # N: Revealed type is '__main__.A' +reveal_type(tup2[idx1]) # N: Revealed type is '__main__.B' +reveal_type(tup2[idx2]) # N: Revealed type is '__main__.C' +reveal_type(tup2[idx3]) # N: Revealed type is '__main__.D' +reveal_type(tup2[idx4]) # N: Revealed type is '__main__.E' +reveal_type(tup2[idx_neg1]) # N: Revealed type is '__main__.E' tup2[idx5] # E: Tuple index out of range -reveal_type(tup2[idx2:idx4]) # E: Revealed type is 'Tuple[__main__.C, __main__.D, fallback=__main__.Tup2Class]' -reveal_type(tup2[::idx2]) # E: Revealed type is 'Tuple[__main__.A, __main__.C, __main__.E, fallback=__main__.Tup2Class]' +reveal_type(tup2[idx2:idx4]) # N: Revealed type is 'Tuple[__main__.C, __main__.D, fallback=__main__.Tup2Class]' +reveal_type(tup2[::idx2]) # N: Revealed type is 'Tuple[__main__.A, __main__.C, __main__.E, fallback=__main__.Tup2Class]' [builtins fixtures/slice.pyi] [out] @@ -2152,17 +2152,17 @@ c_key: Literal["c"] d: Outer -reveal_type(d[a_key]) # E: Revealed type is 'builtins.int' -reveal_type(d[b_key]) # E: Revealed type is 'builtins.str' +reveal_type(d[a_key]) # N: Revealed type is 'builtins.int' +reveal_type(d[b_key]) # N: Revealed type is 'builtins.str' d[c_key] # E: TypedDict "Outer" has no key 'c' -reveal_type(d.get(a_key, u)) # E: Revealed type is 'Union[builtins.int, __main__.Unrelated]' -reveal_type(d.get(b_key, u)) # E: Revealed type is 'Union[builtins.str, __main__.Unrelated]' +reveal_type(d.get(a_key, u)) # N: Revealed type is 'Union[builtins.int, __main__.Unrelated]' +reveal_type(d.get(b_key, u)) # N: Revealed type is 'Union[builtins.str, __main__.Unrelated]' d.get(c_key, u) # E: TypedDict "Outer" has no key 'c' -reveal_type(d.pop(a_key)) # E: Revealed type is 'builtins.int' \ +reveal_type(d.pop(a_key)) # N: Revealed type is 'builtins.int' \ # E: Key 'a' of TypedDict "Outer" cannot be deleted -reveal_type(d.pop(b_key)) # E: Revealed type is 'builtins.str' +reveal_type(d.pop(b_key)) # N: Revealed type is 'builtins.str' d.pop(c_key) # E: TypedDict "Outer" has no key 'c' del d[a_key] # E: Key 'a' of TypedDict "Outer" cannot be deleted @@ -2198,10 +2198,10 @@ b: MyTuple c: MyDict u: Unrelated -reveal_type(a[int_key_good]) # E: Revealed type is 'builtins.int' -reveal_type(b[int_key_good]) # E: Revealed type is 'builtins.int' -reveal_type(c[str_key_good]) # E: Revealed type is 'builtins.int' -reveal_type(c.get(str_key_good, u)) # E: Revealed type is 'Union[builtins.int, __main__.Unrelated]' +reveal_type(a[int_key_good]) # N: Revealed type is 'builtins.int' +reveal_type(b[int_key_good]) # N: Revealed type is 'builtins.int' +reveal_type(c[str_key_good]) # N: Revealed type is 'builtins.int' +reveal_type(c.get(str_key_good, u)) # N: Revealed type is 'Union[builtins.int, __main__.Unrelated]' a[int_key_bad] # E: Tuple index out of range b[int_key_bad] # E: Tuple index out of range @@ -2237,15 +2237,15 @@ unicode_key = u"key" # type: Literal[u"key"] # actual string literals. # # See https://github.com/python/mypy/issues/6123 for more details. -reveal_type(normal_dict[normal_key]) # E: Revealed type is 'builtins.int' -reveal_type(normal_dict[unicode_key]) # E: Revealed type is 'builtins.int' -reveal_type(unicode_dict[normal_key]) # E: Revealed type is 'builtins.int' -reveal_type(unicode_dict[unicode_key]) # E: Revealed type is 'builtins.int' +reveal_type(normal_dict[normal_key]) # N: Revealed type is 'builtins.int' +reveal_type(normal_dict[unicode_key]) # N: Revealed type is 'builtins.int' +reveal_type(unicode_dict[normal_key]) # N: Revealed type is 'builtins.int' +reveal_type(unicode_dict[unicode_key]) # N: Revealed type is 'builtins.int' -reveal_type(normal_dict.get(normal_key)) # E: Revealed type is 'builtins.int' -reveal_type(normal_dict.get(unicode_key)) # E: Revealed type is 'builtins.int' -reveal_type(unicode_dict.get(normal_key)) # E: Revealed type is 'builtins.int' -reveal_type(unicode_dict.get(unicode_key)) # E: Revealed type is 'builtins.int' +reveal_type(normal_dict.get(normal_key)) # N: Revealed type is 'builtins.int' +reveal_type(normal_dict.get(unicode_key)) # N: Revealed type is 'builtins.int' +reveal_type(unicode_dict.get(normal_key)) # N: Revealed type is 'builtins.int' +reveal_type(unicode_dict.get(unicode_key)) # N: Revealed type is 'builtins.int' [file normal_mod.py] from mypy_extensions import TypedDict @@ -2289,33 +2289,33 @@ def force2(x: Literal["foo"]) -> None: pass def force3(x: Literal[True]) -> None: pass def force4(x: Literal[None]) -> None: pass -reveal_type(var1) # E: Revealed type is 'builtins.int' -reveal_type(var2) # E: Revealed type is 'builtins.str' -reveal_type(var3) # E: Revealed type is 'builtins.bool' -reveal_type(var4) # E: Revealed type is 'None' -force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(var2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(var3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(var4)) # E: Revealed type is 'None' - -reveal_type(Foo.classvar1) # E: Revealed type is 'builtins.int' -reveal_type(Foo.classvar2) # E: Revealed type is 'builtins.str' -reveal_type(Foo.classvar3) # E: Revealed type is 'builtins.bool' -reveal_type(Foo.classvar4) # E: Revealed type is 'None' -force1(reveal_type(Foo.classvar1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(Foo.classvar2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(Foo.classvar3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(Foo.classvar4)) # E: Revealed type is 'None' +reveal_type(var1) # N: Revealed type is 'builtins.int' +reveal_type(var2) # N: Revealed type is 'builtins.str' +reveal_type(var3) # N: Revealed type is 'builtins.bool' +reveal_type(var4) # N: Revealed type is 'None' +force1(reveal_type(var1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(var2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(var3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(var4)) # N: Revealed type is 'None' + +reveal_type(Foo.classvar1) # N: Revealed type is 'builtins.int' +reveal_type(Foo.classvar2) # N: Revealed type is 'builtins.str' +reveal_type(Foo.classvar3) # N: Revealed type is 'builtins.bool' +reveal_type(Foo.classvar4) # N: Revealed type is 'None' +force1(reveal_type(Foo.classvar1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(Foo.classvar2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(Foo.classvar3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(Foo.classvar4)) # N: Revealed type is 'None' f = Foo() -reveal_type(f.instancevar1) # E: Revealed type is 'builtins.int' -reveal_type(f.instancevar2) # E: Revealed type is 'builtins.str' -reveal_type(f.instancevar3) # E: Revealed type is 'builtins.bool' -reveal_type(f.instancevar4) # E: Revealed type is 'None' -force1(reveal_type(f.instancevar1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(f.instancevar2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(f.instancevar3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(f.instancevar4)) # E: Revealed type is 'None' +reveal_type(f.instancevar1) # N: Revealed type is 'builtins.int' +reveal_type(f.instancevar2) # N: Revealed type is 'builtins.str' +reveal_type(f.instancevar3) # N: Revealed type is 'builtins.bool' +reveal_type(f.instancevar4) # N: Revealed type is 'None' +force1(reveal_type(f.instancevar1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(f.instancevar2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(f.instancevar3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(f.instancevar4)) # N: Revealed type is 'None' [builtins fixtures/primitives.pyi] [out] @@ -2344,29 +2344,29 @@ def force2(x: Literal["foo"]) -> None: pass def force3(x: Literal[True]) -> None: pass def force4(x: Literal[None]) -> None: pass -reveal_type(var1) # E: Revealed type is 'builtins.int' -reveal_type(var2) # E: Revealed type is 'builtins.str' -reveal_type(var3) # E: Revealed type is 'builtins.bool' -reveal_type(var4) # E: Revealed type is 'None' +reveal_type(var1) # N: Revealed type is 'builtins.int' +reveal_type(var2) # N: Revealed type is 'builtins.str' +reveal_type(var3) # N: Revealed type is 'builtins.bool' +reveal_type(var4) # N: Revealed type is 'None' force1(var1) # E: Argument 1 to "force1" has incompatible type "int"; expected "Literal[1]" force2(var2) # E: Argument 1 to "force2" has incompatible type "str"; expected "Literal['foo']" force3(var3) # E: Argument 1 to "force3" has incompatible type "bool"; expected "Literal[True]" force4(var4) -reveal_type(Foo.classvar1) # E: Revealed type is 'builtins.int' -reveal_type(Foo.classvar2) # E: Revealed type is 'builtins.str' -reveal_type(Foo.classvar3) # E: Revealed type is 'builtins.bool' -reveal_type(Foo.classvar4) # E: Revealed type is 'None' +reveal_type(Foo.classvar1) # N: Revealed type is 'builtins.int' +reveal_type(Foo.classvar2) # N: Revealed type is 'builtins.str' +reveal_type(Foo.classvar3) # N: Revealed type is 'builtins.bool' +reveal_type(Foo.classvar4) # N: Revealed type is 'None' force1(Foo.classvar1) # E: Argument 1 to "force1" has incompatible type "int"; expected "Literal[1]" force2(Foo.classvar2) # E: Argument 1 to "force2" has incompatible type "str"; expected "Literal['foo']" force3(Foo.classvar3) # E: Argument 1 to "force3" has incompatible type "bool"; expected "Literal[True]" force4(Foo.classvar4) f = Foo() -reveal_type(f.instancevar1) # E: Revealed type is 'builtins.int' -reveal_type(f.instancevar2) # E: Revealed type is 'builtins.str' -reveal_type(f.instancevar3) # E: Revealed type is 'builtins.bool' -reveal_type(f.instancevar4) # E: Revealed type is 'None' +reveal_type(f.instancevar1) # N: Revealed type is 'builtins.int' +reveal_type(f.instancevar2) # N: Revealed type is 'builtins.str' +reveal_type(f.instancevar3) # N: Revealed type is 'builtins.bool' +reveal_type(f.instancevar4) # N: Revealed type is 'None' force1(f.instancevar1) # E: Argument 1 to "force1" has incompatible type "int"; expected "Literal[1]" force2(f.instancevar2) # E: Argument 1 to "force2" has incompatible type "str"; expected "Literal['foo']" force3(f.instancevar3) # E: Argument 1 to "force3" has incompatible type "bool"; expected "Literal[True]" @@ -2399,33 +2399,33 @@ def force2(x: Literal["foo"]) -> None: pass def force3(x: Literal[True]) -> None: pass def force4(x: Literal[None]) -> None: pass -reveal_type(var1) # E: Revealed type is 'Literal[1]' -reveal_type(var2) # E: Revealed type is 'Literal['foo']' -reveal_type(var3) # E: Revealed type is 'Literal[True]' -reveal_type(var4) # E: Revealed type is 'None' -force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(var2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(var3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(var4)) # E: Revealed type is 'None' - -reveal_type(Foo.classvar1) # E: Revealed type is 'Literal[1]' -reveal_type(Foo.classvar2) # E: Revealed type is 'Literal['foo']' -reveal_type(Foo.classvar3) # E: Revealed type is 'Literal[True]' -reveal_type(Foo.classvar4) # E: Revealed type is 'None' -force1(reveal_type(Foo.classvar1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(Foo.classvar2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(Foo.classvar3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(Foo.classvar4)) # E: Revealed type is 'None' +reveal_type(var1) # N: Revealed type is 'Literal[1]' +reveal_type(var2) # N: Revealed type is 'Literal['foo']' +reveal_type(var3) # N: Revealed type is 'Literal[True]' +reveal_type(var4) # N: Revealed type is 'None' +force1(reveal_type(var1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(var2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(var3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(var4)) # N: Revealed type is 'None' + +reveal_type(Foo.classvar1) # N: Revealed type is 'Literal[1]' +reveal_type(Foo.classvar2) # N: Revealed type is 'Literal['foo']' +reveal_type(Foo.classvar3) # N: Revealed type is 'Literal[True]' +reveal_type(Foo.classvar4) # N: Revealed type is 'None' +force1(reveal_type(Foo.classvar1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(Foo.classvar2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(Foo.classvar3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(Foo.classvar4)) # N: Revealed type is 'None' f = Foo() -reveal_type(f.instancevar1) # E: Revealed type is 'Literal[1]' -reveal_type(f.instancevar2) # E: Revealed type is 'Literal['foo']' -reveal_type(f.instancevar3) # E: Revealed type is 'Literal[True]' -reveal_type(f.instancevar4) # E: Revealed type is 'None' -force1(reveal_type(f.instancevar1)) # E: Revealed type is 'Literal[1]' -force2(reveal_type(f.instancevar2)) # E: Revealed type is 'Literal['foo']' -force3(reveal_type(f.instancevar3)) # E: Revealed type is 'Literal[True]' -force4(reveal_type(f.instancevar4)) # E: Revealed type is 'None' +reveal_type(f.instancevar1) # N: Revealed type is 'Literal[1]' +reveal_type(f.instancevar2) # N: Revealed type is 'Literal['foo']' +reveal_type(f.instancevar3) # N: Revealed type is 'Literal[True]' +reveal_type(f.instancevar4) # N: Revealed type is 'None' +force1(reveal_type(f.instancevar1)) # N: Revealed type is 'Literal[1]' +force2(reveal_type(f.instancevar2)) # N: Revealed type is 'Literal['foo']' +force3(reveal_type(f.instancevar3)) # N: Revealed type is 'Literal[True]' +force4(reveal_type(f.instancevar4)) # N: Revealed type is 'None' [builtins fixtures/primitives.pyi] [out] @@ -2468,12 +2468,12 @@ b: Final = (1, 2) def force1(x: Literal[1]) -> None: pass def force2(x: Tuple[Literal[1], Literal[2]]) -> None: pass -reveal_type(a) # E: Revealed type is 'builtins.int' -reveal_type(b) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(a) # N: Revealed type is 'builtins.int' +reveal_type(b) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' -force1(reveal_type(a)) # E: Revealed type is 'Literal[1]' +force1(reveal_type(a)) # N: Revealed type is 'Literal[1]' force2(reveal_type(b)) # E: Argument 1 to "force2" has incompatible type "Tuple[int, int]"; expected "Tuple[Literal[1], Literal[2]]" \ - # E: Revealed type is 'Tuple[builtins.int, builtins.int]' + # N: Revealed type is 'Tuple[builtins.int, builtins.int]' [builtins fixtures/tuple.pyi] [out] @@ -2489,21 +2489,21 @@ direct = [1] def force1(x: List[Literal[1]]) -> None: pass def force2(x: Literal[1]) -> None: pass -reveal_type(implicit) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(implicit) # N: Revealed type is 'builtins.list[builtins.int*]' force1(reveal_type(implicit)) # E: Argument 1 to "force1" has incompatible type "List[int]"; expected "List[Literal[1]]" \ - # E: Revealed type is 'builtins.list[builtins.int*]' + # N: Revealed type is 'builtins.list[builtins.int*]' force2(reveal_type(implicit[0])) # E: Argument 1 to "force2" has incompatible type "int"; expected "Literal[1]" \ - # E: Revealed type is 'builtins.int*' + # N: Revealed type is 'builtins.int*' -reveal_type(explicit) # E: Revealed type is 'builtins.list[Literal[1]]' -force1(reveal_type(explicit)) # E: Revealed type is 'builtins.list[Literal[1]]' -force2(reveal_type(explicit[0])) # E: Revealed type is 'Literal[1]' +reveal_type(explicit) # N: Revealed type is 'builtins.list[Literal[1]]' +force1(reveal_type(explicit)) # N: Revealed type is 'builtins.list[Literal[1]]' +force2(reveal_type(explicit[0])) # N: Revealed type is 'Literal[1]' -reveal_type(direct) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(direct) # N: Revealed type is 'builtins.list[builtins.int*]' force1(reveal_type(direct)) # E: Argument 1 to "force1" has incompatible type "List[int]"; expected "List[Literal[1]]" \ - # E: Revealed type is 'builtins.list[builtins.int*]' + # N: Revealed type is 'builtins.list[builtins.int*]' force2(reveal_type(direct[0])) # E: Argument 1 to "force2" has incompatible type "int"; expected "Literal[1]" \ - # E: Revealed type is 'builtins.int*' + # N: Revealed type is 'builtins.int*' [builtins fixtures/list.pyi] [out] @@ -2517,16 +2517,16 @@ c: Final = b"foo" def force_unicode(x: Literal[u"foo"]) -> None: pass def force_bytes(x: Literal[b"foo"]) -> None: pass -force_unicode(reveal_type(a)) # E: Revealed type is 'Literal['foo']' -force_unicode(reveal_type(b)) # E: Revealed type is 'Literal['foo']' +force_unicode(reveal_type(a)) # N: Revealed type is 'Literal['foo']' +force_unicode(reveal_type(b)) # N: Revealed type is 'Literal['foo']' force_unicode(reveal_type(c)) # E: Argument 1 to "force_unicode" has incompatible type "Literal[b'foo']"; expected "Literal['foo']" \ - # E: Revealed type is 'Literal[b'foo']' + # N: Revealed type is 'Literal[b'foo']' force_bytes(reveal_type(a)) # E: Argument 1 to "force_bytes" has incompatible type "Literal['foo']"; expected "Literal[b'foo']" \ - # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal['foo']' force_bytes(reveal_type(b)) # E: Argument 1 to "force_bytes" has incompatible type "Literal['foo']"; expected "Literal[b'foo']" \ - # E: Revealed type is 'Literal['foo']' -force_bytes(reveal_type(c)) # E: Revealed type is 'Literal[b'foo']' + # N: Revealed type is 'Literal['foo']' +force_bytes(reveal_type(c)) # N: Revealed type is 'Literal[b'foo']' [out] [case testLiteralFinalStringTypesPython2UnicodeLiterals] @@ -2545,16 +2545,16 @@ def force_bytes(x): # type: (Literal[b"foo"]) -> None pass -force_unicode(reveal_type(a)) # E: Revealed type is 'Literal[u'foo']' -force_unicode(reveal_type(b)) # E: Revealed type is 'Literal[u'foo']' +force_unicode(reveal_type(a)) # N: Revealed type is 'Literal[u'foo']' +force_unicode(reveal_type(b)) # N: Revealed type is 'Literal[u'foo']' force_unicode(reveal_type(c)) # E: Argument 1 to "force_unicode" has incompatible type "Literal['foo']"; expected "Literal[u'foo']" \ - # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal['foo']' force_bytes(reveal_type(a)) # E: Argument 1 to "force_bytes" has incompatible type "Literal[u'foo']"; expected "Literal['foo']" \ - # E: Revealed type is 'Literal[u'foo']' + # N: Revealed type is 'Literal[u'foo']' force_bytes(reveal_type(b)) # E: Argument 1 to "force_bytes" has incompatible type "Literal[u'foo']"; expected "Literal['foo']" \ - # E: Revealed type is 'Literal[u'foo']' -force_bytes(reveal_type(c)) # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal[u'foo']' +force_bytes(reveal_type(c)) # N: Revealed type is 'Literal['foo']' [out] [case testLiteralFinalStringTypesPython2] @@ -2572,16 +2572,16 @@ def force_bytes(x): # type: (Literal[b"foo"]) -> None pass -force_unicode(reveal_type(a)) # E: Revealed type is 'Literal[u'foo']' +force_unicode(reveal_type(a)) # N: Revealed type is 'Literal[u'foo']' force_unicode(reveal_type(b)) # E: Argument 1 to "force_unicode" has incompatible type "Literal['foo']"; expected "Literal[u'foo']" \ - # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal['foo']' force_unicode(reveal_type(c)) # E: Argument 1 to "force_unicode" has incompatible type "Literal['foo']"; expected "Literal[u'foo']" \ - # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal['foo']' force_bytes(reveal_type(a)) # E: Argument 1 to "force_bytes" has incompatible type "Literal[u'foo']"; expected "Literal['foo']" \ - # E: Revealed type is 'Literal[u'foo']' -force_bytes(reveal_type(b)) # E: Revealed type is 'Literal['foo']' -force_bytes(reveal_type(c)) # E: Revealed type is 'Literal['foo']' + # N: Revealed type is 'Literal[u'foo']' +force_bytes(reveal_type(b)) # N: Revealed type is 'Literal['foo']' +force_bytes(reveal_type(c)) # N: Revealed type is 'Literal['foo']' [out] [case testLiteralFinalPropagatesThroughGenerics] @@ -2605,38 +2605,38 @@ def over_literal(x: WrapperClass[Literal[99]]) -> None: pass var1: Final = 99 w1 = WrapperClass(var1) force(reveal_type(w1.data)) # E: Argument 1 to "force" has incompatible type "int"; expected "Literal[99]" \ - # E: Revealed type is 'builtins.int*' + # N: Revealed type is 'builtins.int*' force(reveal_type(WrapperClass(var1).data)) # E: Argument 1 to "force" has incompatible type "int"; expected "Literal[99]" \ - # E: Revealed type is 'builtins.int*' -force(reveal_type(wrapper_func(var1))) # E: Revealed type is 'Literal[99]' -over_int(reveal_type(w1)) # E: Revealed type is '__main__.WrapperClass[builtins.int*]' + # N: Revealed type is 'builtins.int*' +force(reveal_type(wrapper_func(var1))) # N: Revealed type is 'Literal[99]' +over_int(reveal_type(w1)) # N: Revealed type is '__main__.WrapperClass[builtins.int*]' over_literal(reveal_type(w1)) # E: Argument 1 to "over_literal" has incompatible type "WrapperClass[int]"; expected "WrapperClass[Literal[99]]" \ - # E: Revealed type is '__main__.WrapperClass[builtins.int*]' -over_int(reveal_type(WrapperClass(var1))) # E: Revealed type is '__main__.WrapperClass[builtins.int]' -over_literal(reveal_type(WrapperClass(var1))) # E: Revealed type is '__main__.WrapperClass[Literal[99]]' + # N: Revealed type is '__main__.WrapperClass[builtins.int*]' +over_int(reveal_type(WrapperClass(var1))) # N: Revealed type is '__main__.WrapperClass[builtins.int]' +over_literal(reveal_type(WrapperClass(var1))) # N: Revealed type is '__main__.WrapperClass[Literal[99]]' w2 = WrapperClass(99) force(reveal_type(w2.data)) # E: Argument 1 to "force" has incompatible type "int"; expected "Literal[99]" \ - # E: Revealed type is 'builtins.int*' + # N: Revealed type is 'builtins.int*' force(reveal_type(WrapperClass(99).data)) # E: Argument 1 to "force" has incompatible type "int"; expected "Literal[99]" \ - # E: Revealed type is 'builtins.int*' -force(reveal_type(wrapper_func(99))) # E: Revealed type is 'Literal[99]' -over_int(reveal_type(w2)) # E: Revealed type is '__main__.WrapperClass[builtins.int*]' + # N: Revealed type is 'builtins.int*' +force(reveal_type(wrapper_func(99))) # N: Revealed type is 'Literal[99]' +over_int(reveal_type(w2)) # N: Revealed type is '__main__.WrapperClass[builtins.int*]' over_literal(reveal_type(w2)) # E: Argument 1 to "over_literal" has incompatible type "WrapperClass[int]"; expected "WrapperClass[Literal[99]]" \ - # E: Revealed type is '__main__.WrapperClass[builtins.int*]' -over_int(reveal_type(WrapperClass(99))) # E: Revealed type is '__main__.WrapperClass[builtins.int]' -over_literal(reveal_type(WrapperClass(99))) # E: Revealed type is '__main__.WrapperClass[Literal[99]]' + # N: Revealed type is '__main__.WrapperClass[builtins.int*]' +over_int(reveal_type(WrapperClass(99))) # N: Revealed type is '__main__.WrapperClass[builtins.int]' +over_literal(reveal_type(WrapperClass(99))) # N: Revealed type is '__main__.WrapperClass[Literal[99]]' var3: Literal[99] = 99 w3 = WrapperClass(var3) -force(reveal_type(w3.data)) # E: Revealed type is 'Literal[99]' -force(reveal_type(WrapperClass(var3).data)) # E: Revealed type is 'Literal[99]' -force(reveal_type(wrapper_func(var3))) # E: Revealed type is 'Literal[99]' +force(reveal_type(w3.data)) # N: Revealed type is 'Literal[99]' +force(reveal_type(WrapperClass(var3).data)) # N: Revealed type is 'Literal[99]' +force(reveal_type(wrapper_func(var3))) # N: Revealed type is 'Literal[99]' over_int(reveal_type(w3)) # E: Argument 1 to "over_int" has incompatible type "WrapperClass[Literal[99]]"; expected "WrapperClass[int]" \ - # E: Revealed type is '__main__.WrapperClass[Literal[99]]' -over_literal(reveal_type(w3)) # E: Revealed type is '__main__.WrapperClass[Literal[99]]' -over_int(reveal_type(WrapperClass(var3))) # E: Revealed type is '__main__.WrapperClass[builtins.int]' -over_literal(reveal_type(WrapperClass(var3))) # E: Revealed type is '__main__.WrapperClass[Literal[99]]' + # N: Revealed type is '__main__.WrapperClass[Literal[99]]' +over_literal(reveal_type(w3)) # N: Revealed type is '__main__.WrapperClass[Literal[99]]' +over_int(reveal_type(WrapperClass(var3))) # N: Revealed type is '__main__.WrapperClass[builtins.int]' +over_literal(reveal_type(WrapperClass(var3))) # N: Revealed type is '__main__.WrapperClass[Literal[99]]' [out] [case testLiteralFinalUsedInLiteralType] @@ -2734,9 +2734,9 @@ expects_red(r) expects_red(g) # E: Argument 1 to "expects_red" has incompatible type "Literal[Color.GREEN]"; expected "Literal[Color.RED]" expects_red(b) # E: Argument 1 to "expects_red" has incompatible type "Literal[Color.BLUE]"; expected "Literal[Color.RED]" -reveal_type(expects_red) # E: Revealed type is 'def (x: Literal[__main__.Color.RED])' -reveal_type(r) # E: Revealed type is 'Literal[__main__.Color.RED]' -reveal_type(r.func()) # E: Revealed type is 'builtins.int' +reveal_type(expects_red) # N: Revealed type is 'def (x: Literal[__main__.Color.RED])' +reveal_type(r) # N: Revealed type is 'Literal[__main__.Color.RED]' +reveal_type(r.func()) # N: Revealed type is 'builtins.int' [out] [case testLiteralWithEnumsDefinedInClass] @@ -2757,8 +2757,8 @@ g: Literal[Wrapper.Color.GREEN] foo(r) foo(g) # E: Argument 1 to "foo" has incompatible type "Literal[Color.GREEN]"; expected "Literal[Color.RED]" -reveal_type(foo) # E: Revealed type is 'def (x: Literal[__main__.Wrapper.Color.RED])' -reveal_type(r) # E: Revealed type is 'Literal[__main__.Wrapper.Color.RED]' +reveal_type(foo) # N: Revealed type is 'def (x: Literal[__main__.Wrapper.Color.RED])' +reveal_type(r) # N: Revealed type is 'Literal[__main__.Wrapper.Color.RED]' [out] [case testLiteralWithEnumsSimilarDefinitions] @@ -2809,10 +2809,10 @@ b: Literal[B.FOO] c: Literal[C.FOO] d: Literal[D.FOO] -reveal_type(a) # E: Revealed type is 'Literal[__main__.A.FOO]' -reveal_type(b) # E: Revealed type is 'Literal[__main__.B.FOO]' -reveal_type(c) # E: Revealed type is 'Literal[__main__.C.FOO]' -reveal_type(d) # E: Revealed type is 'Literal[__main__.D.FOO]' +reveal_type(a) # N: Revealed type is 'Literal[__main__.A.FOO]' +reveal_type(b) # N: Revealed type is 'Literal[__main__.B.FOO]' +reveal_type(c) # N: Revealed type is 'Literal[__main__.C.FOO]' +reveal_type(d) # N: Revealed type is 'Literal[__main__.D.FOO]' [builtins fixtures/dict.pyi] [out] @@ -2860,7 +2860,7 @@ class Test(Enum): Alias = Test x: Literal[Alias.FOO] -reveal_type(x) # E: Revealed type is 'Literal[__main__.Test.FOO]' +reveal_type(x) # N: Revealed type is 'Literal[__main__.Test.FOO]' [out] [case testLiteralUsingEnumAttributesInLiteralContexts] @@ -2922,9 +2922,9 @@ expects_foo(Test3.BAR.name) # E: Argument 1 to "expects_foo" has incompatible t expects_foo(Test4.BAR.name) # E: Argument 1 to "expects_foo" has incompatible type "Literal['BAR']"; expected "Literal['FOO']" expects_foo(Test5.BAR.name) # E: Argument 1 to "expects_foo" has incompatible type "Literal['BAR']"; expected "Literal['FOO']" -reveal_type(Test1.FOO.name) # E: Revealed type is 'builtins.str' -reveal_type(Test2.FOO.name) # E: Revealed type is 'builtins.str' -reveal_type(Test3.FOO.name) # E: Revealed type is 'builtins.str' -reveal_type(Test4.FOO.name) # E: Revealed type is 'builtins.str' -reveal_type(Test5.FOO.name) # E: Revealed type is 'builtins.str' +reveal_type(Test1.FOO.name) # N: Revealed type is 'builtins.str' +reveal_type(Test2.FOO.name) # N: Revealed type is 'builtins.str' +reveal_type(Test3.FOO.name) # N: Revealed type is 'builtins.str' +reveal_type(Test4.FOO.name) # N: Revealed type is 'builtins.str' +reveal_type(Test5.FOO.name) # N: Revealed type is 'builtins.str' [out] diff --git a/test-data/unit/check-modules-case.test b/test-data/unit/check-modules-case.test index 0a1f7296a5f1..92026302e978 100644 --- a/test-data/unit/check-modules-case.test +++ b/test-data/unit/check-modules-case.test @@ -11,7 +11,7 @@ from a import B # E: Module 'a' has no attribute 'B' from a import B # E: Module 'a' has no attribute 'B' from other import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file a/__init__.py] [file a/b/__init__.py] @@ -44,7 +44,7 @@ import a [case testNamespacePackagePickFirstOnMypyPathCase] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file XX/foo/bar.py] x = 0 [file yy/foo/bar.py] @@ -56,7 +56,7 @@ mypy_path = tmp/xx, tmp/yy [case testClassicPackageInsideNamespacePackageCase] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar.baz.boo import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file xx/foo/bar/baz/boo.py] x = '' [file xx/foo/bar/baz/__init__.py] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 0498a05b5bb1..c390a66cf0ba 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -833,9 +833,9 @@ def f(self, session: Session) -> None: # E: Invalid type "a.Session" [case testSubmoduleRegularImportAddsAllParents] import a.b.c -reveal_type(a.value) # E: Revealed type is 'builtins.int' -reveal_type(a.b.value) # E: Revealed type is 'builtins.str' -reveal_type(a.b.c.value) # E: Revealed type is 'builtins.float' +reveal_type(a.value) # N: Revealed type is 'builtins.int' +reveal_type(a.b.value) # N: Revealed type is 'builtins.str' +reveal_type(a.b.c.value) # N: Revealed type is 'builtins.float' b.value # E: Name 'b' is not defined c.value # E: Name 'c' is not defined @@ -849,7 +849,7 @@ value = 3.2 [case testSubmoduleImportAsDoesNotAddParents] import a.b.c as foo -reveal_type(foo.value) # E: Revealed type is 'builtins.float' +reveal_type(foo.value) # N: Revealed type is 'builtins.float' a.value # E: Name 'a' is not defined b.value # E: Name 'b' is not defined c.value # E: Name 'c' is not defined @@ -864,7 +864,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents] from a import b -reveal_type(b.value) # E: Revealed type is 'builtins.str' +reveal_type(b.value) # N: Revealed type is 'builtins.str' b.c.value # E: Module has no attribute "c" a.value # E: Name 'a' is not defined @@ -879,7 +879,7 @@ value = 3.2 [case testSubmoduleImportFromDoesNotAddParents2] from a.b import c -reveal_type(c.value) # E: Revealed type is 'builtins.float' +reveal_type(c.value) # N: Revealed type is 'builtins.float' a.value # E: Name 'a' is not defined b.value # E: Name 'b' is not defined @@ -965,7 +965,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:8: note: Revealed type is 'parent.common.SomeClass' tmp/parent/child.py:9: error: Module has no attribute "unrelated" [case testSubmoduleMixingImportFromAndImport2] @@ -984,7 +984,7 @@ reveal_type(foo) [builtins fixtures/module.pyi] [out] -tmp/parent/child.py:4: error: Revealed type is 'parent.common.SomeClass' +tmp/parent/child.py:4: note: Revealed type is 'parent.common.SomeClass' -- Tests repeated imports @@ -1186,7 +1186,7 @@ x = 0 [case testImportInClass] class C: import foo -reveal_type(C.foo.bar) # E: Revealed type is 'builtins.int' +reveal_type(C.foo.bar) # N: Revealed type is 'builtins.int' [file foo.py] bar = 0 [builtins fixtures/module.pyi] @@ -1259,7 +1259,7 @@ import x class Sub(x.Base): attr = 0 [out] -tmp/x.py:5: error: Revealed type is 'builtins.int' +tmp/x.py:5: note: Revealed type is 'builtins.int' -- This case has a symmetrical cycle, so it doesn't matter in what -- order the files are processed. It depends on the lightweight type @@ -1336,7 +1336,7 @@ def foo() -> int: import x value = 12 [out] -tmp/x.py:3: error: Revealed type is 'builtins.int' +tmp/x.py:3: note: Revealed type is 'builtins.int' -- This is not really cycle-related but still about the lightweight -- type checker. @@ -1346,7 +1346,7 @@ x = 1 # type: str reveal_type(x) [out] main:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") -main:2: error: Revealed type is 'builtins.str' +main:2: note: Revealed type is 'builtins.str' -- Tests for cross-module second_pass checking. @@ -1364,7 +1364,7 @@ def g() -> int: return a.y x = 1 + 1 [out] -tmp/b.py:3: error: Revealed type is 'builtins.int' +tmp/b.py:3: note: Revealed type is 'builtins.int' [case testSymmetricImportCycle2] import b @@ -1380,7 +1380,7 @@ def g() -> int: return a.y x = 1 + 1 [out] -tmp/a.py:3: error: Revealed type is 'builtins.int' +tmp/a.py:3: note: Revealed type is 'builtins.int' [case testThreePassesRequired] import b @@ -1441,7 +1441,7 @@ def deco(f: Callable[[T], int]) -> Callable[[T], int]: a.x return f [out] -tmp/a.py:6: error: Revealed type is 'def (builtins.str*) -> builtins.int' +tmp/a.py:6: note: Revealed type is 'def (builtins.str*) -> builtins.int' [case testDeferredClassContext] class A: @@ -1498,7 +1498,7 @@ def part4_thing(a: int) -> str: pass [builtins fixtures/bool.pyi] [out] -tmp/part3.py:2: error: Revealed type is 'def (a: builtins.int) -> builtins.str' +tmp/part3.py:2: note: Revealed type is 'def (a: builtins.int) -> builtins.str' [case testImportStarAliasAnyList] import bar @@ -1516,7 +1516,7 @@ AnyAlias = Any ListAlias = List [builtins fixtures/list.pyi] [out] -tmp/bar.py:5: error: Revealed type is 'builtins.list[builtins.int]' +tmp/bar.py:5: note: Revealed type is 'builtins.list[builtins.int]' [case testImportStarAliasSimpleGeneric] from ex2a import * @@ -1528,7 +1528,7 @@ def do_another() -> Row: return {} do_something({'good': 'bad'}) # E: Dict entry 0 has incompatible type "str": "str"; expected "str": "int" -reveal_type(do_another()) # E: Revealed type is 'builtins.dict[builtins.str, builtins.int]' +reveal_type(do_another()) # N: Revealed type is 'builtins.dict[builtins.str, builtins.int]' [file ex2a.py] from typing import Dict @@ -1543,10 +1543,10 @@ another = G[X]() second = XT[str]() last = XT[G]() -reveal_type(notes) # E: Revealed type is 'y.G[y.G[builtins.int]]' -reveal_type(another) # E: Revealed type is 'y.G[y.G*[builtins.int]]' -reveal_type(second) # E: Revealed type is 'y.G[builtins.str*]' -reveal_type(last) # E: Revealed type is 'y.G[y.G*[Any]]' +reveal_type(notes) # N: Revealed type is 'y.G[y.G[builtins.int]]' +reveal_type(another) # N: Revealed type is 'y.G[y.G*[builtins.int]]' +reveal_type(second) # N: Revealed type is 'y.G[builtins.str*]' +reveal_type(last) # N: Revealed type is 'y.G[y.G*[Any]]' [file y.py] from typing import Generic, TypeVar @@ -1568,7 +1568,7 @@ def bar(x: Any, y: AnyCallable) -> Any: return 'foo' cb = None # type: AnyCallable -reveal_type(cb) # E: Revealed type is 'def (*Any, **Any) -> Any' +reveal_type(cb) # N: Revealed type is 'def (*Any, **Any) -> Any' [file foo.py] from typing import Callable, Any @@ -1579,8 +1579,8 @@ AnyCallable = Callable[..., Any] import types def f() -> types.ModuleType: return types -reveal_type(f()) # E: Revealed type is 'types.ModuleType' -reveal_type(types) # E: Revealed type is 'types.ModuleType' +reveal_type(f()) # N: Revealed type is 'types.ModuleType' +reveal_type(types) # N: Revealed type is 'types.ModuleType' [builtins fixtures/module.pyi] @@ -1589,14 +1589,14 @@ class C: import m def foo(self) -> None: x = self.m.a - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' # ensure we distinguish self from other variables y = 'hello' z = y.m.a # E: "str" has no attribute "m" @classmethod def cmethod(cls) -> None: y = cls.m.a - reveal_type(y) # E: Revealed type is 'builtins.str' + reveal_type(y) # N: Revealed type is 'builtins.str' @staticmethod def smethod(foo: int) -> None: # we aren't confused by first arg of a staticmethod @@ -1610,7 +1610,7 @@ a = 'foo' [case testModuleAlias] import m m2 = m -reveal_type(m2.a) # E: Revealed type is 'builtins.str' +reveal_type(m2.a) # N: Revealed type is 'builtins.str' m2.b # E: Module has no attribute "b" m2.c = 'bar' # E: Module has no attribute "c" @@ -1625,7 +1625,7 @@ import m class C: x = m def foo(self) -> None: - reveal_type(self.x.a) # E: Revealed type is 'builtins.str' + reveal_type(self.x.a) # N: Revealed type is 'builtins.str' [file m.py] a = 'foo' @@ -1637,12 +1637,12 @@ import m def foo() -> None: x = m - reveal_type(x.a) # E: Revealed type is 'builtins.str' + reveal_type(x.a) # N: Revealed type is 'builtins.str' class C: def foo(self) -> None: x = m - reveal_type(x.a) # E: Revealed type is 'builtins.str' + reveal_type(x.a) # N: Revealed type is 'builtins.str' [file m.py] a = 'foo' @@ -1654,10 +1654,10 @@ import m m3 = m2 = m m4 = m3 m5 = m4 -reveal_type(m2.a) # E: Revealed type is 'builtins.str' -reveal_type(m3.a) # E: Revealed type is 'builtins.str' -reveal_type(m4.a) # E: Revealed type is 'builtins.str' -reveal_type(m5.a) # E: Revealed type is 'builtins.str' +reveal_type(m2.a) # N: Revealed type is 'builtins.str' +reveal_type(m3.a) # N: Revealed type is 'builtins.str' +reveal_type(m4.a) # N: Revealed type is 'builtins.str' +reveal_type(m5.a) # N: Revealed type is 'builtins.str' [file m.py] a = 'foo' @@ -1667,10 +1667,10 @@ a = 'foo' [case testMultiModuleAlias] import m, n m2, n2, (m3, n3) = m, n, [m, n] -reveal_type(m2.a) # E: Revealed type is 'builtins.str' -reveal_type(n2.b) # E: Revealed type is 'builtins.str' -reveal_type(m3.a) # E: Revealed type is 'builtins.str' -reveal_type(n3.b) # E: Revealed type is 'builtins.str' +reveal_type(m2.a) # N: Revealed type is 'builtins.str' +reveal_type(n2.b) # N: Revealed type is 'builtins.str' +reveal_type(m3.a) # N: Revealed type is 'builtins.str' +reveal_type(n3.b) # N: Revealed type is 'builtins.str' x, y = m # E: 'types.ModuleType' object is not iterable x, y, z = m, n # E: Need more than 2 values to unpack (3 expected) @@ -1697,13 +1697,13 @@ mod_mod3 = m # type: types.ModuleType mod_any: Any = m mod_int: int = m # E: Incompatible types in assignment (expression has type Module, variable has type "int") -reveal_type(mod_mod) # E: Revealed type is 'types.ModuleType' +reveal_type(mod_mod) # N: Revealed type is 'types.ModuleType' mod_mod.a # E: Module has no attribute "a" -reveal_type(mod_mod2) # E: Revealed type is 'types.ModuleType' +reveal_type(mod_mod2) # N: Revealed type is 'types.ModuleType' mod_mod2.a # E: Module has no attribute "a" -reveal_type(mod_mod3) # E: Revealed type is 'types.ModuleType' +reveal_type(mod_mod3) # N: Revealed type is 'types.ModuleType' mod_mod3.a # E: Module has no attribute "a" -reveal_type(mod_any) # E: Revealed type is 'Any' +reveal_type(mod_any) # N: Revealed type is 'Any' [file m.py] a = 'foo' @@ -1715,7 +1715,7 @@ import types import m def takes_module(x: types.ModuleType): - reveal_type(x.__file__) # E: Revealed type is 'builtins.str' + reveal_type(x.__file__) # N: Revealed type is 'builtins.str' n = m takes_module(m) @@ -1763,7 +1763,7 @@ else: x = n x.a # E: Module has no attribute "a" -reveal_type(x.__file__) # E: Revealed type is 'builtins.str' +reveal_type(x.__file__) # N: Revealed type is 'builtins.str' [file m.py] a = 'foo' @@ -1789,7 +1789,7 @@ if int(): xx = m if int(): xx = m -reveal_type(xx.a) # E: Revealed type is 'builtins.str' +reveal_type(xx.a) # N: Revealed type is 'builtins.str' [file m.py] a = 'foo' @@ -1817,9 +1817,9 @@ from stub import Iterable # E: Module 'stub' has no attribute 'Iterable' from stub import C c = C() -reveal_type(c.x) # E: Revealed type is 'builtins.int' +reveal_type(c.x) # N: Revealed type is 'builtins.int' it: Iterable[int] -reveal_type(it) # E: Revealed type is 'Any' +reveal_type(it) # N: Revealed type is 'Any' [file stub.pyi] from typing import Iterable @@ -1837,9 +1837,9 @@ class C: import stub c = stub.C() -reveal_type(c.x) # E: Revealed type is 'builtins.int' +reveal_type(c.x) # N: Revealed type is 'builtins.int' it: stub.Iterable[int] # E: Name 'stub.Iterable' is not defined -reveal_type(it) # E: Revealed type is 'Any' +reveal_type(it) # N: Revealed type is 'Any' [file stub.pyi] from typing import Iterable @@ -1856,8 +1856,8 @@ class C: [case testNoReExportFromStubsMemberVar] import stub -reveal_type(stub.y) # E: Revealed type is 'builtins.int' -reveal_type(stub.z) # E: Revealed type is 'Any' \ +reveal_type(stub.y) # N: Revealed type is 'builtins.int' +reveal_type(stub.z) # N: Revealed type is 'Any' \ # E: Module has no attribute "z" [file stub.pyi] @@ -1874,9 +1874,9 @@ z: int import mod from mod import submod -reveal_type(mod.x) # E: Revealed type is 'mod.submod.C' +reveal_type(mod.x) # N: Revealed type is 'mod.submod.C' y = submod.C() -reveal_type(y.a) # E: Revealed type is 'builtins.str' +reveal_type(y.a) # N: Revealed type is 'builtins.str' [file mod/__init__.pyi] from . import submod @@ -1892,7 +1892,7 @@ class C: import mod.submod y = mod.submod.C() -reveal_type(y.a) # E: Revealed type is 'builtins.str' +reveal_type(y.a) # N: Revealed type is 'builtins.str' [file mod/__init__.pyi] from . import submod @@ -1908,10 +1908,10 @@ class C: import mod from mod import C, D # E: Module 'mod' has no attribute 'C' -reveal_type(mod.x) # E: Revealed type is 'mod.submod.C' +reveal_type(mod.x) # N: Revealed type is 'mod.submod.C' mod.C # E: Module has no attribute "C" y = mod.D() -reveal_type(y.a) # E: Revealed type is 'builtins.str' +reveal_type(y.a) # N: Revealed type is 'builtins.str' [file mod/__init__.pyi] from .submod import C, D as D @@ -1937,7 +1937,7 @@ x = 42 [case testModuleAliasToQualifiedImport] import package.module alias = package.module -reveal_type(alias.whatever('/')) # E: Revealed type is 'builtins.str*' +reveal_type(alias.whatever('/')) # N: Revealed type is 'builtins.str*' [file package/__init__.py] [file package/module.py] @@ -1950,7 +1950,7 @@ def whatever(x: T) -> T: pass import mod import othermod alias = mod.submod -reveal_type(alias.whatever('/')) # E: Revealed type is 'builtins.str*' +reveal_type(alias.whatever('/')) # N: Revealed type is 'builtins.str*' if int(): alias = othermod # E: Cannot assign multiple modules to name 'alias' without explicit 'types.ModuleType' annotation [file mod.py] @@ -1966,7 +1966,7 @@ def whatever(x: T) -> T: pass [case testModuleLevelGetattr] import has_getattr -reveal_type(has_getattr.any_attribute) # E: Revealed type is 'Any' +reveal_type(has_getattr.any_attribute) # N: Revealed type is 'Any' [file has_getattr.pyi] from typing import Any @@ -1978,7 +1978,7 @@ def __getattr__(name: str) -> Any: ... [case testModuleLevelGetattrReturnType] import has_getattr -reveal_type(has_getattr.any_attribute) # E: Revealed type is 'builtins.str' +reveal_type(has_getattr.any_attribute) # N: Revealed type is 'builtins.str' [file has_getattr.pyi] def __getattr__(name: str) -> str: ... @@ -1995,7 +1995,7 @@ def __getattr__(x: int, y: str) -> str: ... [out] tmp/has_getattr.pyi:1: error: Invalid signature "def (builtins.int, builtins.str) -> builtins.str" for "__getattr__" -main:3: error: Revealed type is 'builtins.str' +main:3: note: Revealed type is 'builtins.str' [builtins fixtures/module.pyi] @@ -2009,13 +2009,13 @@ __getattr__ = 3 [out] tmp/has_getattr.pyi:1: error: Invalid signature "builtins.int" for "__getattr__" -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' [builtins fixtures/module.pyi] [case testModuleLevelGetattrUntyped] import has_getattr -reveal_type(has_getattr.any_attribute) # E: Revealed type is 'Any' +reveal_type(has_getattr.any_attribute) # N: Revealed type is 'Any' [file has_getattr.pyi] def __getattr__(name): ... @@ -2025,7 +2025,7 @@ def __getattr__(name): ... [case testModuleLevelGetattrNotStub36] # flags: --python-version 3.6 import has_getattr -reveal_type(has_getattr.any_attribute) # E: Revealed type is 'Any' # E: Module has no attribute "any_attribute" +reveal_type(has_getattr.any_attribute) # N: Revealed type is 'Any' # E: Module has no attribute "any_attribute" [file has_getattr.py] def __getattr__(name) -> str: ... @@ -2036,7 +2036,7 @@ def __getattr__(name) -> str: ... # flags: --python-version 3.7 import has_getattr -reveal_type(has_getattr.any_attribute) # E: Revealed type is 'builtins.str' +reveal_type(has_getattr.any_attribute) # N: Revealed type is 'builtins.str' [file has_getattr.py] def __getattr__(name) -> str: ... @@ -2049,7 +2049,7 @@ def __getattribute__(): ... # E: __getattribute__ is not valid at the module le [case testModuleLevelGetattrImportFrom] from has_attr import name -reveal_type(name) # E: Revealed type is 'Any' +reveal_type(name) # N: Revealed type is 'Any' [file has_attr.pyi] from typing import Any @@ -2059,7 +2059,7 @@ def __getattr__(name: str) -> Any: ... [case testModuleLevelGetattrImportFromRetType] from has_attr import int_attr -reveal_type(int_attr) # E: Revealed type is 'builtins.int' +reveal_type(int_attr) # N: Revealed type is 'builtins.int' [file has_attr.pyi] def __getattr__(name: str) -> int: ... @@ -2069,7 +2069,7 @@ def __getattr__(name: str) -> int: ... [case testModuleLevelGetattrImportFromNotStub36] # flags: --python-version 3.6 from non_stub import name # E: Module 'non_stub' has no attribute 'name' -reveal_type(name) # E: Revealed type is 'Any' +reveal_type(name) # N: Revealed type is 'Any' [file non_stub.py] from typing import Any @@ -2080,7 +2080,7 @@ def __getattr__(name: str) -> Any: ... [case testModuleLevelGetattrImportFromNotStub37] # flags: --python-version 3.7 from non_stub import name -reveal_type(name) # E: Revealed type is 'Any' +reveal_type(name) # N: Revealed type is 'Any' [file non_stub.py] from typing import Any @@ -2090,8 +2090,8 @@ def __getattr__(name: str) -> Any: ... [case testModuleLevelGetattrImportFromAs] from has_attr import name as n -reveal_type(name) # E: Revealed type is 'Any' # E: Name 'name' is not defined -reveal_type(n) # E: Revealed type is 'Any' +reveal_type(name) # N: Revealed type is 'Any' # E: Name 'name' is not defined +reveal_type(n) # N: Revealed type is 'Any' [file has_attr.pyi] from typing import Any @@ -2105,7 +2105,7 @@ from has_attr import name from has_attr import name from has_attr import x from has_attr import y as x # E: Name 'x' already defined (possibly by an import) -reveal_type(name) # E: Revealed type is 'builtins.int' +reveal_type(name) # N: Revealed type is 'builtins.int' [file has_attr.pyi] from typing import Any @@ -2115,7 +2115,7 @@ def __getattr__(name: str) -> int: ... [case testModuleLevelGetattrAssignedGood] # flags: --python-version 3.7 import non_stub -reveal_type(non_stub.name) # E: Revealed type is 'builtins.int' +reveal_type(non_stub.name) # N: Revealed type is 'builtins.int' [file non_stub.py] from typing import Callable @@ -2136,12 +2136,12 @@ __getattr__ = make_getattr_bad() [out] tmp/non_stub.py:4: error: Invalid signature "def () -> builtins.int" for "__getattr__" -main:3: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' [case testModuleLevelGetattrImportedGood] # flags: --python-version 3.7 import non_stub -reveal_type(non_stub.name) # E: Revealed type is 'builtins.int' +reveal_type(non_stub.name) # N: Revealed type is 'builtins.int' [file non_stub.py] from has_getattr import __getattr__ @@ -2162,7 +2162,7 @@ def __getattr__() -> int: ... [out] tmp/has_getattr.py:1: error: Invalid signature "def () -> builtins.int" for "__getattr__" -main:3: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' [builtins fixtures/module.pyi] @@ -2187,7 +2187,7 @@ from c import x from c import y from a import x def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file c.py] x = str() y = int() @@ -2198,7 +2198,7 @@ import a from c import y from b import x def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file b.py] from a import f from c import x @@ -2216,7 +2216,7 @@ from p.c import x from p.c import y from p.a import x def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file p/c.py] x = str() y = int() @@ -2232,7 +2232,7 @@ from p.c import x from p.c import y from p.a import x def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file p/c.py] x = str() y = int() @@ -2241,14 +2241,14 @@ y = int() # TODO: This fails because of missing ImportedName handling in # mypy.typeanal.TypeAnalyser.visit_unbound_type. x: List[int] -reveal_type(x) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(x) # N: Revealed type is 'builtins.list[builtins.int]' def f() -> 'List[int]': pass -reveal_type(f) # E: Revealed type is 'def () -> builtins.list[builtins.int]' +reveal_type(f) # N: Revealed type is 'def () -> builtins.list[builtins.int]' class A: y: 'List[str]' def g(self, x: 'List[int]') -> None: pass -reveal_type(A().y) # E: Revealed type is 'builtins.list[builtins.str]' -reveal_type(A().g) # E: Revealed type is 'def (x: builtins.list[builtins.int])' +reveal_type(A().y) # N: Revealed type is 'builtins.list[builtins.str]' +reveal_type(A().g) # N: Revealed type is 'def (x: builtins.list[builtins.int])' from typing import List [builtins fixtures/list.pyi] @@ -2261,7 +2261,7 @@ from c import x from c import y from a import * def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file c.py] x = str() y = int() @@ -2272,7 +2272,7 @@ import a from c import y from b import * def f() -> None: pass -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [file b.py] from a import f from c import x @@ -2410,7 +2410,7 @@ from c import B [file b.py] from c import y class A(B): pass -reveal_type(A().x) # E: Revealed type is 'builtins.str' +reveal_type(A().x) # N: Revealed type is 'builtins.str' from a import B def f() -> None: pass [file c.py] @@ -2441,11 +2441,11 @@ y: Two y = x x = y [out] -tmp/m/two.py:2: error: Revealed type is 'def () -> m.one.One' -tmp/m/two.py:4: error: Revealed type is 'm.one.One' +tmp/m/two.py:2: note: Revealed type is 'def () -> m.one.One' +tmp/m/two.py:4: note: Revealed type is 'm.one.One' tmp/m/two.py:9: error: Incompatible types in assignment (expression has type "One", variable has type "Two") -tmp/m/__init__.py:3: error: Revealed type is 'def () -> m.one.One' -main:2: error: Revealed type is 'def () -> m.one.One' +tmp/m/__init__.py:3: note: Revealed type is 'def () -> m.one.One' +main:2: note: Revealed type is 'def () -> m.one.One' [case testImportReExportInCycleUsingRelativeImport2] from m import One @@ -2465,10 +2465,10 @@ reveal_type(x) class Two: pass [out] -tmp/m/two.py:2: error: Revealed type is 'def () -> m.one.One' -tmp/m/two.py:4: error: Revealed type is 'm.one.One' -tmp/m/__init__.py:3: error: Revealed type is 'def () -> m.one.One' -main:2: error: Revealed type is 'def () -> m.one.One' +tmp/m/two.py:2: note: Revealed type is 'def () -> m.one.One' +tmp/m/two.py:4: note: Revealed type is 'm.one.One' +tmp/m/__init__.py:3: note: Revealed type is 'def () -> m.one.One' +main:2: note: Revealed type is 'def () -> m.one.One' [case testImportReExportedNamedTupleInCycle1] from m import One @@ -2486,7 +2486,7 @@ reveal_type(x.name) class Two: pass [out] -tmp/m/two.py:3: error: Revealed type is 'builtins.str' +tmp/m/two.py:3: note: Revealed type is 'builtins.str' [case testImportReExportedNamedTupleInCycle2] from m import One @@ -2503,7 +2503,7 @@ reveal_type(x.name) class Two: pass [out] -tmp/m/two.py:3: error: Revealed type is 'builtins.str' +tmp/m/two.py:3: note: Revealed type is 'builtins.str' [case testImportReExportedTypeAliasInCycle] from m import One @@ -2520,7 +2520,7 @@ reveal_type(x) class Two: pass [out] -tmp/m/two.py:3: error: Revealed type is 'Union[builtins.int, builtins.str]' +tmp/m/two.py:3: note: Revealed type is 'Union[builtins.int, builtins.str]' [case testImportCycleSpecialCase] import p @@ -2538,8 +2538,8 @@ def run() -> None: reveal_type(p.a.foo()) [builtins fixtures/module.pyi] [out] -tmp/p/b.py:4: error: Revealed type is 'builtins.int' -tmp/p/__init__.py:3: error: Revealed type is 'builtins.int' +tmp/p/b.py:4: note: Revealed type is 'builtins.int' +tmp/p/__init__.py:3: note: Revealed type is 'builtins.int' [case testMissingSubmoduleImportedWithIgnoreMissingImports] # flags: --ignore-missing-imports @@ -2578,7 +2578,7 @@ y = a.b.c.d.f() [case testModuleGetattrBusted] from a import A x: A -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' [file a.pyi] from typing import Any def __getattr__(attr: str) -> Any: ... @@ -2588,7 +2588,7 @@ def __getattr__(attr: str) -> Any: ... [case testModuleGetattrBusted2] from a import A def f(x: A.B) -> None: ... -reveal_type(f) # E: Revealed type is 'def (x: Any)' +reveal_type(f) # N: Revealed type is 'def (x: Any)' [file a.pyi] from typing import Any def __getattr__(attr: str) -> Any: ... @@ -2598,7 +2598,7 @@ def __getattr__(attr: str) -> Any: ... [case testNoGetattrInterference] import testmod as t def f(x: t.Cls) -> None: - reveal_type(x) # E: Revealed type is 'testmod.Cls' + reveal_type(x) # N: Revealed type is 'testmod.Cls' [file testmod.pyi] from typing import Any def __getattr__(attr: str) -> Any: ... @@ -2635,7 +2635,7 @@ main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missin [case testNamespacePackage] # flags: --namespace-packages from foo.bar import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file foo/bar.py] x = 0 @@ -2644,9 +2644,9 @@ x = 0 from foo.bax import x from foo.bay import y from foo.baz import z -reveal_type(x) # E: Revealed type is 'builtins.int' -reveal_type(y) # E: Revealed type is 'builtins.int' -reveal_type(z) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.int' +reveal_type(z) # N: Revealed type is 'builtins.int' [file xx/foo/bax.py] x = 0 [file yy/foo/bay.py] @@ -2660,7 +2660,7 @@ mypy_path = tmp/xx, tmp/yy [case testClassicPackageIgnoresEarlierNamespacePackage] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar import y -reveal_type(y) # E: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.int' [file xx/foo/bar.py] x = '' [file yy/foo/bar.py] @@ -2673,7 +2673,7 @@ mypy_path = tmp/xx, tmp/yy [case testNamespacePackagePickFirstOnMypyPath] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file xx/foo/bar.py] x = 0 [file yy/foo/bar.py] @@ -2685,7 +2685,7 @@ mypy_path = tmp/xx, tmp/yy [case testNamespacePackageInsideClassicPackage] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar.baz import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file xx/foo/bar/baz.py] x = '' [file yy/foo/bar/baz.py] @@ -2698,7 +2698,7 @@ mypy_path = tmp/xx, tmp/yy [case testClassicPackageInsideNamespacePackage] # flags: --namespace-packages --config-file tmp/mypy.ini from foo.bar.baz.boo import x -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [file xx/foo/bar/baz/boo.py] x = '' [file xx/foo/bar/baz/__init__.py] @@ -2712,7 +2712,7 @@ mypy_path = tmp/xx, tmp/yy [case testNamespacePackagePlainImport] # flags: --namespace-packages import foo.bar.baz -reveal_type(foo.bar.baz.x) # E: Revealed type is 'builtins.int' +reveal_type(foo.bar.baz.x) # N: Revealed type is 'builtins.int' [file foo/bar/baz.py] x = 0 diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 62d712548b70..653adc0a0f11 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -327,7 +327,7 @@ from collections import namedtuple X = namedtuple('X', ['x', 'y']) x = None # type: X -reveal_type(x._asdict()) # E: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(x._asdict()) # N: Revealed type is 'builtins.dict[builtins.str, Any]' [builtins fixtures/dict.pyi] @@ -336,7 +336,7 @@ from collections import namedtuple X = namedtuple('X', ['x', 'y']) x = None # type: X -reveal_type(x._replace()) # E: Revealed type is 'Tuple[Any, Any, fallback=__main__.X]' +reveal_type(x._replace()) # N: Revealed type is 'Tuple[Any, Any, fallback=__main__.X]' x._replace(y=5) x._replace(x=3) x._replace(x=3, y=5) @@ -361,7 +361,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) x = None # type: X -reveal_type(x._replace()) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' +reveal_type(x._replace()) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' x._replace(x=5) x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str" @@ -369,12 +369,12 @@ x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "i 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]' +reveal_type(X._make([5, 'a'])) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected "Iterable[Any]" -- # FIX: not a proper class method -- x = None # type: X --- reveal_type(x._make([5, 'a'])) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' +-- reveal_type(x._make([5, 'a'])) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=__main__.X]' -- x._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected Iterable[Any] [builtins fixtures/list.pyi] @@ -383,15 +383,15 @@ X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; e from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type(X._fields) # E: Revealed type is 'Tuple[builtins.str, builtins.str]' +reveal_type(X._fields) # N: Revealed type is 'Tuple[builtins.str, builtins.str]' [case testNamedTupleSource] from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type(X._source) # E: Revealed type is 'builtins.str' +reveal_type(X._source) # N: Revealed type is 'builtins.str' x = None # type: X -reveal_type(x._source) # E: Revealed type is 'builtins.str' +reveal_type(x._source) # N: Revealed type is 'builtins.str' [case testNamedTupleUnit] from typing import NamedTuple @@ -406,7 +406,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) Y = NamedTuple('Y', [('x', int), ('y', str)]) -reveal_type([X(3, 'b'), Y(1, 'a')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' [builtins fixtures/list.pyi] @@ -414,8 +414,8 @@ reveal_type([X(3, 'b'), Y(1, 'a')]) # E: Revealed type is 'builtins.list[Tuple[ from typing import NamedTuple, Tuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type([(3, 'b'), X(1, 'a')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' -reveal_type([X(1, 'a'), (3, 'b')]) # E: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' +reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is 'builtins.list[Tuple[builtins.int, builtins.str]]' [builtins fixtures/list.pyi] @@ -423,9 +423,9 @@ reveal_type([X(1, 'a'), (3, 'b')]) # E: Revealed type is 'builtins.list[Tuple[b from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type(X._field_types) # E: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(X._field_types) # N: Revealed type is 'builtins.dict[builtins.str, Any]' x = None # type: X -reveal_type(x._field_types) # E: Revealed type is 'builtins.dict[builtins.str, Any]' +reveal_type(x._field_types) # N: Revealed type is 'builtins.dict[builtins.str, Any]' [builtins fixtures/dict.pyi] @@ -473,27 +473,27 @@ a = B('').member() [case testNamedTupleSelfTypeReplace] from typing import NamedTuple, TypeVar A = NamedTuple('A', [('x', str)]) -reveal_type(A('hello')._replace(x='')) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.A]' +reveal_type(A('hello')._replace(x='')) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.A]' a = None # type: A a = A('hello')._replace(x='') class B(A): pass -reveal_type(B('hello')._replace(x='')) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.B]' +reveal_type(B('hello')._replace(x='')) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.B]' b = None # type: B b = B('hello')._replace(x='') [case testNamedTupleSelfTypeMake] from typing import NamedTuple, TypeVar A = NamedTuple('A', [('x', str)]) -reveal_type(A._make([''])) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.A]' +reveal_type(A._make([''])) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.A]' a = A._make(['']) # type: A class B(A): pass -reveal_type(B._make([''])) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.B]' +reveal_type(B._make([''])) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.B]' b = B._make(['']) # type: B [builtins fixtures/list.pyi] @@ -528,8 +528,8 @@ class G(Generic[T]): yb: G[int] # E: Type argument "builtins.int" of "G" must be a subtype of "Tuple[builtins.int, fallback=__main__.M]" yg: G[M] -reveal_type(G[M]().x.x) # E: Revealed type is 'builtins.int' -reveal_type(G[M]().x[0]) # E: Revealed type is 'builtins.int' +reveal_type(G[M]().x.x) # N: Revealed type is 'builtins.int' +reveal_type(G[M]().x[0]) # N: Revealed type is 'builtins.int' M = NamedTuple('M', [('x', int)]) [out] @@ -551,8 +551,8 @@ def f(x: a.X) -> None: x = a.X(1) reveal_type(x) [out] -tmp/b.py:4: error: Revealed type is 'Tuple[Any, fallback=a.X]' -tmp/b.py:6: error: Revealed type is 'Tuple[Any, fallback=a.X]' +tmp/b.py:4: note: Revealed type is 'Tuple[Any, fallback=a.X]' +tmp/b.py:6: note: Revealed type is 'Tuple[Any, fallback=a.X]' [case testNamedTupleWithImportCycle2] import a @@ -570,8 +570,8 @@ def f(x: a.N) -> None: x = a.N(1) reveal_type(x) [out] -tmp/b.py:4: error: Revealed type is 'Tuple[Any, fallback=a.N]' -tmp/b.py:7: error: Revealed type is 'Tuple[Any, fallback=a.N]' +tmp/b.py:4: note: Revealed type is 'Tuple[Any, fallback=a.N]' +tmp/b.py:7: note: Revealed type is 'Tuple[Any, fallback=a.N]' [case testSimpleSelfReferentialNamedTuple] # flags: --no-new-semantic-analyzer @@ -586,7 +586,7 @@ x: MyNamedTuple reveal_type(x.parent) [out] main:3: error: Recursive types not fully supported yet, nested types replaced with "Any" -main:10: error: Revealed type is 'Tuple[Any, fallback=__main__.MyNamedTuple]' +main:10: note: Revealed type is 'Tuple[Any, fallback=__main__.MyNamedTuple]' -- Some crazy self-referential named tuples and types dicts -- to be sure that everything works @@ -621,7 +621,7 @@ Node = NamedTuple('Node', [ # E: Recursive types not fully supported yet, nested ('children', Tuple['Node', ...]), ]) n: Node -reveal_type(n) # E: Revealed type is 'Tuple[builtins.str, builtins.tuple[Tuple[builtins.str, builtins.tuple[Any], fallback=__main__.Node]], fallback=__main__.Node]' +reveal_type(n) # N: Revealed type is 'Tuple[builtins.str, builtins.tuple[Tuple[builtins.str, builtins.tuple[Any], fallback=__main__.Node]], fallback=__main__.Node]' [builtins fixtures/tuple.pyi] @@ -638,7 +638,7 @@ class B(NamedTuple): # E y: int n: A -reveal_type(n) # E: Revealed type is 'Tuple[builtins.str, builtins.tuple[Tuple[Tuple[builtins.str, builtins.tuple[Any], fallback=__main__.A], builtins.int, fallback=__main__.B]], fallback=__main__.A]' +reveal_type(n) # N: Revealed type is 'Tuple[builtins.str, builtins.tuple[Tuple[Tuple[builtins.str, builtins.tuple[Any], fallback=__main__.A], builtins.int, fallback=__main__.B]], fallback=__main__.A]' [builtins fixtures/tuple.pyi] [out] main:4: error: Recursive types not fully supported yet, nested types replaced with "Any" @@ -658,10 +658,10 @@ A = NamedTuple('A', [ # E: Recursive types not fully supported yet, nested types ]) n: B m: A -reveal_type(n.x) # E: Revealed type is 'Tuple[Tuple[builtins.str, Tuple[Tuple[Any, builtins.int], builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int]' -reveal_type(m[0]) # E: Revealed type is 'builtins.str' +reveal_type(n.x) # N: Revealed type is 'Tuple[Tuple[builtins.str, Tuple[Tuple[Any, builtins.int], builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int]' +reveal_type(m[0]) # N: Revealed type is 'builtins.str' lst = [m, n] -reveal_type(lst[0]) # E: Revealed type is 'Tuple[builtins.object, builtins.object]' +reveal_type(lst[0]) # N: Revealed type is 'Tuple[builtins.object, builtins.object]' [builtins fixtures/tuple.pyi] [out] main:4: error: Recursive types not fully supported yet, nested types replaced with "Any" @@ -679,7 +679,7 @@ class A(NamedTuple): # E y: B n: A -reveal_type(n.y[0]) # E: Revealed type is 'Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A]' +reveal_type(n.y[0]) # N: Revealed type is 'Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A]' [builtins fixtures/tuple.pyi] [out] main:4: error: Recursive types not fully supported yet, nested types replaced with "Any" @@ -699,8 +699,8 @@ A = NamedTuple('A', [ # E: Recursive types not fully supported yet, nested types ]) n: A def f(m: B) -> None: pass -reveal_type(n) # E: Revealed type is 'Tuple[builtins.str, Tuple[Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int, fallback=__main__.B], fallback=__main__.A]' -reveal_type(f) # E: Revealed type is 'def (m: Tuple[Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int, fallback=__main__.B])' +reveal_type(n) # N: Revealed type is 'Tuple[builtins.str, Tuple[Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int, fallback=__main__.B], fallback=__main__.A]' +reveal_type(f) # N: Revealed type is 'def (m: Tuple[Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B], fallback=__main__.A], builtins.int, fallback=__main__.B])' [builtins fixtures/tuple.pyi] [case testRecursiveNamedTupleInBases] @@ -712,7 +712,7 @@ class A(NamedTuple('A', [('attr', List[Exp])])): pass class B(NamedTuple('B', [('val', object)])): pass def my_eval(exp: Exp) -> int: - reveal_type(exp) # E: Revealed type is 'Union[Tuple[builtins.list[Any], fallback=__main__.A], Tuple[builtins.object, fallback=__main__.B]]' + reveal_type(exp) # N: Revealed type is 'Union[Tuple[builtins.list[Any], fallback=__main__.A], Tuple[builtins.object, fallback=__main__.B]]' if isinstance(exp, A): my_eval(exp[0][0]) return my_eval(exp.attr[0]) @@ -732,9 +732,9 @@ class C: from b import tp x: tp -reveal_type(x.x) # E: Revealed type is 'builtins.int' +reveal_type(x.x) # N: Revealed type is 'builtins.int' -reveal_type(tp) # E: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=b.tp]' +reveal_type(tp) # N: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=b.tp]' tp('x') # E: Argument 1 to "tp" has incompatible type "str"; expected "int" [file b.py] @@ -755,7 +755,7 @@ class HelpCommand(Command): pass hc = HelpCommand(subcommands=[]) -reveal_type(hc) # E: Revealed type is 'Tuple[builtins.list[Tuple[builtins.list[Any], fallback=__main__.Command]], fallback=__main__.HelpCommand]' +reveal_type(hc) # N: Revealed type is 'Tuple[builtins.list[Tuple[builtins.list[Any], fallback=__main__.Command]], fallback=__main__.HelpCommand]' [builtins fixtures/list.pyi] [out] @@ -813,7 +813,7 @@ class MyTuple(BaseTuple, Base): def f(o: Base) -> None: if isinstance(o, MyTuple): - reveal_type(o.value) # E: Revealed type is 'builtins.float' + reveal_type(o.value) # N: Revealed type is 'builtins.float' [builtins fixtures/isinstance.pyi] [out] @@ -844,7 +844,7 @@ class Parent(NamedTuple): class Child(Parent): pass -reveal_type(Child.class_method()) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.Child]' +reveal_type(Child.class_method()) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.Child]' [builtins fixtures/classmethod.pyi] [case testNamedTupleAsConditionalStrictOptionalDisabled] diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 1242f6119622..528304cb3cb5 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -46,7 +46,7 @@ y() # E: "B" not callable import a class B: pass x: a.A -reveal_type(x) # E: Revealed type is 'a.A' +reveal_type(x) # N: Revealed type is 'a.A' [case testNewAnalyzerTypeAnnotationCycle2] import a @@ -88,7 +88,7 @@ _ = d _e = e _f = f # E: Name 'f' is not defined _ = _g # E: Name '_g' is not defined -reveal_type(_e) # E: Revealed type is 'm.A' +reveal_type(_e) # N: Revealed type is 'm.A' [file m.py] __all__ = ['a'] __all__ += ('b',) @@ -124,7 +124,7 @@ class A: [case testNewAnalyzerFunctionForwardRef] def f() -> None: x = g(1) # E: Argument 1 to "g" has incompatible type "int"; expected "str" - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' def g(x: str) -> str: return x @@ -138,7 +138,7 @@ from b import b2 as a3 def a1() -> int: pass -reveal_type(a3()) # E: Revealed type is 'builtins.int' +reveal_type(a3()) # N: Revealed type is 'builtins.int' [file b.py] from a import a1 as b2 @@ -146,11 +146,11 @@ from a import a2 as b3 def b1() -> str: pass -reveal_type(b3()) # E: Revealed type is 'builtins.str' +reveal_type(b3()) # N: Revealed type is 'builtins.str' [case testNewAnalyzerBool] -reveal_type(True) # E: Revealed type is 'builtins.bool' -reveal_type(False) # E: Revealed type is 'builtins.bool' +reveal_type(True) # N: Revealed type is 'builtins.bool' +reveal_type(False) # N: Revealed type is 'builtins.bool' [case testNewAnalyzerNewTypeMultiplePasses] import b @@ -211,10 +211,10 @@ class D(b.C): d: int d = D() -reveal_type(d.a) # E: Revealed type is 'builtins.int' -reveal_type(d.b) # E: Revealed type is 'builtins.int' -reveal_type(d.c) # E: Revealed type is 'builtins.int' -reveal_type(d.d) # E: Revealed type is 'builtins.int' +reveal_type(d.a) # N: Revealed type is 'builtins.int' +reveal_type(d.b) # N: Revealed type is 'builtins.int' +reveal_type(d.c) # N: Revealed type is 'builtins.int' +reveal_type(d.d) # N: Revealed type is 'builtins.int' [file b.py] from a import B @@ -245,8 +245,8 @@ from a import TypedDict as TD1 from a import TD2 as TD3 [out] -tmp/a.py:5: error: Revealed type is 'TypedDict('a.T2', {'x': builtins.int})' -main:6: error: Revealed type is 'TypedDict('__main__.T1', {'x': __main__.A})' +tmp/a.py:5: note: Revealed type is 'TypedDict('a.T2', {'x': builtins.int})' +main:6: note: Revealed type is 'TypedDict('__main__.T1', {'x': __main__.A})' [case testNewAnalyzerTypedDictClassInheritance] @@ -268,9 +268,9 @@ class A: pass T2(x=0, y=0) # E: Incompatible types (expression has type "int", TypedDict item "x" has type "str") x: T2 -reveal_type(x) # E: Revealed type is 'TypedDict('__main__.T2', {'x': builtins.str, 'y': builtins.int})' +reveal_type(x) # N: Revealed type is 'TypedDict('__main__.T2', {'x': builtins.str, 'y': builtins.int})' y: T4 -reveal_type(y) # E: Revealed type is 'TypedDict('__main__.T4', {'x': builtins.str, 'y': __main__.A})' +reveal_type(y) # N: Revealed type is 'TypedDict('__main__.T4', {'x': builtins.str, 'y': __main__.A})' [case testNewAnalyzerRedefinitionAndDeferral] import a @@ -280,15 +280,15 @@ from b import x as y x = 0 def y(): pass # E: Name 'y' already defined on line 2 -reveal_type(y) # E: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.int' y2 = y class y2: pass # E: Name 'y2' already defined on line 7 -reveal_type(y2) # E: Revealed type is 'builtins.int' +reveal_type(y2) # N: Revealed type is 'builtins.int' y3, y4 = y, y from b import f as y3 # E: Incompatible import of "y3" (imported name has type "Callable[[], Any]", local name has type "int") -reveal_type(y3) # E: Revealed type is 'builtins.int' +reveal_type(y3) # N: Revealed type is 'builtins.int' [file b.py] from a import x @@ -315,7 +315,7 @@ def f(): pass a, *b = g() class b(): pass # E: Name 'b' already defined on line 4 -reveal_type(b) # E: Revealed type is 'Any' +reveal_type(b) # N: Revealed type is 'Any' [file b.py] from a import f @@ -325,7 +325,7 @@ import a [file a.py] x: A -reveal_type(x) # E: Revealed type is 'b.A' +reveal_type(x) # N: Revealed type is 'b.A' from b import * @@ -342,16 +342,16 @@ def main() -> None: def __init__(self) -> None: self.x: A x() # E: "C" not callable - reveal_type(x.x) # E: Revealed type is '__main__.A@8' + reveal_type(x.x) # N: Revealed type is '__main__.A@8' class A: pass [case testNewAnalyzerMutuallyRecursiveFunctions] def main() -> None: def f() -> int: - reveal_type(g()) # E: Revealed type is 'builtins.str' + reveal_type(g()) # N: Revealed type is 'builtins.str' return int() def g() -> str: - reveal_type(f()) # E: Revealed type is 'builtins.int' + reveal_type(f()) # N: Revealed type is 'builtins.int' return str() [case testNewAnalyzerMissingNamesInFunctions] @@ -390,14 +390,14 @@ def main() -> None: @overload def f(x: str) -> str: ... def f(x: Union[int, str]) -> Union[int, str]: - reveal_type(g(str())) # E: Revealed type is 'builtins.str' + reveal_type(g(str())) # N: Revealed type is 'builtins.str' return x @overload def g(x: int) -> int: ... @overload def g(x: str) -> str: ... def g(x: Union[int, str]) -> Union[int, str]: - reveal_type(f(int())) # E: Revealed type is 'builtins.int' + reveal_type(f(int())) # N: Revealed type is 'builtins.int' return float() # E: Incompatible return value type (got "float", expected "Union[int, str]") [case testNewAnalyzerNestedClassInMethod] @@ -405,7 +405,7 @@ class C: class D: def meth(self) -> None: x: Out.In - reveal_type(x.t) # E: Revealed type is 'builtins.int' + reveal_type(x.t) # N: Revealed type is 'builtins.int' class Out: class In: def meth(self) -> None: @@ -416,7 +416,7 @@ class Out: class In: def meth(self) -> None: x: C.D - reveal_type(x.t) # E: Revealed type is '__main__.Test@10' + reveal_type(x.t) # N: Revealed type is '__main__.Test@10' class C: class D: def meth(self) -> None: @@ -424,10 +424,10 @@ class Out: class Test: def test(self) -> None: def one() -> int: - reveal_type(other()) # E: Revealed type is 'builtins.str' + reveal_type(other()) # N: Revealed type is 'builtins.str' return int() def other() -> str: - reveal_type(one()) # E: Revealed type is 'builtins.int' + reveal_type(one()) # N: Revealed type is 'builtins.int' return str() [case testNewAnalyzerNestedClass1] @@ -443,16 +443,16 @@ class A: b: A.B b = A.B('') # E: Argument 1 to "B" has incompatible type "str"; expected "int" -reveal_type(b) # E: Revealed type is '__main__.A.B' -reveal_type(b.x) # E: Revealed type is 'builtins.int' -reveal_type(b.f()) # E: Revealed type is 'builtins.str' +reveal_type(b) # N: Revealed type is '__main__.A.B' +reveal_type(b.x) # N: Revealed type is 'builtins.int' +reveal_type(b.f()) # N: Revealed type is 'builtins.str' [case testNewAnalyzerNestedClass2] b: A.B b = A.B('') # E: Argument 1 to "B" has incompatible type "str"; expected "int" -reveal_type(b) # E: Revealed type is '__main__.A.B' -reveal_type(b.x) # E: Revealed type is 'builtins.int' -reveal_type(b.f()) # E: Revealed type is 'builtins.str' +reveal_type(b) # N: Revealed type is '__main__.A.B' +reveal_type(b.x) # N: Revealed type is 'builtins.int' +reveal_type(b.f()) # N: Revealed type is 'builtins.str' class A: class B: @@ -471,9 +471,9 @@ c: C[int] c2: C[int, str] # E: "C" expects 1 type argument, but 2 given c3: C c = C('') # E: Argument 1 to "C" has incompatible type "str"; expected "int" -reveal_type(c.get()) # E: Revealed type is 'builtins.int*' -reveal_type(c2) # E: Revealed type is '__main__.C[Any]' -reveal_type(c3) # E: Revealed type is '__main__.C[Any]' +reveal_type(c.get()) # N: Revealed type is 'builtins.int*' +reveal_type(c2) # N: Revealed type is '__main__.C[Any]' +reveal_type(c3) # N: Revealed type is '__main__.C[Any]' T = TypeVar('T') @@ -497,9 +497,9 @@ class C(Generic[T]): T = TypeVar('T') c: C[int] -reveal_type(c) # E: Revealed type is '__main__.C[builtins.int]' +reveal_type(c) # N: Revealed type is '__main__.C[builtins.int]' c = C('') # E: Argument 1 to "C" has incompatible type "str"; expected "int" -reveal_type(c.get()) # E: Revealed type is 'builtins.int*' +reveal_type(c.get()) # N: Revealed type is 'builtins.int*' [case testNewAnalyzerTypeAlias] from typing import Union, TypeVar, Generic @@ -509,11 +509,11 @@ U = Union[C, int] G = D[T, C] c: C2 -reveal_type(c) # E: Revealed type is '__main__.C' +reveal_type(c) # N: Revealed type is '__main__.C' u: U -reveal_type(u) # E: Revealed type is 'Union[__main__.C, builtins.int]' +reveal_type(u) # N: Revealed type is 'Union[__main__.C, builtins.int]' g: G[int] -reveal_type(g) # E: Revealed type is '__main__.D[builtins.int, __main__.C]' +reveal_type(g) # N: Revealed type is '__main__.D[builtins.int, __main__.C]' class C: pass @@ -528,7 +528,7 @@ class C(D): pass A = Union[C, int] x: A -reveal_type(x) # E: Revealed type is 'Union[__main__.C, builtins.int]' +reveal_type(x) # N: Revealed type is 'Union[__main__.C, builtins.int]' class D: pass @@ -536,7 +536,7 @@ class D: pass from typing import List x: List[C] -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.C]' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.C]' class C: pass [builtins fixtures/list.pyi] @@ -625,7 +625,7 @@ def f2(x: int) -> int: return '' # E: Incompatible return value type (got "str", expected "int") f1(1) # E: Argument 1 to "f1" has incompatible type "int"; expected "str" -reveal_type(f1('')) # E: Revealed type is 'builtins.str' +reveal_type(f1('')) # N: Revealed type is 'builtins.str' f2(1) # E: Argument 1 to "f2" has incompatible type "int"; expected "str" [case testNewAnalyzerTypeVarForwardReference] @@ -704,8 +704,8 @@ def func(x: U) -> U: ... U = TypeVar('U', asdf, asdf) # E: Name 'asdf' is not defined T = TypeVar('T', bound=asdf) # E: Name 'asdf' is not defined -reveal_type(C) # E: Revealed type is 'def [T <: Any] (x: T`1) -> __main__.C[T`1]' -reveal_type(func) # E: Revealed type is 'def [U in (Any, Any)] (x: U`-1) -> U`-1' +reveal_type(C) # N: Revealed type is 'def [T <: Any] (x: T`1) -> __main__.C[T`1]' +reveal_type(func) # N: Revealed type is 'def [U in (Any, Any)] (x: U`-1) -> U`-1' [case testNewAnalyzerSubModuleInCycle] import a @@ -748,7 +748,7 @@ class E: pass def f(x: T) -> T: return x -reveal_type(f(D())) # E: Revealed type is '__main__.D*' +reveal_type(f(D())) # N: Revealed type is '__main__.D*' f(E()) # E: Value of type variable "T" of "f" cannot be "E" [case testNewAnalyzerNameExprRefersToIncompleteType] @@ -762,7 +762,7 @@ class D: pass [file b.py] from a import C -reveal_type(C()) # E: Revealed type is 'a.C' +reveal_type(C()) # N: Revealed type is 'a.C' def f(): pass [case testNewAnalyzerMemberExprRefersToIncompleteType] @@ -776,7 +776,7 @@ class D: pass [file b.py] import a -reveal_type(a.C()) # E: Revealed type is 'a.C' +reveal_type(a.C()) # N: Revealed type is 'a.C' def f(): pass [case testNewAnalyzerNamedTupleCall] @@ -787,11 +787,11 @@ i: In Out = NamedTuple('Out', [('x', In), ('y', Other)]) -reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' -reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' -reveal_type(o.y) # E: Revealed type is '__main__.Other' -reveal_type(o.x.t) # E: Revealed type is '__main__.Other' -reveal_type(i.t) # E: Revealed type is '__main__.Other' +reveal_type(o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' +reveal_type(o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' +reveal_type(o.y) # N: Revealed type is '__main__.Other' +reveal_type(o.x.t) # N: Revealed type is '__main__.Other' +reveal_type(i.t) # N: Revealed type is '__main__.Other' In = NamedTuple('In', [('s', str), ('t', Other)]) class Other: pass @@ -806,11 +806,11 @@ class Out(NamedTuple): x: In y: Other -reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' -reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' -reveal_type(o.y) # E: Revealed type is '__main__.Other' -reveal_type(o.x.t) # E: Revealed type is '__main__.Other' -reveal_type(i.t) # E: Revealed type is '__main__.Other' +reveal_type(o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' +reveal_type(o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' +reveal_type(o.y) # N: Revealed type is '__main__.Other' +reveal_type(o.x.t) # N: Revealed type is '__main__.Other' +reveal_type(i.t) # N: Revealed type is '__main__.Other' class In(NamedTuple): s: str @@ -823,11 +823,11 @@ from typing import NamedTuple o: C.Out i: C.In -reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]' -reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]' -reveal_type(o.y) # E: Revealed type is '__main__.C.Other' -reveal_type(o.x.t) # E: Revealed type is '__main__.C.Other' -reveal_type(i.t) # E: Revealed type is '__main__.C.Other' +reveal_type(o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]' +reveal_type(o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]' +reveal_type(o.y) # N: Revealed type is '__main__.C.Other' +reveal_type(o.x.t) # N: Revealed type is '__main__.C.Other' +reveal_type(i.t) # N: Revealed type is '__main__.C.Other' class C: In = NamedTuple('In', [('s', str), ('t', Other)]) @@ -841,11 +841,11 @@ from typing import NamedTuple o: C.Out i: C.In -reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]' -reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]' -reveal_type(o.y) # E: Revealed type is '__main__.C.Other' -reveal_type(o.x.t) # E: Revealed type is '__main__.C.Other' -reveal_type(i.t) # E: Revealed type is '__main__.C.Other' +reveal_type(o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]' +reveal_type(o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]' +reveal_type(o.y) # N: Revealed type is '__main__.C.Other' +reveal_type(o.x.t) # N: Revealed type is '__main__.C.Other' +reveal_type(i.t) # N: Revealed type is '__main__.C.Other' class C: class Out(NamedTuple): @@ -860,8 +860,8 @@ class C: from typing import NamedTuple c = C() -reveal_type(c.o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@11], __main__.Other@12, fallback=__main__.C.Out@10]' -reveal_type(c.o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@11]' +reveal_type(c.o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@11], __main__.Other@12, fallback=__main__.C.Out@10]' +reveal_type(c.o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@11]' class C: def get_tuple(self) -> None: @@ -874,9 +874,9 @@ class C: from typing import NamedTuple c = C() -reveal_type(c.o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15], __main__.Other@18, fallback=__main__.C.Out@11]' -reveal_type(c.o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15]' -reveal_type(c.o.method()) # E: Revealed type is 'Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15]' +reveal_type(c.o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15], __main__.Other@18, fallback=__main__.C.Out@11]' +reveal_type(c.o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15]' +reveal_type(c.o.method()) # N: Revealed type is 'Tuple[builtins.str, __main__.Other@18, fallback=__main__.C.In@15]' class C: def get_tuple(self) -> None: @@ -894,8 +894,8 @@ class C: from typing import NamedTuple n: NT -reveal_type(n.get_other()) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.Other]' -reveal_type(n.get_other().s) # E: Revealed type is 'builtins.str' +reveal_type(n.get_other()) # N: Revealed type is 'Tuple[builtins.str, fallback=__main__.Other]' +reveal_type(n.get_other().s) # N: Revealed type is 'builtins.str' class NT(NamedTuple): x: int @@ -910,8 +910,8 @@ from typing import NamedTuple o: SubO -reveal_type(SubO._make) # E: Revealed type is 'def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]' -reveal_type(o._replace(y=Other())) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]' +reveal_type(SubO._make) # N: Revealed type is 'def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]' +reveal_type(o._replace(y=Other())) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]' class SubO(Out): pass @@ -923,10 +923,10 @@ class Other: pass from typing import NamedTuple o: Out -reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' -reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' -reveal_type(o.x.t) # E: Revealed type is '__main__.Other' -reveal_type(Out._make) # E: Revealed type is 'def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' +reveal_type(o) # N: Revealed type is 'Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' +reveal_type(o.x) # N: Revealed type is 'Tuple[builtins.str, __main__.Other, fallback=__main__.In]' +reveal_type(o.x.t) # N: Revealed type is '__main__.Other' +reveal_type(Out._make) # N: Revealed type is 'def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]' class Out(NamedTuple('Out', [('x', In), ('y', Other)])): pass @@ -946,7 +946,7 @@ from b import C as int x: int[str] -reveal_type(x) # E: Revealed type is 'a.C[builtins.str]' +reveal_type(x) # N: Revealed type is 'a.C[builtins.str]' T = TypeVar('T') class C(Generic[T]): pass @@ -965,7 +965,7 @@ int = b.C class C: pass x: int -reveal_type(x) # E: Revealed type is 'b.C' +reveal_type(x) # N: Revealed type is 'b.C' [file b.py] import a @@ -975,7 +975,7 @@ int = a.C class C: pass x: int -reveal_type(x) # E: Revealed type is 'a.C' +reveal_type(x) # N: Revealed type is 'a.C' [case testNewAnalyzerNamespaceCompleteness] import a @@ -1032,10 +1032,10 @@ class B(type): def f(cls) -> int: return 0 -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' [case testNewAnalyzerMetaclass2] -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' class A(metaclass=B): pass @@ -1059,7 +1059,7 @@ class C(type): def f(cls) -> int: return 0 -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' [case testNewAnalyzerMetaclassSix1] import six @@ -1071,7 +1071,7 @@ class B(type): def f(cls) -> int: return 0 -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' [case testNewAnalyzerMetaclassSix2] import six @@ -1084,7 +1084,7 @@ class B(type): def f(cls) -> int: return 0 -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' [case testNewAnalyzerMetaclassSix3] import six @@ -1099,8 +1099,8 @@ class B(type): class Defer: x: str -reveal_type(A.f()) # E: Revealed type is 'builtins.int' -reveal_type(A.x) # E: Revealed type is 'builtins.str' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' +reveal_type(A.x) # N: Revealed type is 'builtins.str' [case testNewAnalyzerMetaclassSix4] import six @@ -1109,8 +1109,8 @@ class B(type): def f(cls) -> int: return 0 -reveal_type(A.f()) # E: Revealed type is 'builtins.int' -reveal_type(A.x) # E: Revealed type is 'builtins.str' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' +reveal_type(A.x) # N: Revealed type is 'builtins.str' class A(six.with_metaclass(B, Defer)): pass @@ -1122,7 +1122,7 @@ class Defer: class A: __metaclass__ = B -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' class B(type): def f(cls): @@ -1130,7 +1130,7 @@ class B(type): return 0 [case testNewAnalyzerMetaclass2_python2] -reveal_type(A.f()) # E: Revealed type is 'builtins.int' +reveal_type(A.f()) # N: Revealed type is 'builtins.int' class A: __metaclass__ = B @@ -1152,8 +1152,8 @@ x: Final = C() y: Final[C] = D() bad: Final[D] = C() # E: Incompatible types in assignment (expression has type "C", variable has type "D") -reveal_type(x) # E: Revealed type is '__main__.C' -reveal_type(y) # E: Revealed type is '__main__.C' +reveal_type(x) # N: Revealed type is '__main__.C' +reveal_type(y) # N: Revealed type is '__main__.C' class D(C): ... class C: ... @@ -1164,8 +1164,8 @@ class C: def __init__(self, x: D) -> None: self.x: Final = x self.y: Final[C] = E(D()) -reveal_type(C(D()).x) # E: Revealed type is '__main__.D' -reveal_type(C(D()).y) # E: Revealed type is '__main__.C' +reveal_type(C(D()).x) # N: Revealed type is '__main__.D' +reveal_type(C(D()).y) # N: Revealed type is '__main__.C' class D: ... class E(C): ... @@ -1244,7 +1244,7 @@ from a import x class B(List[B]): pass -reveal_type(x[0][0]) # E: Revealed type is 'b.B*' +reveal_type(x[0][0]) # N: Revealed type is 'b.B*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClass2] @@ -1255,7 +1255,7 @@ x: A class A(List[B]): pass B = A -reveal_type(x[0][0]) # E: Revealed type is '__main__.A*' +reveal_type(x[0][0]) # N: Revealed type is '__main__.A*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClass3] @@ -1266,7 +1266,7 @@ B = A A = C class C(List[B]): pass -reveal_type(x[0][0]) # E: Revealed type is '__main__.C*' +reveal_type(x[0][0]) # N: Revealed type is '__main__.C*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyNestedClass] @@ -1283,7 +1283,7 @@ from a import x class Out: class B(List[B]): pass -reveal_type(x[0][0]) # E: Revealed type is 'b.Out.B*' +reveal_type(x[0][0]) # N: Revealed type is 'b.Out.B*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyNestedClass2] @@ -1295,7 +1295,7 @@ class Out: class A(List[B]): pass B = Out.A -reveal_type(x[0][0]) # E: Revealed type is '__main__.Out.A*' +reveal_type(x[0][0]) # N: Revealed type is '__main__.Out.A*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClassGeneric] @@ -1312,7 +1312,7 @@ from a import x class B(List[B], Generic[T]): pass T = TypeVar('T') -reveal_type(x) # E: Revealed type is 'b.B[Tuple[builtins.int, builtins.int]]' +reveal_type(x) # N: Revealed type is 'b.B[Tuple[builtins.int, builtins.int]]' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClassInGeneric] @@ -1329,7 +1329,7 @@ from a import x class B(List[B]): pass -reveal_type(x) # E: Revealed type is 'Tuple[b.B, b.B]' +reveal_type(x) # N: Revealed type is 'Tuple[b.B, b.B]' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClassDoubleGeneric] @@ -1342,8 +1342,8 @@ B = A[List[T]] A = Union[int, T] class C(List[B[int]]): pass -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.list[builtins.int]]' -reveal_type(y[0]) # E: Revealed type is 'Union[builtins.int, builtins.list[builtins.int]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.list[builtins.int]]' +reveal_type(y[0]) # N: Revealed type is 'Union[builtins.int, builtins.list[builtins.int]]' y: C [builtins fixtures/list.pyi] @@ -1356,7 +1356,7 @@ class D: x: List[A] def test(self) -> None: - reveal_type(self.x[0].y) # E: Revealed type is 'builtins.int' + reveal_type(self.x[0].y) # N: Revealed type is 'builtins.int' class B: y: int @@ -1372,8 +1372,8 @@ B = List[C] A = C class C(List[A]): pass -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.C]' -reveal_type(x[0][0]) # E: Revealed type is '__main__.C*' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.C]' +reveal_type(x[0][0]) # N: Revealed type is '__main__.C*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyDirectBase] @@ -1383,8 +1383,8 @@ x: B B = List[C] class C(B): pass -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.C]' -reveal_type(x[0][0]) # E: Revealed type is '__main__.C*' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.C]' +reveal_type(x[0][0]) # N: Revealed type is '__main__.C*' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyTwoDeferralsFunction] @@ -1400,7 +1400,7 @@ class C(List[A]): pass [file b.py] from a import f class D: ... -reveal_type(f) # E: Revealed type is 'def (x: builtins.list[a.C]) -> builtins.list[builtins.list[a.C]]' +reveal_type(f) # N: Revealed type is 'def (x: builtins.list[a.C]) -> builtins.list[builtins.list[a.C]]' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyDirectBaseFunction] @@ -1416,7 +1416,7 @@ class C(B): pass [file b.py] from a import f class D: ... -reveal_type(f) # E: Revealed type is 'def (x: builtins.list[a.C]) -> builtins.list[builtins.list[a.C]]' +reveal_type(f) # N: Revealed type is 'def (x: builtins.list[a.C]) -> builtins.list[builtins.list[a.C]]' [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyMixed] @@ -1428,8 +1428,8 @@ A = Union[B, C] class B(List[A]): pass class C(List[A]): pass -reveal_type(x) # E: Revealed type is 'Union[__main__.B, __main__.C]' -reveal_type(x[0]) # E: Revealed type is 'Union[__main__.B, __main__.C]' +reveal_type(x) # N: Revealed type is 'Union[__main__.B, __main__.C]' +reveal_type(x[0]) # N: Revealed type is 'Union[__main__.B, __main__.C]' [builtins fixtures/list.pyi] [case testNewAnalyzerTrickyAliasInFuncDef] @@ -1437,7 +1437,7 @@ import a [file a.py] from b import B def func() -> B: ... -reveal_type(func()) # E: Revealed type is 'builtins.list[Tuple[b.C, b.C]]' +reveal_type(func()) # N: Revealed type is 'builtins.list[Tuple[b.C, b.C]]' [file b.py] from typing import List, Tuple @@ -1624,7 +1624,7 @@ class A: class B: pass a = A() -reveal_type(a.x) # E: Revealed type is '__main__.B' +reveal_type(a.x) # N: Revealed type is '__main__.B' a.y = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "B") [builtins fixtures/property.pyi] @@ -1636,8 +1636,8 @@ def func(x: List[C[T]]) -> T: x: A A = List[C] -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.C[Any]]' -reveal_type(func(x)) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.C[Any]]' +reveal_type(func(x)) # N: Revealed type is 'Any' class C(Generic[T]): ... @@ -1653,8 +1653,8 @@ def func(x: List[C[T]]) -> T: x: A A = List[C[int, str]] # E: "C" expects 1 type argument, but 2 given -reveal_type(x) # E: Revealed type is 'builtins.list[__main__.C[Any]]' -reveal_type(func(x)) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'builtins.list[__main__.C[Any]]' +reveal_type(func(x)) # N: Revealed type is 'Any' class C(Generic[T]): ... @@ -1666,9 +1666,9 @@ from typing import List, Optional x: Optional[List] = None y: List[str] -reveal_type(x) # E: Revealed type is 'Union[builtins.list[Any], None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.list[Any], None]' x = ['a', 'b'] -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' x.extend(y) [builtins fixtures/list.pyi] @@ -1676,7 +1676,7 @@ x.extend(y) import b [file a.py] from b import x -reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' [file b.py] import a x = (1, 2) @@ -1685,7 +1685,7 @@ x = (1, 2) import a [file a.py] from b import x -reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' [file b.py] import a x = (1, 2) @@ -1705,7 +1705,7 @@ else: def f(x: int) -> None: ''() # E: "str" not callable -reveal_type(g) # E: Revealed type is 'def (x: builtins.int)' +reveal_type(g) # N: Revealed type is 'def (x: builtins.int)' [case testNewAnalyzerConditionalFuncDefer] if int(): @@ -1719,7 +1719,7 @@ else: def g(x: str) -> None: # E: All conditional function variants must have identical signatures pass -reveal_type(g) # E: Revealed type is 'def (x: __main__.A)' +reveal_type(g) # N: Revealed type is 'def (x: __main__.A)' class A: pass @@ -1735,7 +1735,7 @@ else: @dec def f(x: int) -> None: 1() # E: "int" not callable -reveal_type(f) # E: Revealed type is 'def (x: builtins.str)' +reveal_type(f) # N: Revealed type is 'def (x: builtins.str)' [file m.py] def f(x: str) -> None: pass @@ -1747,7 +1747,7 @@ if int(): else: def f(x: str) -> None: ... -reveal_type(f) # E: Revealed type is 'def (builtins.str)' +reveal_type(f) # N: Revealed type is 'def (builtins.str)' [case testNewAnalyzerConditionallyDefineFuncOverClass] class C: @@ -1774,18 +1774,18 @@ class NTStr(NamedTuple): y: str t1: T -reveal_type(t1.__iter__) # E: Revealed type is 'def () -> typing.Iterator[__main__.A*]' +reveal_type(t1.__iter__) # N: Revealed type is 'def () -> typing.Iterator[__main__.A*]' t2: NTInt -reveal_type(t2.__iter__) # E: Revealed type is 'def () -> typing.Iterator[builtins.int*]' +reveal_type(t2.__iter__) # N: Revealed type is 'def () -> typing.Iterator[builtins.int*]' nt: Union[NTInt, NTStr] -reveal_type(nt.__iter__) # E: Revealed type is 'Union[def () -> typing.Iterator[builtins.int*], def () -> typing.Iterator[builtins.str*]]' +reveal_type(nt.__iter__) # N: Revealed type is 'Union[def () -> typing.Iterator[builtins.int*], def () -> typing.Iterator[builtins.str*]]' for nx in nt: - reveal_type(nx) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(nx) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' t: Union[Tuple[int, int], Tuple[str, str]] for x in t: - reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [builtins fixtures/for.pyi] [out] @@ -1811,7 +1811,7 @@ class G(Generic[T]): pass t: Tuple[G[B], G[C]] # E: Type argument "__main__.B" of "G" must be a subtype of "__main__.A" \ # E: Type argument "__main__.C" of "G" must be a subtype of "__main__.A" -reveal_type(t.__iter__) # E: Revealed type is 'def () -> typing.Iterator[__main__.G*[__main__.B]]' +reveal_type(t.__iter__) # N: Revealed type is 'def () -> typing.Iterator[__main__.G*[__main__.B]]' [builtins fixtures/tuple.pyi] [case testNewAnalyzerClassKeywordsForward] @@ -1883,7 +1883,7 @@ class Meta(type): x = int() y = C.x -reveal_type(y) # E: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.int' class C(metaclass=Meta): pass @@ -1909,7 +1909,7 @@ A = NewType('A', str) # E: Cannot redefine 'A' as a NewType \ from typing import NewType, List x: C -reveal_type(x[0]) # E: Revealed type is '__main__.C*' +reveal_type(x[0]) # N: Revealed type is '__main__.C*' C = NewType('C', B) @@ -1921,7 +1921,7 @@ class B(List[C]): from typing import NewType, List x: D -reveal_type(x[0]) # E: Revealed type is '__main__.C*' +reveal_type(x[0]) # N: Revealed type is '__main__.C*' D = C C = NewType('C', B) @@ -1934,7 +1934,7 @@ class B(List[D]): from typing import NewType, List x: D -reveal_type(x[0][0]) # E: Revealed type is '__main__.C*' +reveal_type(x[0][0]) # N: Revealed type is '__main__.C*' D = C C = NewType('C', List[B]) @@ -1947,7 +1947,7 @@ class B(List[C]): from typing import NewType, List x: D -reveal_type(x[0][0]) # E: Revealed type is '__main__.C*' +reveal_type(x[0][0]) # N: Revealed type is '__main__.C*' D = List[C] C = NewType('C', B) @@ -1982,10 +1982,10 @@ class B(NamedTuple): x: int y: C -reveal_type(y.x) # E: Revealed type is 'builtins.int' -reveal_type(y[0]) # E: Revealed type is 'builtins.int' +reveal_type(y.x) # N: Revealed type is 'builtins.int' +reveal_type(y[0]) # N: Revealed type is 'builtins.int' x: A -reveal_type(x) # E: Revealed type is '__main__.G[Tuple[builtins.int, fallback=__main__.C]]' +reveal_type(x) # N: Revealed type is '__main__.G[Tuple[builtins.int, fallback=__main__.C]]' [builtins fixtures/list.pyi] [case testNewAnalyzerCastForward1] @@ -1996,8 +1996,8 @@ class A: def foo(self) -> None: self.x = cast('C', None) -reveal_type(x) # E: Revealed type is '__main__.C' -reveal_type(A().x) # E: Revealed type is '__main__.C' +reveal_type(x) # N: Revealed type is '__main__.C' +reveal_type(A().x) # N: Revealed type is '__main__.C' class C(A): ... @@ -2006,7 +2006,7 @@ from typing import cast x = cast('C', None) -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' C = int @@ -2015,8 +2015,8 @@ from typing import cast, NamedTuple x = cast('C', None) -reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.C]' -reveal_type(x.x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, fallback=__main__.C]' +reveal_type(x.x) # N: Revealed type is 'builtins.int' C = NamedTuple('C', [('x', int)]) @@ -2024,7 +2024,7 @@ C = NamedTuple('C', [('x', int)]) from typing import Generic, TypeVar x = C[int]() -reveal_type(x) # E: Revealed type is '__main__.C[builtins.int*]' +reveal_type(x) # N: Revealed type is '__main__.C[builtins.int*]' T = TypeVar('T') class C(Generic[T]): ... @@ -2036,7 +2036,7 @@ T = TypeVar('T') class C(Generic[T]): ... x = C['A']() -reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]' +reveal_type(x) # N: Revealed type is '__main__.C[__main__.A*]' class A: ... @@ -2044,7 +2044,7 @@ class A: ... from typing import Generic, TypeVar x = C[A]() -reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]' +reveal_type(x) # N: Revealed type is '__main__.C[__main__.A*]' T = TypeVar('T') class C(Generic[T]): ... @@ -2055,7 +2055,7 @@ class A: ... from typing import Generic, TypeVar x = C[A]() # E: Value of type variable "T" of "C" cannot be "A" -reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]' +reveal_type(x) # N: Revealed type is '__main__.C[__main__.A*]' T = TypeVar('T', bound='D') class C(Generic[T]): ... @@ -2090,14 +2090,14 @@ from pp import x as y [file pp.pyi] def __getattr__(attr): ... [out2] -tmp/a.py:2: error: Revealed type is 'Any' +tmp/a.py:2: note: Revealed type is 'Any' [case testNewAnanlyzerTrickyImportPackage] from lib import config import lib -reveal_type(lib.config.x) # E: Revealed type is 'builtins.int' -reveal_type(config.x) # E: Revealed type is 'builtins.int' +reveal_type(lib.config.x) # N: Revealed type is 'builtins.int' +reveal_type(config.x) # N: Revealed type is 'builtins.int' [file lib/__init__.py] from lib.config import config @@ -2113,7 +2113,7 @@ config = Config() import lib.config import lib.config as tmp -reveal_type(lib.config.x) # E: Revealed type is 'builtins.int' +reveal_type(lib.config.x) # N: Revealed type is 'builtins.int' # TODO: this actually doesn't match runtime behavior, variable wins. tmp.x # E: Module has no attribute "x" @@ -2151,8 +2151,8 @@ class Config: config = Config() [builtins fixtures/module.pyi] [out2] -tmp/a.py:4: error: Revealed type is 'builtins.int' -tmp/a.py:5: error: Revealed type is 'builtins.int' +tmp/a.py:4: note: Revealed type is 'builtins.int' +tmp/a.py:5: note: Revealed type is 'builtins.int' [case testNewAnalyzerRedefineAsClass] from typing import Any @@ -2189,7 +2189,7 @@ else: Alias = DummyTarget # type: ignore x: Alias -reveal_type(x.attr) # E: Revealed type is 'builtins.int' +reveal_type(x.attr) # N: Revealed type is 'builtins.int' class DesiredTarget: attr: int @@ -2237,7 +2237,7 @@ var1: Final = 1 def force1(x: Literal[1]) -> None: pass -force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]' +force1(reveal_type(var1)) # N: Revealed type is 'Literal[1]' [case testNewAnalyzerReportLoopInMRO] class A(A): ... # E: Cannot resolve name "A" (possible cyclic definition) @@ -2271,7 +2271,7 @@ def C(): pass import m x: m.n.C # E: Name 'm.n.C' is not defined -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' [file m.pyi] import n @@ -2321,17 +2321,17 @@ class C: class X: pass class C: X = X - reveal_type(X) # E: Revealed type is 'def () -> __main__.X' -reveal_type(C.X) # E: Revealed type is 'def () -> __main__.X' + reveal_type(X) # N: Revealed type is 'def () -> __main__.X' +reveal_type(C.X) # N: Revealed type is 'def () -> __main__.X' [case testNewAnalyzerShadowOuterDefinitionBasedOnOrderTwoPasses] c: C # Force second semantic analysis pass class X: pass class C: X = X - reveal_type(X) # E: Revealed type is 'def () -> __main__.X' + reveal_type(X) # N: Revealed type is 'def () -> __main__.X' -reveal_type(C.X) # E: Revealed type is 'def () -> __main__.X' +reveal_type(C.X) # N: Revealed type is 'def () -> __main__.X' [case testNewAnalyzerAnnotationConflictsWithAttributeSinglePass] class C: @@ -2351,10 +2351,10 @@ class C: zz: str # E: Invalid type "__main__.C.str" -reveal_type(C().x()) # E: Revealed type is 'builtins.int' -reveal_type(C().y()) # E: Revealed type is 'builtins.int' -reveal_type(C().z) # E: Revealed type is 'builtins.str' -reveal_type(C().str()) # E: Revealed type is 'builtins.str' +reveal_type(C().x()) # N: Revealed type is 'builtins.int' +reveal_type(C().y()) # N: Revealed type is 'builtins.int' +reveal_type(C().z) # N: Revealed type is 'builtins.str' +reveal_type(C().str()) # N: Revealed type is 'builtins.str' [case testNewAnalyzerAnnotationConflictsWithAttributeTwoPasses] c: C # Force second semantic analysis pass @@ -2376,10 +2376,10 @@ class C: zz: str # E: Invalid type "__main__.C.str" -reveal_type(C().x()) # E: Revealed type is 'builtins.int' -reveal_type(C().y()) # E: Revealed type is 'builtins.int' -reveal_type(C().z) # E: Revealed type is 'builtins.str' -reveal_type(C().str()) # E: Revealed type is 'builtins.str' +reveal_type(C().x()) # N: Revealed type is 'builtins.int' +reveal_type(C().y()) # N: Revealed type is 'builtins.int' +reveal_type(C().z) # N: Revealed type is 'builtins.str' +reveal_type(C().str()) # N: Revealed type is 'builtins.str' [case testNewAnalyzerNameConflictsAndMultiLineDefinition] c: C # Force second semantic analysis pass @@ -2394,8 +2394,8 @@ class C: ) -> str: return 0 # E: Incompatible return value type (got "int", expected "str") -reveal_type(C.X) # E: # E: Revealed type is 'def () -> __main__.X' -reveal_type(C().str()) # E: Revealed type is 'builtins.str' +reveal_type(C.X) # E: # N: Revealed type is 'def () -> __main__.X' +reveal_type(C().str()) # N: Revealed type is 'builtins.str' [case testNewAnalyzerNameNotDefinedYetInClassBody] class C: @@ -2406,7 +2406,7 @@ class C: def g(self) -> None: pass -reveal_type(C.X) # E: Revealed type is 'Any' +reveal_type(C.X) # N: Revealed type is 'Any' [case testNewAnalyzerImportedNameUsedInClassBody] import m @@ -2458,7 +2458,7 @@ class C(Generic[T]): C = C[int] # E: Cannot assign to a type \ # E: Incompatible types in assignment (expression has type "Type[__main__.C[Any]]", variable has type "Type[__main__.C[Any]]") x: C -reveal_type(x) # E: Revealed type is '__main__.C[Any]' +reveal_type(x) # N: Revealed type is '__main__.C[Any]' [out] [out2] @@ -2485,7 +2485,7 @@ from a import A class C: A = A # Initially rvalue will be a placeholder -reveal_type(C.A) # E: Revealed type is 'def () -> a.A' +reveal_type(C.A) # N: Revealed type is 'def () -> a.A' [case testNewAnalyzerFinalLiteralInferredAsLiteralWithDeferral] from typing_extensions import Final, Literal @@ -2494,14 +2494,14 @@ defer: Yes var: Final = 42 def force(x: Literal[42]) -> None: pass -force(reveal_type(var)) # E: Revealed type is 'Literal[42]' +force(reveal_type(var)) # N: Revealed type is 'Literal[42]' class Yes: ... [case testNewAnalyzerImportCycleWithIgnoreMissingImports] # flags: --ignore-missing-imports import p -reveal_type(p.get) # E: Revealed type is 'def () -> builtins.int' +reveal_type(p.get) # N: Revealed type is 'def () -> builtins.int' [file p/__init__.pyi] from . import api diff --git a/test-data/unit/check-newsyntax.test b/test-data/unit/check-newsyntax.test index 61a012b49f82..25269d8e9f9d 100644 --- a/test-data/unit/check-newsyntax.test +++ b/test-data/unit/check-newsyntax.test @@ -41,7 +41,7 @@ def tst_local(dct: Dict[int, T]) -> Dict[T, int]: ret: Dict[T, int] = {} return ret -reveal_type(tst_local({1: 'a'})) # E: Revealed type is 'builtins.dict[builtins.str*, builtins.int]' +reveal_type(tst_local({1: 'a'})) # N: Revealed type is 'builtins.dict[builtins.str*, builtins.int]' [builtins fixtures/dict.pyi] [out] @@ -148,6 +148,6 @@ f'result: {value:{width}.{precision}}' [case testNewSyntaxFStringSingleField] # flags: --python-version 3.6 v = 1 -reveal_type(f'{v}') # E: Revealed type is 'builtins.str' -reveal_type(f'{1}') # E: Revealed type is 'builtins.str' +reveal_type(f'{v}') # N: Revealed type is 'builtins.str' +reveal_type(f'{1}') # N: Revealed type is 'builtins.str' [builtins fixtures/f_string.pyi] diff --git a/test-data/unit/check-newtype.test b/test-data/unit/check-newtype.test index ea1a1c9a988a..c35610705104 100644 --- a/test-data/unit/check-newtype.test +++ b/test-data/unit/check-newtype.test @@ -17,8 +17,8 @@ name_by_id(UserId(42)) id = UserId(5) num = id + 1 -reveal_type(id) # E: Revealed type is '__main__.UserId' -reveal_type(num) # E: Revealed type is 'builtins.int' +reveal_type(id) # N: Revealed type is '__main__.UserId' +reveal_type(num) # N: Revealed type is 'builtins.int' [out] [case testNewTypePEP484Example2] @@ -45,8 +45,8 @@ TwoTuple = NewType('TwoTuple', Tuple[int, str]) a = TwoTuple((3, "a")) b = TwoTuple(("a", 3)) # E: Argument 1 to "TwoTuple" has incompatible type "Tuple[str, int]"; expected "Tuple[int, str]" -reveal_type(a[0]) # E: Revealed type is 'builtins.int' -reveal_type(a[1]) # E: Revealed type is 'builtins.str' +reveal_type(a[0]) # N: Revealed type is 'builtins.int' +reveal_type(a[1]) # N: Revealed type is 'builtins.str' [builtins fixtures/tuple.pyi] [out] @@ -65,9 +65,9 @@ foo.extend(IdList([UserId(1), UserId(2), UserId(3)])) bar = IdList([UserId(2)]) baz = foo + bar -reveal_type(foo) # E: Revealed type is '__main__.IdList' -reveal_type(bar) # E: Revealed type is '__main__.IdList' -reveal_type(baz) # E: Revealed type is 'builtins.list[__main__.UserId*]' +reveal_type(foo) # N: Revealed type is '__main__.IdList' +reveal_type(bar) # N: Revealed type is '__main__.IdList' +reveal_type(baz) # N: Revealed type is 'builtins.list[__main__.UserId*]' [builtins fixtures/list.pyi] [out] @@ -95,8 +95,8 @@ Derived2(Base('a')) Derived3(Base(1)) Derived3(Base('a')) -reveal_type(Derived1(Base('a')).getter()) # E: Revealed type is 'builtins.str*' -reveal_type(Derived3(Base('a')).getter()) # E: Revealed type is 'Any' +reveal_type(Derived1(Base('a')).getter()) # N: Revealed type is 'builtins.str*' +reveal_type(Derived3(Base('a')).getter()) # N: Revealed type is 'Any' [out] [case testNewTypeWithNamedTuple] @@ -106,14 +106,14 @@ from typing import NewType, NamedTuple Vector1 = namedtuple('Vector1', ['x', 'y']) Point1 = NewType('Point1', Vector1) p1 = Point1(Vector1(1, 2)) -reveal_type(p1.x) # E: Revealed type is 'Any' -reveal_type(p1.y) # E: Revealed type is 'Any' +reveal_type(p1.x) # N: Revealed type is 'Any' +reveal_type(p1.y) # N: Revealed type is 'Any' Vector2 = NamedTuple('Vector2', [('x', int), ('y', int)]) Point2 = NewType('Point2', Vector2) p2 = Point2(Vector2(1, 2)) -reveal_type(p2.x) # E: Revealed type is 'builtins.int' -reveal_type(p2.y) # E: Revealed type is 'builtins.int' +reveal_type(p2.x) # N: Revealed type is 'builtins.int' +reveal_type(p2.y) # N: Revealed type is 'builtins.int' class Vector3: def __init__(self, x: int, y: int) -> None: @@ -121,8 +121,8 @@ class Vector3: self.y = y Point3 = NewType('Point3', Vector3) p3 = Point3(Vector3(1, 3)) -reveal_type(p3.x) # E: Revealed type is 'builtins.int' -reveal_type(p3.y) # E: Revealed type is 'builtins.int' +reveal_type(p3.x) # N: Revealed type is 'builtins.int' +reveal_type(p3.y) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] @@ -259,8 +259,8 @@ reveal_type(num) [stale] [out1] [out2] -tmp/m.py:13: error: Revealed type is 'm.UserId' -tmp/m.py:14: error: Revealed type is 'builtins.int' +tmp/m.py:13: note: Revealed type is 'm.UserId' +tmp/m.py:14: note: Revealed type is 'builtins.int' -- Check misuses of NewType fail @@ -346,7 +346,7 @@ class D: C = NewType('C', P) # E: NewType cannot be used with protocol classes x: C = C(D()) # We still accept this, treating 'C' as non-protocol subclass. -reveal_type(x.attr) # E: Revealed type is 'builtins.int' +reveal_type(x.attr) # N: Revealed type is 'builtins.int' x.bad_attr # E: "C" has no attribute "bad_attr" C(1) # E: Argument 1 to "C" has incompatible type "int"; expected "P" [out] @@ -361,7 +361,7 @@ from typing import NewType T = NewType('T', int) d: object if isinstance(d, T): # E: Cannot use isinstance() with a NewType type - reveal_type(d) # E: Revealed type is '__main__.T' + reveal_type(d) # N: Revealed type is '__main__.T' issubclass(object, T) # E: Cannot use issubclass() with a NewType type [builtins fixtures/isinstancelist.pyi] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index dbcf54aca4bc..8f5313870e27 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -42,85 +42,85 @@ f(x) # E: Argument 1 to "f" has incompatible type "Optional[int]"; expected "in from typing import Optional x = None # type: Optional[int] if isinstance(x, int): - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' else: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' [builtins fixtures/isinstance.pyi] [case testIfCases] from typing import Optional x = None # type: Optional[int] if x: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/bool.pyi] [case testIfNotCases] from typing import Optional x = None # type: Optional[int] if not x: - reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' else: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/bool.pyi] [case testIsNotNoneCases] from typing import Optional x = None # type: Optional[int] if x is not None: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' else: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' [builtins fixtures/bool.pyi] [case testIsNoneCases] from typing import Optional x = None # type: Optional[int] if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' else: - reveal_type(x) # E: Revealed type is 'builtins.int' -reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/bool.pyi] [case testAnyCanBeNone] from typing import Optional, Any x = None # type: Any if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' else: - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' [builtins fixtures/bool.pyi] [case testOrCases] from typing import Optional x = None # type: Optional[str] y1 = x or 'a' -reveal_type(y1) # E: Revealed type is 'builtins.str' +reveal_type(y1) # N: Revealed type is 'builtins.str' y2 = x or 1 -reveal_type(y2) # E: Revealed type is 'Union[builtins.str, builtins.int]' +reveal_type(y2) # N: Revealed type is 'Union[builtins.str, builtins.int]' z1 = 'a' or x -reveal_type(z1) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(z1) # N: Revealed type is 'Union[builtins.str, None]' z2 = int() or x -reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, None]' +reveal_type(z2) # N: Revealed type is 'Union[builtins.int, builtins.str, None]' [case testAndCases] from typing import Optional x = None # type: Optional[str] y1 = x and 'b' -reveal_type(y1) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(y1) # N: Revealed type is 'Union[builtins.str, None]' y2 = x and 1 # x could be '', so... -reveal_type(y2) # E: Revealed type is 'Union[builtins.str, None, builtins.int]' +reveal_type(y2) # N: Revealed type is 'Union[builtins.str, None, builtins.int]' z1 = 'b' and x -reveal_type(z1) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(z1) # N: Revealed type is 'Union[builtins.str, None]' z2 = int() and x -reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, None]' +reveal_type(z2) # N: Revealed type is 'Union[builtins.int, builtins.str, None]' [case testLambdaReturningNone] f = lambda: None x = f() -reveal_type(x) # E: Revealed type is 'None' +reveal_type(x) # N: Revealed type is 'None' [case testNoneArgumentType] def f(x: None) -> None: pass @@ -160,15 +160,15 @@ if bool(): # scope limit assignment x = 1 # in scope of the assignment, x is an int - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' # out of scope of the assignment, it's an Optional[int] -reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/bool.pyi] [case testInferOptionalTypeLocallyBound] x = None x = 1 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [case testInferOptionalAnyType] from typing import Any @@ -176,8 +176,8 @@ x = None a = None # type: Any if bool(): x = a - reveal_type(x) # E: Revealed type is 'Any' -reveal_type(x) # E: Revealed type is 'Union[Any, None]' + reveal_type(x) # N: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Union[Any, None]' [builtins fixtures/bool.pyi] [case testInferOptionalTypeFromOptional] @@ -185,7 +185,7 @@ from typing import Optional y = None # type: Optional[int] x = None x = y -reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [case testInferOptionalListType] x = [None] @@ -244,8 +244,8 @@ from typing import overload def f(x: None) -> str: pass @overload def f(x: int) -> int: pass -reveal_type(f(None)) # E: Revealed type is 'builtins.str' -reveal_type(f(0)) # E: Revealed type is 'builtins.int' +reveal_type(f(None)) # N: Revealed type is 'builtins.str' +reveal_type(f(0)) # N: Revealed type is 'builtins.int' [case testOptionalTypeOrTypePlain] from typing import Optional @@ -267,15 +267,15 @@ def f(a: Optional[int], b: Optional[int]) -> None: def g(a: int, b: Optional[int]) -> None: reveal_type(a or b) [out] -main:3: error: Revealed type is 'Union[builtins.int, None]' -main:5: error: Revealed type is 'Union[builtins.int, None]' +main:3: note: Revealed type is 'Union[builtins.int, None]' +main:5: note: Revealed type is 'Union[builtins.int, None]' [case testOptionalTypeOrTypeComplexUnion] from typing import Union def f(a: Union[int, str, None]) -> None: reveal_type(a or 'default') [out] -main:3: error: Revealed type is 'Union[builtins.int, builtins.str]' +main:3: note: Revealed type is 'Union[builtins.int, builtins.str]' [case testOptionalTypeOrTypeNoTriggerPlain] from typing import Optional @@ -316,7 +316,7 @@ def f() -> Generator[None, None, None]: [case testNoneAndStringIsNone] a = None b = "foo" -reveal_type(a and b) # E: Revealed type is 'None' +reveal_type(a and b) # N: Revealed type is 'None' [case testNoneMatchesObjectInOverload] import a @@ -388,11 +388,11 @@ def lookup_field(name, obj): attr = None [case testTernaryWithNone] -reveal_type(None if bool() else 0) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(None if bool() else 0) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/bool.pyi] [case testListWithNone] -reveal_type([0, None, 0]) # E: Revealed type is 'builtins.list[Union[builtins.int, None]]' +reveal_type([0, None, 0]) # N: Revealed type is 'builtins.list[Union[builtins.int, None]]' [builtins fixtures/list.pyi] [case testOptionalWhitelistSuppressesOptionalErrors] @@ -459,9 +459,9 @@ raise BaseException from None from typing import Generator def f() -> Generator[str, None, None]: pass x = f() -reveal_type(x) # E: Revealed type is 'typing.Generator[builtins.str, None, None]' +reveal_type(x) # N: Revealed type is 'typing.Generator[builtins.str, None, None]' l = [f()] -reveal_type(l) # E: Revealed type is 'builtins.list[typing.Generator*[builtins.str, None, None]]' +reveal_type(l) # N: Revealed type is 'builtins.list[typing.Generator*[builtins.str, None, None]]' [builtins fixtures/list.pyi] [case testNoneListTernary] @@ -482,36 +482,36 @@ foo([f]) # E: List item 0 has incompatible type "Callable[[], int]"; expected " from typing import Optional x = '' # type: Optional[str] if x == '': - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, None]' [builtins fixtures/ops.pyi] [case testInferEqualsNotOptionalWithUnion] from typing import Union x = '' # type: Union[str, int, None] if x == '': - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int]' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int, None]' [builtins fixtures/ops.pyi] [case testInferEqualsNotOptionalWithOverlap] from typing import Union x = '' # type: Union[str, int, None] if x == object(): - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int]' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int, None]' [builtins fixtures/ops.pyi] [case testInferEqualsStillOptionalWithNoOverlap] from typing import Optional x = '' # type: Optional[str] if x == 0: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, None]' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, None]' [builtins fixtures/ops.pyi] [case testInferEqualsStillOptionalWithBothOptional] @@ -519,9 +519,9 @@ from typing import Union x = '' # type: Union[str, int, None] y = '' # type: Union[str, None] if x == y: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int, None]' else: - reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.str, builtins.int, None]' [builtins fixtures/ops.pyi] [case testWarnNoReturnWorksWithStrictOptional] @@ -592,14 +592,14 @@ def u(x: T, y: S) -> Union[S, T]: pass a = None # type: Any # Test both orders -reveal_type(u(C(), None)) # E: Revealed type is 'Union[None, __main__.C*]' -reveal_type(u(None, C())) # E: Revealed type is 'Union[__main__.C*, None]' +reveal_type(u(C(), None)) # N: Revealed type is 'Union[None, __main__.C*]' +reveal_type(u(None, C())) # N: Revealed type is 'Union[__main__.C*, None]' -reveal_type(u(a, None)) # E: Revealed type is 'Union[None, Any]' -reveal_type(u(None, a)) # E: Revealed type is 'Union[Any, None]' +reveal_type(u(a, None)) # N: Revealed type is 'Union[None, Any]' +reveal_type(u(None, a)) # N: Revealed type is 'Union[Any, None]' -reveal_type(u(1, None)) # E: Revealed type is 'Union[None, builtins.int*]' -reveal_type(u(None, 1)) # E: Revealed type is 'Union[builtins.int*, None]' +reveal_type(u(1, None)) # N: Revealed type is 'Union[None, builtins.int*]' +reveal_type(u(None, 1)) # N: Revealed type is 'Union[builtins.int*, None]' [case testOptionalAndAnyBaseClass] from typing import Any, Optional @@ -616,21 +616,21 @@ B = None # type: Any class A(B): pass def f(a: Optional[A]): - reveal_type(a) # E: Revealed type is 'Union[__main__.A, None]' + reveal_type(a) # N: Revealed type is 'Union[__main__.A, None]' if a is not None: - reveal_type(a) # E: Revealed type is '__main__.A' + reveal_type(a) # N: Revealed type is '__main__.A' else: - reveal_type(a) # E: Revealed type is 'None' - reveal_type(a) # E: Revealed type is 'Union[__main__.A, None]' + reveal_type(a) # N: Revealed type is 'None' + reveal_type(a) # N: Revealed type is 'Union[__main__.A, None]' [builtins fixtures/isinstance.pyi] [case testFlattenOptionalUnion] from typing import Optional, Union x: Optional[Union[int, str]] -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str, None]' y: Optional[Union[int, None]] -reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [case testOverloadWithNoneAndOptional] from typing import overload, Optional @@ -641,10 +641,10 @@ def f(x: int) -> str: ... def f(x: Optional[int]) -> Optional[str]: ... def f(x): return x -reveal_type(f(1)) # E: Revealed type is 'builtins.str' -reveal_type(f(None)) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(f(1)) # N: Revealed type is 'builtins.str' +reveal_type(f(None)) # N: Revealed type is 'Union[builtins.str, None]' x: Optional[int] -reveal_type(f(x)) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(f(x)) # N: Revealed type is 'Union[builtins.str, None]' [case testUnionTruthinessTracking] from typing import Optional, Any @@ -660,7 +660,7 @@ from typing import Optional x: object y: Optional[int] x = y -reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' [out] [case testNarrowOptionalOutsideLambda] @@ -709,11 +709,11 @@ def f(): def g(x: Optional[int]) -> int: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' # As a special case for Unions containing None, during x = f() - reveal_type(x) # E: Revealed type is 'Union[builtins.int, Any]' - reveal_type(x) # E: Revealed type is 'Union[builtins.int, Any]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, Any]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, Any]' return x [builtins fixtures/bool.pyi] @@ -725,13 +725,13 @@ def f(): def g(x: Optional[int]) -> int: if x is None: - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' # Since we've assigned to x, the special case None behavior shouldn't happen x = f() - reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' - reveal_type(x) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, None]' return x # E: Incompatible return value type (got "Optional[int]", expected "int") [builtins fixtures/bool.pyi] @@ -744,10 +744,10 @@ def f(): def g(x: Optional[int]) -> int: if x is not None: return x - reveal_type(x) # E: Revealed type is 'None' + reveal_type(x) # N: Revealed type is 'None' if 1: x = f() - reveal_type(x) # E: Revealed type is 'Union[builtins.int, Any]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, Any]' return x [builtins fixtures/bool.pyi] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 1145093183df..f805dd3e0903 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -32,8 +32,8 @@ def f(x: 'B') -> 'A': ... def f(x: Any) -> Any: pass -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -46,8 +46,8 @@ def f(x: 'A') -> 'B': ... @overload def f(x: 'B') -> 'A': ... -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -73,8 +73,8 @@ def f(x: 'B') -> 'A': ... def f(x: Any) -> Any: pass -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -94,8 +94,8 @@ def f(x: 'B') -> 'A': ... def f(x: Any) -> Any: pass -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -169,8 +169,8 @@ def f(x): def f(x): pass -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -199,8 +199,8 @@ def g(x): if int(): foo = "bar" -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' class A: pass class B: pass @@ -233,8 +233,8 @@ def f(x: 'B') -> 'A': ... def f(x: 'A') -> Any: # E: Overloaded function implementation does not accept all possible arguments of signature 2 pass -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' [builtins fixtures/isinstance.pyi] @@ -254,8 +254,8 @@ def f(x: 'B') -> 'A': ... def f(x: Any) -> 'B': # E: Overloaded function implementation cannot produce return type of signature 2 return B() -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.A' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.A' [builtins fixtures/isinstance.pyi] @@ -277,8 +277,8 @@ def f(x: 'B') -> 'B': ... def f(x: T) -> T: ... -reveal_type(f(A())) # E: Revealed type is '__main__.A' -reveal_type(f(B())) # E: Revealed type is '__main__.B' +reveal_type(f(A())) # N: Revealed type is '__main__.A' +reveal_type(f(B())) # N: Revealed type is '__main__.B' [builtins fixtures/isinstance.pyi] @@ -300,8 +300,8 @@ def f(x: 'B') -> 'B': ... def f(x: Union[T, B]) -> T: # E: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables ... -reveal_type(f(A())) # E: Revealed type is '__main__.A' -reveal_type(f(B())) # E: Revealed type is '__main__.B' +reveal_type(f(A())) # N: Revealed type is '__main__.A' +reveal_type(f(B())) # N: Revealed type is '__main__.B' [builtins fixtures/isinstance.pyi] @@ -1185,7 +1185,7 @@ 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]"; expected "int" -reveal_type(a) # E: Revealed type is 'builtins.int' +reveal_type(a) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] [case testOverloadWithDerivedFromAny] @@ -1246,7 +1246,7 @@ def g(x: U, y: V) -> None: # N: def [T <: str] f(x: T) -> T \ # N: def [T <: str] f(x: List[T]) -> None a = f([x]) - reveal_type(a) # E: Revealed type is 'None' + reveal_type(a) # N: Revealed type is 'None' f([y]) # E: Value of type variable "T" of "f" cannot be "V" f([x, y]) # E: Value of type variable "T" of "f" cannot be "object" [builtins fixtures/list.pyi] @@ -1354,10 +1354,10 @@ foo(g) [builtins fixtures/list.pyi] [out] -main:17: error: Revealed type is 'builtins.int' -main:18: error: Revealed type is 'builtins.str' -main:19: error: Revealed type is 'Any' -main:20: error: Revealed type is 'Union[builtins.int, builtins.str]' +main:17: note: Revealed type is 'builtins.int' +main:18: note: Revealed type is 'builtins.str' +main:19: note: Revealed type is 'Any' +main:20: note: Revealed type is 'Union[builtins.int, builtins.str]' main:21: error: Argument 1 to "foo" has incompatible type "List[bool]"; expected "List[int]" main:21: note: "List" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance main:21: note: Consider using "Sequence" instead, which is covariant @@ -1373,7 +1373,7 @@ def f(x: List[int]) -> int: ... def f(x: List[str]) -> str: ... def f(x): pass -reveal_type(f([])) # E: Revealed type is 'builtins.int' +reveal_type(f([])) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] [case testOverloadAgainstEmptyCovariantCollections] @@ -1392,9 +1392,9 @@ def f(x: Wrapper[A]) -> int: ... def f(x: Wrapper[C]) -> str: ... def f(x): pass -reveal_type(f(Wrapper())) # E: Revealed type is 'builtins.int' -reveal_type(f(Wrapper[C]())) # E: Revealed type is 'builtins.str' -reveal_type(f(Wrapper[B]())) # E: Revealed type is 'builtins.int' +reveal_type(f(Wrapper())) # N: Revealed type is 'builtins.int' +reveal_type(f(Wrapper[C]())) # N: Revealed type is 'builtins.str' +reveal_type(f(Wrapper[B]())) # N: Revealed type is 'builtins.int' [case testOverlappingOverloadCounting] from foo import * @@ -1540,7 +1540,7 @@ class Test(object): return 3 t = Test() -reveal_type(t.do_chain) # E: Revealed type is '__main__.Chain' +reveal_type(t.do_chain) # N: Revealed type is '__main__.Chain' [case testOverloadWithOverlappingItemsAndAnyArgument1] from typing import overload, Any @@ -1552,7 +1552,7 @@ def f(x: object) -> object: ... def f(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument2] from typing import overload, Any @@ -1564,7 +1564,7 @@ def f(x: float) -> float: ... def f(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument3] from typing import overload, Any @@ -1576,7 +1576,7 @@ def f(x: str) -> str: ... def f(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument4] from typing import overload, Any @@ -1589,15 +1589,15 @@ def f(x): pass a: Any # Any causes ambiguity -reveal_type(f(a, 1, '')) # E: Revealed type is 'Any' +reveal_type(f(a, 1, '')) # N: Revealed type is 'Any' # Any causes no ambiguity -reveal_type(f(1, a, a)) # E: Revealed type is 'builtins.int' -reveal_type(f('', a, a)) # E: Revealed type is 'builtins.object' +reveal_type(f(1, a, a)) # N: Revealed type is 'builtins.int' +reveal_type(f('', a, a)) # N: Revealed type is 'builtins.object' # Like above, but use keyword arguments. -reveal_type(f(y=1, z='', x=a)) # E: Revealed type is 'Any' -reveal_type(f(y=a, z='', x=1)) # E: Revealed type is 'builtins.int' -reveal_type(f(z='', x=1, y=a)) # E: Revealed type is 'builtins.int' -reveal_type(f(z='', x=a, y=1)) # E: Revealed type is 'Any' +reveal_type(f(y=1, z='', x=a)) # N: Revealed type is 'Any' +reveal_type(f(y=a, z='', x=1)) # N: Revealed type is 'builtins.int' +reveal_type(f(z='', x=1, y=a)) # N: Revealed type is 'builtins.int' +reveal_type(f(z='', x=a, y=1)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument5] from typing import overload, Any, Union @@ -1619,8 +1619,8 @@ def g(x: Union[int, float]) -> float: ... def g(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'Any' -reveal_type(g(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'Any' +reveal_type(g(a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument6] from typing import overload, Any @@ -1635,11 +1635,11 @@ def f(x): pass a: Any # Any causes ambiguity -reveal_type(f(*a)) # E: Revealed type is 'Any' -reveal_type(f(a, *a)) # E: Revealed type is 'Any' -reveal_type(f(1, *a)) # E: Revealed type is 'Any' -reveal_type(f(1.1, *a)) # E: Revealed type is 'Any' -reveal_type(f('', *a)) # E: Revealed type is 'builtins.str' +reveal_type(f(*a)) # N: Revealed type is 'Any' +reveal_type(f(a, *a)) # N: Revealed type is 'Any' +reveal_type(f(1, *a)) # N: Revealed type is 'Any' +reveal_type(f(1.1, *a)) # N: Revealed type is 'Any' +reveal_type(f('', *a)) # N: Revealed type is 'builtins.str' [case testOverloadWithOverlappingItemsAndAnyArgument7] from typing import overload, Any @@ -1657,8 +1657,8 @@ def g(x: object, y: int, z: str) -> object: ... def g(x): pass a: Any -reveal_type(f(1, *a)) # E: Revealed type is 'builtins.int' -reveal_type(g(1, *a)) # E: Revealed type is 'Any' +reveal_type(f(1, *a)) # N: Revealed type is 'builtins.int' +reveal_type(g(1, *a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument8] from typing import overload, Any @@ -1671,8 +1671,8 @@ def f(x): pass a: Any # The return type is not ambiguous so Any arguments cause no ambiguity. -reveal_type(f(a, 1, 1)) # E: Revealed type is 'builtins.str' -reveal_type(f(1, *a)) # E: Revealed type is 'builtins.str' +reveal_type(f(a, 1, 1)) # N: Revealed type is 'builtins.str' +reveal_type(f(1, *a)) # N: Revealed type is 'builtins.str' [case testOverloadWithOverlappingItemsAndAnyArgument9] from typing import overload, Any, List @@ -1687,10 +1687,10 @@ a: Any b: List[Any] c: List[str] d: List[int] -reveal_type(f(a)) # E: Revealed type is 'builtins.list[Any]' -reveal_type(f(b)) # E: Revealed type is 'builtins.list[Any]' -reveal_type(f(c)) # E: Revealed type is 'builtins.list[Any]' -reveal_type(f(d)) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(a)) # N: Revealed type is 'builtins.list[Any]' +reveal_type(f(b)) # N: Revealed type is 'builtins.list[Any]' +reveal_type(f(c)) # N: Revealed type is 'builtins.list[Any]' +reveal_type(f(d)) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] @@ -1708,9 +1708,9 @@ def f(*args, **kwargs): pass # keyword arguments. a: Any i: int -reveal_type(f(x=a, y=i)) # E: Revealed type is 'builtins.int' -reveal_type(f(y=a)) # E: Revealed type is 'Any' -reveal_type(f(x=a, y=a)) # E: Revealed type is 'Any' +reveal_type(f(x=a, y=i)) # N: Revealed type is 'builtins.int' +reveal_type(f(y=a)) # N: Revealed type is 'Any' +reveal_type(f(x=a, y=a)) # N: Revealed type is 'Any' [builtins fixtures/dict.pyi] @@ -1725,8 +1725,8 @@ def f(*args, **kwargs): pass a: Dict[str, Any] i: int -reveal_type(f(x=i, **a)) # E: Revealed type is 'builtins.int' -reveal_type(f(**a)) # E: Revealed type is 'Any' +reveal_type(f(x=i, **a)) # N: Revealed type is 'builtins.int' +reveal_type(f(**a)) # N: Revealed type is 'Any' [builtins fixtures/dict.pyi] @@ -1740,7 +1740,7 @@ def f(x: str) -> str: ... def f(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument13] from typing import Any, overload, TypeVar, Generic @@ -1757,7 +1757,7 @@ class A(Generic[T]): i: Any a: A[Any] -reveal_type(a.f(i)) # E: Revealed type is 'Any' +reveal_type(a.f(i)) # N: Revealed type is 'Any' [case testOverloadWithOverlappingItemsAndAnyArgument14] from typing import Any, overload, TypeVar, Generic @@ -1776,7 +1776,7 @@ class A(Generic[T]): i: Any a: A[Any] -reveal_type(a.f(i)) # E: Revealed type is '__main__.Wrapper[Any]' +reveal_type(a.f(i)) # N: Revealed type is '__main__.Wrapper[Any]' [case testOverloadWithOverlappingItemsAndAnyArgument15] from typing import overload, Any, Union @@ -1794,8 +1794,8 @@ def g(x: str) -> Union[int, str]: ... def g(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'builtins.str' -reveal_type(g(a)) # E: Revealed type is 'Union[builtins.str, builtins.int]' +reveal_type(f(a)) # N: Revealed type is 'builtins.str' +reveal_type(g(a)) # N: Revealed type is 'Union[builtins.str, builtins.int]' [case testOverloadWithOverlappingItemsAndAnyArgument16] from typing import overload, Any, Union, Callable @@ -1807,8 +1807,8 @@ def f(x: str) -> Callable[[str], str]: ... def f(x): pass a: Any -reveal_type(f(a)) # E: Revealed type is 'def (*Any, **Any) -> Any' -reveal_type(f(a)(a)) # E: Revealed type is 'Any' +reveal_type(f(a)) # N: Revealed type is 'def (*Any, **Any) -> Any' +reveal_type(f(a)(a)) # N: Revealed type is 'Any' [case testOverloadOnOverloadWithType] from typing import Any, Type, TypeVar, overload @@ -1824,7 +1824,7 @@ def make(*args): pass c = make(MyInt) -reveal_type(c) # E: Revealed type is 'mod.MyInt*' +reveal_type(c) # N: Revealed type is 'mod.MyInt*' [file mod.pyi] from typing import overload @@ -2033,9 +2033,9 @@ def foo(*, p1: A, p2: B = B()) -> A: ... def foo(*, p2: B = B()) -> B: ... def foo(p1, p2=None): ... -reveal_type(foo()) # E: Revealed type is '__main__.B' -reveal_type(foo(p2=B())) # E: Revealed type is '__main__.B' -reveal_type(foo(p1=A())) # E: Revealed type is '__main__.A' +reveal_type(foo()) # N: Revealed type is '__main__.B' +reveal_type(foo(p2=B())) # N: Revealed type is '__main__.B' +reveal_type(foo(p1=A())) # N: Revealed type is '__main__.A' [case testOverloadWithNonPositionalArgsIgnoresOrder] from typing import overload @@ -2387,16 +2387,16 @@ def foo(x: int, y: int) -> B: ... def foo(x: int, y: int, z: int, *args: int) -> C: ... def foo(*args): pass -reveal_type(foo(1)) # E: Revealed type is '__main__.A' -reveal_type(foo(1, 2)) # E: Revealed type is '__main__.B' -reveal_type(foo(1, 2, 3)) # E: Revealed type is '__main__.C' +reveal_type(foo(1)) # N: Revealed type is '__main__.A' +reveal_type(foo(1, 2)) # N: Revealed type is '__main__.B' +reveal_type(foo(1, 2, 3)) # N: Revealed type is '__main__.C' -reveal_type(foo(*[1])) # E: Revealed type is '__main__.C' -reveal_type(foo(*[1, 2])) # E: Revealed type is '__main__.C' -reveal_type(foo(*[1, 2, 3])) # E: Revealed type is '__main__.C' +reveal_type(foo(*[1])) # N: Revealed type is '__main__.C' +reveal_type(foo(*[1, 2])) # N: Revealed type is '__main__.C' +reveal_type(foo(*[1, 2, 3])) # N: Revealed type is '__main__.C' x: List[int] -reveal_type(foo(*x)) # E: Revealed type is '__main__.C' +reveal_type(foo(*x)) # N: Revealed type is '__main__.C' y: List[str] foo(*y) # E: No overload variant of "foo" matches argument type "List[str]" \ @@ -2424,11 +2424,11 @@ def foo(x: int, y: int, z: int, *args: int) -> C: ... def foo(*x: str) -> D: ... def foo(*args): pass -reveal_type(foo(*[1, 2])) # E: Revealed type is '__main__.C' -reveal_type(foo(*["a", "b"])) # E: Revealed type is '__main__.D' +reveal_type(foo(*[1, 2])) # N: Revealed type is '__main__.C' +reveal_type(foo(*["a", "b"])) # N: Revealed type is '__main__.D' x: List[Any] -reveal_type(foo(*x)) # E: Revealed type is 'Any' +reveal_type(foo(*x)) # N: Revealed type is 'Any' [builtins fixtures/list.pyi] [case testOverloadMultipleVarargDefinitionComplex] @@ -2470,9 +2470,9 @@ def f1(x: A) -> B: ... def f2(x: B) -> C: ... def f3(x: C) -> D: ... -reveal_type(chain_call(A(), f1, f2)) # E: Revealed type is '__main__.C*' -reveal_type(chain_call(A(), f1, f2, f3)) # E: Revealed type is 'Any' -reveal_type(chain_call(A(), f, f, f, f)) # E: Revealed type is '__main__.A' +reveal_type(chain_call(A(), f1, f2)) # N: Revealed type is '__main__.C*' +reveal_type(chain_call(A(), f1, f2, f3)) # N: Revealed type is 'Any' +reveal_type(chain_call(A(), f, f, f, f)) # N: Revealed type is '__main__.A' [builtins fixtures/list.pyi] [case testOverloadVarargsSelection] @@ -2486,14 +2486,14 @@ def f(*xs: int) -> Tuple[int, ...]: ... def f(*args): pass i: int -reveal_type(f(i)) # E: Revealed type is 'Tuple[builtins.int]' -reveal_type(f(i, i)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(f(i, i, i)) # E: Revealed type is 'builtins.tuple[builtins.int]' - -reveal_type(f(*[])) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(*[i])) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(*[i, i])) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(*[i, i, i])) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(i)) # N: Revealed type is 'Tuple[builtins.int]' +reveal_type(f(i, i)) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(f(i, i, i)) # N: Revealed type is 'builtins.tuple[builtins.int]' + +reveal_type(f(*[])) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*[i])) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*[i, i])) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*[i, i, i])) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/list.pyi] [case testOverloadVarargsSelectionWithTuples] @@ -2507,10 +2507,10 @@ def f(*xs: int) -> Tuple[int, ...]: ... def f(*args): pass i: int -reveal_type(f(*())) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(*(i,))) # E: Revealed type is 'Tuple[builtins.int]' -reveal_type(f(*(i, i))) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(f(*(i, i, i))) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*())) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*(i,))) # N: Revealed type is 'Tuple[builtins.int]' +reveal_type(f(*(i, i))) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(f(*(i, i, i))) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/tuple.pyi] [case testOverloadVarargsSelectionWithNamedTuples] @@ -2528,9 +2528,9 @@ C = NamedTuple('C', [('a', int), ('b', int), ('c', int)]) a: A b: B c: C -reveal_type(f(*a)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(f(*b)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(f(*c)) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(*a)) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(f(*b)) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(f(*c)) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/tuple.pyi] [case testOverloadKwargsSelectionWithDict] @@ -2544,10 +2544,10 @@ def f(**xs: int) -> Tuple[int, ...]: ... def f(**kwargs): pass empty: Dict[str, int] -reveal_type(f(**empty)) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(**{'x': 4})) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(**{'x': 4, 'y': 4})) # E: Revealed type is 'builtins.tuple[builtins.int]' -reveal_type(f(**{'a': 4, 'b': 4, 'c': 4})) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(**empty)) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(**{'x': 4})) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(**{'x': 4, 'y': 4})) # N: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(**{'a': 4, 'b': 4, 'c': 4})) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/dict.pyi] [case testOverloadKwargsSelectionWithTypedDict-skip] @@ -2571,9 +2571,9 @@ a: A b: B c: C -reveal_type(f(**a)) # E: Revealed type is 'Tuple[builtins.int]' -reveal_type(f(**b)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' -reveal_type(f(**c)) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(f(**a)) # N: Revealed type is 'Tuple[builtins.int]' +reveal_type(f(**b)) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(f(**c)) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/dict.pyi] [case testOverloadVarargsAndKwargsSelection] @@ -2594,15 +2594,15 @@ a: Tuple[int, int] b: Tuple[int, ...] c: Dict[str, int] -reveal_type(f(*a, **c)) # E: Revealed type is '__main__.A' -reveal_type(f(*b, **c)) # E: Revealed type is '__main__.A' -reveal_type(f(*a)) # E: Revealed type is '__main__.B' -reveal_type(f(*b)) # E: Revealed type is 'Any' +reveal_type(f(*a, **c)) # N: Revealed type is '__main__.A' +reveal_type(f(*b, **c)) # N: Revealed type is '__main__.A' +reveal_type(f(*a)) # N: Revealed type is '__main__.B' +reveal_type(f(*b)) # N: Revealed type is 'Any' # TODO: Should this be 'Any' instead? # The first matching overload with a kwarg is f(int, int, **int) -> A, # but f(*int, **int) -> Any feels like a better fit. -reveal_type(f(**c)) # E: Revealed type is '__main__.A' +reveal_type(f(**c)) # N: Revealed type is '__main__.A' [builtins fixtures/args.pyi] [case testOverloadWithPartiallyOverlappingUnions] @@ -3020,7 +3020,7 @@ def f1(x: C) -> D: ... def f1(x): ... arg1: Union[A, C] -reveal_type(f1(arg1)) # E: Revealed type is 'Union[__main__.B, __main__.D]' +reveal_type(f1(arg1)) # N: Revealed type is 'Union[__main__.B, __main__.D]' arg2: Union[A, B] f1(arg2) # E: Argument 1 to "f1" has incompatible type "Union[A, B]"; expected "A" @@ -3031,7 +3031,7 @@ def f2(x: A) -> B: ... def f2(x: C) -> B: ... def f2(x): ... -reveal_type(f2(arg1)) # E: Revealed type is '__main__.B' +reveal_type(f2(arg1)) # N: Revealed type is '__main__.B' [case testOverloadInferUnionReturnMultipleArguments] from typing import overload, Union @@ -3060,13 +3060,13 @@ reveal_type(f2(arg1, arg1)) reveal_type(f2(arg1, C())) [out] -main:15: error: Revealed type is '__main__.B' +main:15: note: Revealed type is '__main__.B' main:15: error: Argument 1 to "f1" has incompatible type "Union[A, C]"; expected "A" main:15: error: Argument 2 to "f1" has incompatible type "Union[A, C]"; expected "C" -main:23: error: Revealed type is '__main__.B' +main:23: note: Revealed type is '__main__.B' main:23: error: Argument 1 to "f2" has incompatible type "Union[A, C]"; expected "A" main:23: error: Argument 2 to "f2" has incompatible type "Union[A, C]"; expected "C" -main:24: error: Revealed type is 'Union[__main__.B, __main__.D]' +main:24: note: Revealed type is 'Union[__main__.B, __main__.D]' [case testOverloadInferUnionRespectsVariance] from typing import overload, TypeVar, Union, Generic @@ -3088,7 +3088,7 @@ def foo(x: WrapperContra[B]) -> str: ... def foo(x): pass compat: Union[WrapperCo[C], WrapperContra[A]] -reveal_type(foo(compat)) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(foo(compat)) # N: Revealed type is 'Union[builtins.int, builtins.str]' not_compat: Union[WrapperCo[A], WrapperContra[C]] foo(not_compat) # E: Argument 1 to "foo" has incompatible type "Union[WrapperCo[A], WrapperContra[C]]"; expected "WrapperCo[B]" @@ -3107,9 +3107,9 @@ def f(y: B) -> C: ... def f(x): ... x: Union[A, B] -reveal_type(f(A())) # E: Revealed type is '__main__.B' -reveal_type(f(B())) # E: Revealed type is '__main__.C' -reveal_type(f(x)) # E: Revealed type is 'Union[__main__.B, __main__.C]' +reveal_type(f(A())) # N: Revealed type is '__main__.B' +reveal_type(f(B())) # N: Revealed type is '__main__.C' +reveal_type(f(x)) # N: Revealed type is 'Union[__main__.B, __main__.C]' [case testOverloadInferUnionReturnFunctionsWithKwargs] from typing import overload, Union, Optional @@ -3127,12 +3127,12 @@ def f(x: A, y: Optional[B] = None) -> C: ... def f(x: A, z: Optional[C] = None) -> B: ... def f(x, y=None, z=None): ... -reveal_type(f(A(), B())) # E: Revealed type is '__main__.C' -reveal_type(f(A(), C())) # E: Revealed type is '__main__.B' +reveal_type(f(A(), B())) # N: Revealed type is '__main__.C' +reveal_type(f(A(), C())) # N: Revealed type is '__main__.B' arg: Union[B, C] -reveal_type(f(A(), arg)) # E: Revealed type is 'Union[__main__.C, __main__.B]' -reveal_type(f(A())) # E: Revealed type is '__main__.D' +reveal_type(f(A(), arg)) # N: Revealed type is 'Union[__main__.C, __main__.B]' +reveal_type(f(A())) # N: Revealed type is '__main__.D' [builtins fixtures/tuple.pyi] @@ -3152,7 +3152,7 @@ def f(x: B, y: B = B()) -> Parent: ... def f(*args): ... x: Union[A, B] -reveal_type(f(x)) # E: Revealed type is '__main__.Parent' +reveal_type(f(x)) # N: Revealed type is '__main__.Parent' f(x, B()) # E: Argument 1 to "f" has incompatible type "Union[A, B]"; expected "B" [case testOverloadInferUnionWithMixOfPositionalAndOptionalArgs] @@ -3171,10 +3171,10 @@ def f(*args): ... x: Union[A, B] y: Optional[A] z: Union[A, Optional[B]] -reveal_type(f(x)) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(f(y)) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(f(z)) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(f()) # E: Revealed type is 'builtins.str' +reveal_type(f(x)) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(f(y)) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(f(z)) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(f()) # N: Revealed type is 'builtins.str' [case testOverloadingInferUnionReturnWithTypevarWithValueRestriction] from typing import overload, Union, TypeVar, Generic @@ -3197,9 +3197,9 @@ class Wrapper(Generic[T]): obj: Wrapper[B] = Wrapper() x: Union[A, B] -reveal_type(obj.f(A())) # E: Revealed type is '__main__.C' -reveal_type(obj.f(B())) # E: Revealed type is '__main__.B' -reveal_type(obj.f(x)) # E: Revealed type is 'Union[__main__.C, __main__.B]' +reveal_type(obj.f(A())) # N: Revealed type is '__main__.C' +reveal_type(obj.f(B())) # N: Revealed type is '__main__.B' +reveal_type(obj.f(x)) # N: Revealed type is 'Union[__main__.C, __main__.B]' [case testOverloadingInferUnionReturnWithFunctionTypevarReturn] from typing import overload, Union, TypeVar, Generic @@ -3224,12 +3224,12 @@ def wrapper() -> None: a1: A = foo(obj1) a2 = foo(obj1) - reveal_type(a1) # E: Revealed type is '__main__.A' - reveal_type(a2) # E: Revealed type is '__main__.A*' + reveal_type(a1) # N: Revealed type is '__main__.A' + reveal_type(a2) # N: Revealed type is '__main__.A*' obj2: Union[W1[A], W2[B]] - reveal_type(foo(obj2)) # E: Revealed type is 'Union[__main__.A*, __main__.B*]' + reveal_type(foo(obj2)) # N: Revealed type is 'Union[__main__.A*, __main__.B*]' bar(obj2) # E: Cannot infer type argument 1 of "bar" b1_overload: A = foo(obj2) # E: Incompatible types in assignment (expression has type "Union[A, B]", variable has type "A") @@ -3258,7 +3258,7 @@ def wrapper() -> None: obj1: Union[W1[A], W2[A]] a1 = SomeType[A]().foo(obj1) - reveal_type(a1) # E: Revealed type is '__main__.A*' + reveal_type(a1) # N: Revealed type is '__main__.A*' # Note: These should be fine, but mypy has an unrelated bug # that makes them error out? @@ -3323,11 +3323,11 @@ T1 = TypeVar('T1', bound=A) def t_is_same_bound(arg1: T1, arg2: S) -> Tuple[T1, S]: x1: Union[List[S], List[Tuple[T1, S]]] y1: S - reveal_type(Dummy[T1]().foo(x1, y1)) # E: Revealed type is 'Union[S`-2, T1`-1]' + reveal_type(Dummy[T1]().foo(x1, y1)) # N: Revealed type is 'Union[S`-2, T1`-1]' x2: Union[List[T1], List[Tuple[T1, T1]]] y2: T1 - reveal_type(Dummy[T1]().foo(x2, y2)) # E: Revealed type is 'T1`-1' + reveal_type(Dummy[T1]().foo(x2, y2)) # N: Revealed type is 'T1`-1' return arg1, arg2 @@ -3361,7 +3361,7 @@ def t_is_same_bound(arg1: T1, arg2: S) -> Tuple[T1, S]: x4: Union[List[int], List[Tuple[C, int]]] y4: int - reveal_type(Dummy[C]().foo(x4, y4)) # E: Revealed type is 'Union[builtins.int*, __main__.C]' + reveal_type(Dummy[C]().foo(x4, y4)) # N: Revealed type is 'Union[builtins.int*, __main__.C]' Dummy[A]().foo(x4, y4) # E: Argument 1 to "foo" of "Dummy" has incompatible type "Union[List[int], List[Tuple[C, int]]]"; expected "List[Tuple[A, int]]" return arg1, arg2 @@ -3390,11 +3390,11 @@ T1 = TypeVar('T1', bound=B) def t_is_tighter_bound(arg1: T1, arg2: S) -> Tuple[T1, S]: x1: Union[List[S], List[Tuple[T1, S]]] y1: S - reveal_type(Dummy[T1]().foo(x1, y1)) # E: Revealed type is 'Union[S`-2, T1`-1]' + reveal_type(Dummy[T1]().foo(x1, y1)) # N: Revealed type is 'Union[S`-2, T1`-1]' x2: Union[List[T1], List[Tuple[T1, T1]]] y2: T1 - reveal_type(Dummy[T1]().foo(x2, y2)) # E: Revealed type is 'T1`-1' + reveal_type(Dummy[T1]().foo(x2, y2)) # N: Revealed type is 'T1`-1' return arg1, arg2 @@ -3432,10 +3432,10 @@ def t_is_compatible_bound(arg1: T3, arg2: S) -> Tuple[T3, S]: [builtins fixtures/list.pyi] [out] -main:22: error: Revealed type is 'Union[S`-2, __main__.B]' -main:22: error: Revealed type is 'Union[S`-2, __main__.C]' -main:26: error: Revealed type is '__main__.B*' -main:26: error: Revealed type is '__main__.C*' +main:22: note: Revealed type is 'Union[S`-2, __main__.B]' +main:22: note: Revealed type is 'Union[S`-2, __main__.C]' +main:26: note: Revealed type is '__main__.B*' +main:26: note: Revealed type is '__main__.C*' [case testOverloadInferUnionReturnWithInconsistentTypevarNames] from typing import overload, TypeVar, Union @@ -3460,7 +3460,7 @@ def inconsistent(x: T, y: Union[str, int]) -> T: def test(x: T) -> T: y: Union[str, int] - reveal_type(consistent(x, y)) # E: Revealed type is 'T`-1' + reveal_type(consistent(x, y)) # N: Revealed type is 'T`-1' # On one hand, this overload is defined in a weird way; on the other, there's technically nothing wrong with it. inconsistent(x, y) @@ -3489,9 +3489,9 @@ def g(x): ... a: None b: int c: Optional[int] -reveal_type(g(a)) # E: Revealed type is 'builtins.int' -reveal_type(g(b)) # E: Revealed type is 'builtins.str' -reveal_type(g(c)) # E: Revealed type is 'builtins.str' +reveal_type(g(a)) # N: Revealed type is 'builtins.int' +reveal_type(g(b)) # N: Revealed type is 'builtins.str' +reveal_type(g(c)) # N: Revealed type is 'builtins.str' [case testOverloadsAndNoneWithStrictOptional] # flags: --strict-optional @@ -3512,9 +3512,9 @@ def g(x): ... a: None b: int c: Optional[int] -reveal_type(g(a)) # E: Revealed type is 'builtins.int' -reveal_type(g(b)) # E: Revealed type is 'builtins.str' -reveal_type(g(c)) # E: Revealed type is 'Union[builtins.str, builtins.int]' +reveal_type(g(a)) # N: Revealed type is 'builtins.int' +reveal_type(g(b)) # N: Revealed type is 'builtins.str' +reveal_type(g(c)) # N: Revealed type is 'Union[builtins.str, builtins.int]' [case testOverloadsNoneAndTypeVarsWithNoStrictOptional] # flags: --no-strict-optional @@ -3534,9 +3534,9 @@ f1: Callable[[int], str] f2: None f3: Optional[Callable[[int], str]] -reveal_type(mymap(f1, seq)) # E: Revealed type is 'typing.Iterable[builtins.str*]' -reveal_type(mymap(f2, seq)) # E: Revealed type is 'typing.Iterable[builtins.int*]' -reveal_type(mymap(f3, seq)) # E: Revealed type is 'typing.Iterable[builtins.str*]' +reveal_type(mymap(f1, seq)) # N: Revealed type is 'typing.Iterable[builtins.str*]' +reveal_type(mymap(f2, seq)) # N: Revealed type is 'typing.Iterable[builtins.int*]' +reveal_type(mymap(f3, seq)) # N: Revealed type is 'typing.Iterable[builtins.str*]' [builtins fixtures/list.pyi] [typing fixtures/typing-full.pyi] @@ -3559,9 +3559,9 @@ f1: Callable[[int], str] f2: None f3: Optional[Callable[[int], str]] -reveal_type(mymap(f1, seq)) # E: Revealed type is 'typing.Iterable[builtins.str*]' -reveal_type(mymap(f2, seq)) # E: Revealed type is 'typing.Iterable[builtins.int*]' -reveal_type(mymap(f3, seq)) # E: Revealed type is 'Union[typing.Iterable[builtins.str*], typing.Iterable[builtins.int*]]' +reveal_type(mymap(f1, seq)) # N: Revealed type is 'typing.Iterable[builtins.str*]' +reveal_type(mymap(f2, seq)) # N: Revealed type is 'typing.Iterable[builtins.int*]' +reveal_type(mymap(f3, seq)) # N: Revealed type is 'Union[typing.Iterable[builtins.str*], typing.Iterable[builtins.int*]]' [builtins fixtures/list.pyi] [typing fixtures/typing-full.pyi] @@ -3582,12 +3582,12 @@ def test_narrow_int() -> None: a: Union[int, str] if int(): a = narrow_int(a) - reveal_type(a) # E: Revealed type is 'builtins.int' + reveal_type(a) # N: Revealed type is 'builtins.int' b: int if int(): b = narrow_int(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: str if int(): @@ -3614,12 +3614,12 @@ def test_narrow_int() -> None: a: Union[int, str] if int(): a = narrow_int(a) - reveal_type(a) # E: Revealed type is 'builtins.int' + reveal_type(a) # N: Revealed type is 'builtins.int' b: int if int(): b = narrow_int(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: str if int(): @@ -3647,12 +3647,12 @@ def test_narrow_none() -> None: a: Optional[int] if int(): a = narrow_none(a) - reveal_type(a) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(a) # N: Revealed type is 'Union[builtins.int, None]' b: int if int(): b = narrow_none(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: None if int(): @@ -3679,12 +3679,12 @@ def test_narrow_none() -> None: a: Optional[int] if int(): a = narrow_none(a) - reveal_type(a) # E: Revealed type is 'builtins.int' + reveal_type(a) # N: Revealed type is 'builtins.int' b: int if int(): b = narrow_none(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: None if int(): @@ -3711,12 +3711,12 @@ def test_narrow_none_v2() -> None: a: Optional[int] if int(): a = narrow_none_v2(a) - reveal_type(a) # E: Revealed type is 'Union[builtins.int, None]' + reveal_type(a) # N: Revealed type is 'Union[builtins.int, None]' b: int if int(): b = narrow_none_v2(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: None if int(): @@ -3742,12 +3742,12 @@ def test_narrow_none_v2() -> None: a: Optional[int] if int(): a = narrow_none_v2(a) - reveal_type(a) # E: Revealed type is 'builtins.int' + reveal_type(a) # N: Revealed type is 'builtins.int' b: int if int(): b = narrow_none_v2(b) - reveal_type(b) # E: Revealed type is 'builtins.int' + reveal_type(b) # N: Revealed type is 'builtins.int' c: None if int(): @@ -3777,7 +3777,7 @@ def test() -> None: val: Union[A, B] if int(): val = narrow_to_not_a(val) - reveal_type(val) # E: Revealed type is '__main__.B' + reveal_type(val) # N: Revealed type is '__main__.B' val2: A if int(): @@ -3806,7 +3806,7 @@ def narrow_to_not_a_v2(x: T) -> T: def test_v2(val: Union[A, B], val2: A) -> None: if int(): val = narrow_to_not_a_v2(val) - reveal_type(val) # E: Revealed type is '__main__.B' + reveal_type(val) # N: Revealed type is '__main__.B' if int(): val2 = narrow_to_not_a_v2(val2) @@ -3834,11 +3834,11 @@ class NumberAttribute: class MyModel: my_number = NumberAttribute() -reveal_type(MyModel().my_number) # E: Revealed type is 'builtins.int' +reveal_type(MyModel().my_number) # N: Revealed type is 'builtins.int' MyModel().my_number.foo() # E: "int" has no attribute "foo" -reveal_type(MyModel.my_number) # E: Revealed type is '__main__.NumberAttribute' -reveal_type(MyModel.my_number.foo()) # E: Revealed type is 'builtins.str' +reveal_type(MyModel.my_number) # N: Revealed type is '__main__.NumberAttribute' +reveal_type(MyModel.my_number.foo()) # N: Revealed type is 'builtins.str' [builtins fixtures/isinstance.pyi] [typing fixtures/typing-full.pyi] @@ -3874,14 +3874,14 @@ class NumberAttribute(Generic[T]): class MyModel: my_number = NumberAttribute[MyModel]() -reveal_type(MyModel().my_number) # E: Revealed type is 'builtins.int' +reveal_type(MyModel().my_number) # N: Revealed type is 'builtins.int' MyModel().my_number.foo() # E: "int" has no attribute "foo" -reveal_type(MyModel.my_number) # E: Revealed type is '__main__.NumberAttribute[__main__.MyModel*]' -reveal_type(MyModel.my_number.foo()) # E: Revealed type is 'builtins.str' +reveal_type(MyModel.my_number) # N: Revealed type is '__main__.NumberAttribute[__main__.MyModel*]' +reveal_type(MyModel.my_number.foo()) # N: Revealed type is 'builtins.str' -reveal_type(NumberAttribute[MyModel]().__get__(None, MyModel)) # E: Revealed type is '__main__.NumberAttribute[__main__.MyModel*]' -reveal_type(NumberAttribute[str]().__get__(None, str)) # E: Revealed type is '__main__.NumberAttribute[builtins.str*]' +reveal_type(NumberAttribute[MyModel]().__get__(None, MyModel)) # N: Revealed type is '__main__.NumberAttribute[__main__.MyModel*]' +reveal_type(NumberAttribute[str]().__get__(None, str)) # N: Revealed type is '__main__.NumberAttribute[builtins.str*]' [builtins fixtures/isinstance.pyi] [typing fixtures/typing-full.pyi] @@ -3924,7 +3924,7 @@ def add_proxy(x, y): # The lambda definition is a syntax error in Python 3 tup = (1, '2') -reveal_type(foo(lambda (x, y): add_proxy(x, y), tup)) # E: Revealed type is 'builtins.str*' +reveal_type(foo(lambda (x, y): add_proxy(x, y), tup)) # N: Revealed type is 'builtins.str*' [builtins fixtures/primitives.pyi] [case testOverloadWithClassMethods] @@ -3940,8 +3940,8 @@ class Wrapper: @classmethod def foo(cls, x): pass -reveal_type(Wrapper.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(Wrapper.foo("foo")) # E: Revealed type is 'builtins.str' +reveal_type(Wrapper.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(Wrapper.foo("foo")) # N: Revealed type is 'builtins.str' [builtins fixtures/classmethod.pyi] @@ -4013,8 +4013,8 @@ class Wrapper3: def foo(cls, x): pass -reveal_type(Wrapper1.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(Wrapper2.foo(3)) # E: Revealed type is 'builtins.int' +reveal_type(Wrapper1.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(Wrapper2.foo(3)) # N: Revealed type is 'builtins.int' [builtins fixtures/classmethod.pyi] @@ -4128,8 +4128,8 @@ class Wrapper: @classmethod # E: Overloaded function implementation cannot produce return type of signature 1 def foo(cls, x: Union[int, str]) -> str: - reveal_type(cls) # E: Revealed type is 'Type[__main__.Wrapper]' - reveal_type(cls.other()) # E: Revealed type is 'builtins.str' + reveal_type(cls) # N: Revealed type is 'Type[__main__.Wrapper]' + reveal_type(cls.other()) # N: Revealed type is 'builtins.str' return "..." [builtins fixtures/classmethod.pyi] @@ -4147,8 +4147,8 @@ class Wrapper: @staticmethod def foo(x): pass -reveal_type(Wrapper.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(Wrapper.foo("foo")) # E: Revealed type is 'builtins.str' +reveal_type(Wrapper.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(Wrapper.foo("foo")) # N: Revealed type is 'builtins.str' [builtins fixtures/staticmethod.pyi] @@ -4221,8 +4221,8 @@ class Wrapper3: @staticmethod def foo(x): pass -reveal_type(Wrapper1.foo(3)) # E: Revealed type is 'builtins.int' -reveal_type(Wrapper2.foo(3)) # E: Revealed type is 'builtins.int' +reveal_type(Wrapper1.foo(3)) # N: Revealed type is 'builtins.int' +reveal_type(Wrapper2.foo(3)) # N: Revealed type is 'builtins.int' [builtins fixtures/staticmethod.pyi] @@ -4351,7 +4351,7 @@ def f(x): pass x: Union[int, str] -reveal_type(f(x)) # E: Revealed type is 'builtins.int' +reveal_type(f(x)) # N: Revealed type is 'builtins.int' [out] [case testOverloadAndSelfTypes] @@ -4366,7 +4366,7 @@ class Parent: def foo(self, x: str) -> str: pass def foo(self: T, x: Union[int, str]) -> Union[T, str]: - reveal_type(self.bar()) # E: Revealed type is 'builtins.str' + reveal_type(self.bar()) # N: Revealed type is 'builtins.str' return self def bar(self) -> str: pass @@ -4375,11 +4375,11 @@ class Child(Parent): def child_only(self) -> int: pass x: Union[int, str] -reveal_type(Parent().foo(3)) # E: Revealed type is '__main__.Parent*' -reveal_type(Child().foo(3)) # E: Revealed type is '__main__.Child*' -reveal_type(Child().foo("...")) # E: Revealed type is 'builtins.str' -reveal_type(Child().foo(x)) # E: Revealed type is 'Union[__main__.Child*, builtins.str]' -reveal_type(Child().foo(3).child_only()) # E: Revealed type is 'builtins.int' +reveal_type(Parent().foo(3)) # N: Revealed type is '__main__.Parent*' +reveal_type(Child().foo(3)) # N: Revealed type is '__main__.Child*' +reveal_type(Child().foo("...")) # N: Revealed type is 'builtins.str' +reveal_type(Child().foo(x)) # N: Revealed type is 'Union[__main__.Child*, builtins.str]' +reveal_type(Child().foo(3).child_only()) # N: Revealed type is 'builtins.int' [case testOverloadAndClassTypes] from typing import overload, Union, TypeVar, Type @@ -4396,7 +4396,7 @@ class Parent: @classmethod def foo(cls: Type[T], x: Union[int, str]) -> Union[Type[T], str]: - reveal_type(cls.bar()) # E: Revealed type is 'builtins.str' + reveal_type(cls.bar()) # N: Revealed type is 'builtins.str' return cls @classmethod @@ -4406,11 +4406,11 @@ class Child(Parent): def child_only(self) -> int: pass x: Union[int, str] -reveal_type(Parent.foo(3)) # E: Revealed type is 'Type[__main__.Parent*]' -reveal_type(Child.foo(3)) # E: Revealed type is 'Type[__main__.Child*]' -reveal_type(Child.foo("...")) # E: Revealed type is 'builtins.str' -reveal_type(Child.foo(x)) # E: Revealed type is 'Union[Type[__main__.Child*], builtins.str]' -reveal_type(Child.foo(3)().child_only()) # E: Revealed type is 'builtins.int' +reveal_type(Parent.foo(3)) # N: Revealed type is 'Type[__main__.Parent*]' +reveal_type(Child.foo(3)) # N: Revealed type is 'Type[__main__.Child*]' +reveal_type(Child.foo("...")) # N: Revealed type is 'builtins.str' +reveal_type(Child.foo(x)) # N: Revealed type is 'Union[Type[__main__.Child*], builtins.str]' +reveal_type(Child.foo(3)().child_only()) # N: Revealed type is 'builtins.int' [builtins fixtures/classmethod.pyi] [case testOptionalIsNotAUnionIfNoStrictOverload] @@ -4428,7 +4428,7 @@ def rp(x): pass x: Optional[C] -reveal_type(rp(x)) # E: Revealed type is '__main__.C' +reveal_type(rp(x)) # N: Revealed type is '__main__.C' [out] [case testOptionalIsNotAUnionIfNoStrictOverloadStr] @@ -4437,7 +4437,7 @@ reveal_type(rp(x)) # E: Revealed type is '__main__.C' from typing import Optional from m import relpath a = '' # type: Optional[str] -reveal_type(relpath(a)) # E: Revealed type is 'builtins.str' +reveal_type(relpath(a)) # N: Revealed type is 'builtins.str' [file m.pyi] from typing import overload @@ -4479,7 +4479,7 @@ class D(C): x: D y: Union[D, Any] -reveal_type(x.f(y)) # E: Revealed type is 'Union[__main__.D, Any]' +reveal_type(x.f(y)) # N: Revealed type is 'Union[__main__.D, Any]' [out] [case testManyUnionsInOverload] @@ -4501,7 +4501,7 @@ class B: pass x: Union[int, str, A, B] y = f(x, x, x, x, x, x, x, x) # 8 args -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str, __main__.A, __main__.B]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str, __main__.A, __main__.B]' [builtins fixtures/dict.pyi] [out] @@ -4622,7 +4622,7 @@ class Other: return NotImplemented actually_b: A = B() -reveal_type(actually_b + Other()) # E: Revealed type is '__main__.Other' +reveal_type(actually_b + Other()) # N: Revealed type is '__main__.Other' # Runtime type is B, this is why we report the error on overriding. [builtins fixtures/isinstance.pyi] [out] @@ -4671,7 +4671,7 @@ g(3) # E: No overload variant of "g" matches argument type "int" \ from lib import f, g for fun in [f, g]: - reveal_type(fun) # E: Revealed type is 'Overload(def (x: builtins.int) -> builtins.str, def (x: builtins.str) -> builtins.int)' + reveal_type(fun) # N: Revealed type is 'Overload(def (x: builtins.int) -> builtins.str, def (x: builtins.str) -> builtins.int)' [file lib.pyi] from typing import overload @@ -4719,7 +4719,7 @@ def f() -> None: # N: Possible overload variant: \ # N: def [T] g(x: T, y: int) -> T \ # N: <1 more non-matching overload not shown> - reveal_type(g(str(), int())) # E: Revealed type is 'builtins.str*' + reveal_type(g(str(), int())) # N: Revealed type is 'builtins.str*' [out] [case testNestedOverloadsTypeVarOverlap] @@ -4748,14 +4748,14 @@ def f() -> None: @overload def g(x: T) -> Dict[int, T]: ... def g(*args, **kwargs) -> Any: - reveal_type(h(C())) # E: Revealed type is 'builtins.dict[builtins.str, __main__.C*]' + reveal_type(h(C())) # N: Revealed type is 'builtins.dict[builtins.str, __main__.C*]' @overload def h() -> None: ... @overload def h(x: T) -> Dict[str, T]: ... def h(*args, **kwargs) -> Any: - reveal_type(g(C())) # E: Revealed type is 'builtins.dict[builtins.int, __main__.C*]' + reveal_type(g(C())) # N: Revealed type is 'builtins.dict[builtins.int, __main__.C*]' [builtins fixtures/dict.pyi] [out] @@ -4764,10 +4764,10 @@ def f() -> None: from lib import attr from typing import Any -reveal_type(attr(1)) # E: Revealed type is 'builtins.int*' -reveal_type(attr("hi")) # E: Revealed type is 'builtins.int' +reveal_type(attr(1)) # N: Revealed type is 'builtins.int*' +reveal_type(attr("hi")) # N: Revealed type is 'builtins.int' x: Any -reveal_type(attr(x)) # E: Revealed type is 'Any' +reveal_type(attr(x)) # N: Revealed type is 'Any' attr("hi", 1) # E: No overload variant of "attr" matches argument types "str", "int" \ # N: Possible overload variant: \ # N: def [T in (int, float)] attr(default: T = ..., blah: int = ...) -> T \ @@ -4787,10 +4787,10 @@ def attr(default: Any = ...) -> int: ... from lib import attr from typing import Any -reveal_type(attr(1)) # E: Revealed type is 'builtins.int*' -reveal_type(attr("hi")) # E: Revealed type is 'builtins.int' +reveal_type(attr(1)) # N: Revealed type is 'builtins.int*' +reveal_type(attr("hi")) # N: Revealed type is 'builtins.int' x: Any -reveal_type(attr(x)) # E: Revealed type is 'Any' +reveal_type(attr(x)) # N: Revealed type is 'Any' attr("hi", 1) # E: No overload variant of "attr" matches argument types "str", "int" \ # N: Possible overload variant: \ # N: def [T <: int] attr(default: T = ..., blah: int = ...) -> T \ @@ -4839,10 +4839,10 @@ def f(x: Child) -> List[Child]: pass # E: Overloaded function signatures 1 an def f(x: Parent) -> List[Parent]: pass def f(x: Union[Child, Parent]) -> Union[List[Child], List[Parent]]: if isinstance(x, Child): - reveal_type(x) # E: Revealed type is '__main__.Child' + reveal_type(x) # N: Revealed type is '__main__.Child' return children else: - reveal_type(x) # E: Revealed type is '__main__.Parent' + reveal_type(x) # N: Revealed type is '__main__.Parent' return parents ints: List[int] @@ -4854,10 +4854,10 @@ def g(x: int) -> List[int]: pass def g(x: float) -> List[float]: pass def g(x: Union[int, float]) -> Union[List[int], List[float]]: if isinstance(x, int): - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' return ints else: - reveal_type(x) # E: Revealed type is 'builtins.float' + reveal_type(x) # N: Revealed type is 'builtins.float' return floats [builtins fixtures/isinstancelist.pyi] @@ -4898,13 +4898,13 @@ a = multiple_plausible(Other()) # E: No overload variant of "multiple_plausible # N: Possible overload variants: \ # N: def multiple_plausible(x: int) -> int \ # N: def multiple_plausible(x: str) -> str -reveal_type(a) # E: Revealed type is 'Any' +reveal_type(a) # N: Revealed type is 'Any' b = single_plausible(Other) # E: Argument 1 to "single_plausible" has incompatible type "Type[Other]"; expected "Type[int]" -reveal_type(b) # E: Revealed type is 'builtins.int' +reveal_type(b) # N: Revealed type is 'builtins.int' c = single_plausible([Other()]) # E: List item 0 has incompatible type "Other"; expected "str" -reveal_type(c) # E: Revealed type is 'builtins.str' +reveal_type(c) # N: Revealed type is 'builtins.str' [builtins fixtures/list.pyi] [case testDisallowUntypedDecoratorsOverload] @@ -4928,8 +4928,8 @@ def f(name: str) -> int: def g(name: str) -> int: return 0 -reveal_type(f) # E: Revealed type is 'def (name: builtins.str) -> builtins.int' -reveal_type(g) # E: Revealed type is 'def (name: builtins.str) -> builtins.int' +reveal_type(f) # N: Revealed type is 'def (name: builtins.str) -> builtins.int' +reveal_type(g) # N: Revealed type is 'def (name: builtins.str) -> builtins.int' [case testOverloadBadArgumentsInferredToAny1] from typing import Union, Any, overload @@ -4975,7 +4975,7 @@ def f(x: int) -> int: ... def f(x: List[int]) -> List[int]: ... def f(x): pass -reveal_type(f(g())) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(g())) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testOverloadInferringArgumentsUsingContext2-skip] @@ -4999,7 +4999,7 @@ def f(x: List[int]) -> List[int]: ... def f(x): pass -reveal_type(f(g([]))) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(f(g([]))) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/list.pyi] [case testOverloadDeferredNode] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 55ca33873748..636396a52152 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -107,7 +107,7 @@ z = x x = C() x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "SubP") -reveal_type(fun(C())) # E: Revealed type is 'builtins.str' +reveal_type(fun(C())) # N: Revealed type is 'builtins.str' fun(B()) # E: Argument 1 to "fun" has incompatible type "B"; expected "SubP" [case testSimpleProtocolTwoMethodsMerge] @@ -141,8 +141,8 @@ class AnotherP(Protocol): pass x: P -reveal_type(x.meth1()) # E: Revealed type is 'builtins.int' -reveal_type(x.meth2()) # E: Revealed type is 'builtins.str' +reveal_type(x.meth1()) # N: Revealed type is 'builtins.int' +reveal_type(x.meth2()) # N: Revealed type is 'builtins.str' c: C c1: C1 @@ -185,8 +185,8 @@ class C: pass x: P2 -reveal_type(x.meth1()) # E: Revealed type is 'builtins.int' -reveal_type(x.meth2()) # E: Revealed type is 'builtins.str' +reveal_type(x.meth1()) # N: Revealed type is 'builtins.int' +reveal_type(x.meth2()) # N: Revealed type is 'builtins.str' if int(): x = C() # OK @@ -368,8 +368,8 @@ class P(Protocol): x: object if isinstance(x, P): - reveal_type(x) # E: Revealed type is '__main__.P' - reveal_type(x.meth()) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is '__main__.P' + reveal_type(x.meth()) # N: Revealed type is 'builtins.int' class C: def meth(self) -> int: @@ -392,7 +392,7 @@ class P2(P, D, Protocol): # E: All bases of a protocol must be protocols P2() # E: Cannot instantiate abstract class 'P2' with abstract attribute 'attr' p: P2 -reveal_type(p.attr) # E: Revealed type is 'builtins.int' +reveal_type(p.attr) # N: Revealed type is 'builtins.int' -- Generic protocol types -- ---------------------- @@ -513,10 +513,10 @@ def close_all(args: Sequence[Closeable[T]]) -> T: arg: Closeable[int] -reveal_type(close(F())) # E: Revealed type is 'builtins.int*' -reveal_type(close(arg)) # E: Revealed type is 'builtins.int*' -reveal_type(close_all([F()])) # E: Revealed type is 'builtins.int*' -reveal_type(close_all([arg])) # E: Revealed type is 'builtins.int*' +reveal_type(close(F())) # N: Revealed type is 'builtins.int*' +reveal_type(close(arg)) # N: Revealed type is 'builtins.int*' +reveal_type(close_all([F()])) # N: Revealed type is 'builtins.int*' +reveal_type(close_all([arg])) # N: Revealed type is 'builtins.int*' [builtins fixtures/isinstancelist.pyi] [typing fixtures/typing-full.pyi] @@ -535,7 +535,7 @@ class C: def fun3(x: P[T, T]) -> T: pass -reveal_type(fun3(C())) # E: Revealed type is 'builtins.int*' +reveal_type(fun3(C())) # N: Revealed type is 'builtins.int*' [case testProtocolGenericInferenceCovariant] from typing import Generic, TypeVar, Protocol @@ -553,7 +553,7 @@ class C: def fun4(x: U, y: P[U, U]) -> U: pass -reveal_type(fun4('a', C())) # E: Revealed type is 'builtins.object*' +reveal_type(fun4('a', C())) # N: Revealed type is 'builtins.object*' [case testUnrealtedGenericProtolsEquivalent] from typing import TypeVar, Protocol @@ -800,7 +800,7 @@ class L: def last(seq: Linked[T]) -> T: pass -reveal_type(last(L())) # E: Revealed type is 'builtins.int*' +reveal_type(last(L())) # N: Revealed type is 'builtins.int*' [builtins fixtures/list.pyi] [case testRecursiveProtocolSubtleMismatch] @@ -1128,7 +1128,7 @@ class P(Protocol): class C(P): pass x = C() -reveal_type(x.meth('hi')) # E: Revealed type is 'builtins.bool' +reveal_type(x.meth('hi')) # N: Revealed type is 'builtins.bool' [builtins fixtures/isinstance.pyi] [case testProtocolsWithIdenticalOverloads] @@ -1200,9 +1200,9 @@ y: P2 l0 = [x, x] l1 = [y, y] l = [x, y] -reveal_type(l0) # E: Revealed type is 'builtins.list[__main__.P*]' -reveal_type(l1) # E: Revealed type is 'builtins.list[__main__.P2*]' -reveal_type(l) # E: Revealed type is 'builtins.list[__main__.P*]' +reveal_type(l0) # N: Revealed type is 'builtins.list[__main__.P*]' +reveal_type(l1) # N: Revealed type is 'builtins.list[__main__.P2*]' +reveal_type(l) # N: Revealed type is 'builtins.list[__main__.P*]' [builtins fixtures/list.pyi] [case testJoinOfIncompatibleProtocols] @@ -1215,7 +1215,7 @@ class P2(Protocol): x: P y: P2 -reveal_type([x, y]) # E: Revealed type is 'builtins.list[builtins.object*]' +reveal_type([x, y]) # N: Revealed type is 'builtins.list[builtins.object*]' [builtins fixtures/list.pyi] [case testJoinProtocolWithNormal] @@ -1232,7 +1232,7 @@ y: C l = [x, y] -reveal_type(l) # E: Revealed type is 'builtins.list[__main__.P*]' +reveal_type(l) # N: Revealed type is 'builtins.list[__main__.P*]' [builtins fixtures/list.pyi] [case testMeetProtocolWithProtocol] @@ -1247,7 +1247,7 @@ class P2(Protocol): T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: P, y: P2) -> None: pass -reveal_type(f(g)) # E: Revealed type is '__main__.P2*' +reveal_type(f(g)) # N: Revealed type is '__main__.P2*' [case testMeetOfIncompatibleProtocols] from typing import Protocol, Callable, TypeVar @@ -1261,7 +1261,7 @@ T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: P, y: P2) -> None: pass x = f(g) -reveal_type(x) # E: Revealed type is 'None' +reveal_type(x) # N: Revealed type is 'None' [case testMeetProtocolWithNormal] from typing import Protocol, Callable, TypeVar @@ -1273,7 +1273,7 @@ class C: T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: P, y: C) -> None: pass -reveal_type(f(g)) # E: Revealed type is '__main__.C*' +reveal_type(f(g)) # N: Revealed type is '__main__.C*' [case testInferProtocolFromProtocol] from typing import Protocol, Sequence, TypeVar, Generic @@ -1292,8 +1292,8 @@ class L(Generic[T]): def last(seq: Linked[T]) -> T: pass -reveal_type(last(L[int]())) # E: Revealed type is '__main__.Box*[builtins.int*]' -reveal_type(last(L[str]()).content) # E: Revealed type is 'builtins.str*' +reveal_type(last(L[int]())) # N: Revealed type is '__main__.Box*[builtins.int*]' +reveal_type(last(L[str]()).content) # N: Revealed type is 'builtins.str*' [case testOverloadOnProtocol] from typing import overload, Protocol, runtime @@ -1320,11 +1320,11 @@ def f(x): if isinstance(x, P2): # E: Only @runtime protocols can be used with instance and class checks return P1.attr2 -reveal_type(f(C1())) # E: Revealed type is 'builtins.int' -reveal_type(f(C2())) # E: Revealed type is 'builtins.str' +reveal_type(f(C1())) # N: Revealed type is 'builtins.int' +reveal_type(f(C2())) # N: Revealed type is 'builtins.str' class D(C1, C2): pass # Compatible with both P1 and P2 # TODO: Should this return a union instead? -reveal_type(f(D())) # E: Revealed type is 'builtins.int' +reveal_type(f(D())) # N: Revealed type is 'builtins.int' f(C()) # E: No overload variant of "f" matches argument type "C" \ # N: Possible overload variants: \ # N: def f(x: P1) -> int \ @@ -1502,11 +1502,11 @@ class R(Protocol): x: object if isinstance(x, P): # E: Only @runtime protocols can be used with instance and class checks - reveal_type(x) # E: Revealed type is '__main__.P' + reveal_type(x) # N: Revealed type is '__main__.P' if isinstance(x, R): - reveal_type(x) # E: Revealed type is '__main__.R' - reveal_type(x.meth()) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is '__main__.R' + reveal_type(x.meth()) # N: Revealed type is 'builtins.int' [builtins fixtures/isinstance.pyi] [typing fixtures/typing-full.pyi] @@ -1516,7 +1516,7 @@ from typing import Iterable, List, Union x: Union[int, List[str]] if isinstance(x, Iterable): - reveal_type(x) # E: Revealed type is 'builtins.list[builtins.str]' + reveal_type(x) # N: Revealed type is 'builtins.list[builtins.str]' [builtins fixtures/isinstancelist.pyi] [typing fixtures/typing-full.pyi] @@ -1547,35 +1547,35 @@ class C(C1[int], C2): pass c = C() if isinstance(c, P1): - reveal_type(c) # E: Revealed type is '__main__.C' + reveal_type(c) # N: Revealed type is '__main__.C' else: reveal_type(c) # Unreachable if isinstance(c, P): - reveal_type(c) # E: Revealed type is '__main__.C' + reveal_type(c) # N: Revealed type is '__main__.C' else: reveal_type(c) # Unreachable c1i: C1[int] if isinstance(c1i, P1): - reveal_type(c1i) # E: Revealed type is '__main__.C1[builtins.int]' + reveal_type(c1i) # N: Revealed type is '__main__.C1[builtins.int]' else: reveal_type(c1i) # Unreachable if isinstance(c1i, P): reveal_type(c1i) # Unreachable else: - reveal_type(c1i) # E: Revealed type is '__main__.C1[builtins.int]' + reveal_type(c1i) # N: Revealed type is '__main__.C1[builtins.int]' c1s: C1[str] if isinstance(c1s, P1): reveal_type(c1s) # Unreachable else: - reveal_type(c1s) # E: Revealed type is '__main__.C1[builtins.str]' + reveal_type(c1s) # N: Revealed type is '__main__.C1[builtins.str]' c2: C2 if isinstance(c2, P): reveal_type(c2) # Unreachable else: - reveal_type(c2) # E: Revealed type is '__main__.C2' + reveal_type(c2) # N: Revealed type is '__main__.C2' [builtins fixtures/isinstancelist.pyi] [typing fixtures/typing-full.pyi] @@ -1603,14 +1603,14 @@ class C2: x: Union[C1[int], C2] if isinstance(x, P1): - reveal_type(x) # E: Revealed type is '__main__.C1[builtins.int]' + reveal_type(x) # N: Revealed type is '__main__.C1[builtins.int]' else: - reveal_type(x) # E: Revealed type is '__main__.C2' + reveal_type(x) # N: Revealed type is '__main__.C2' if isinstance(x, P2): - reveal_type(x) # E: Revealed type is '__main__.C2' + reveal_type(x) # N: Revealed type is '__main__.C2' else: - reveal_type(x) # E: Revealed type is '__main__.C1[builtins.int]' + reveal_type(x) # N: Revealed type is '__main__.C1[builtins.int]' [builtins fixtures/isinstancelist.pyi] [typing fixtures/typing-full.pyi] @@ -1675,9 +1675,9 @@ fun(N2(1)) # E: Argument 1 to "fun" has incompatible type "N2"; expected "P[int, # N: 'N2' is missing following 'P' protocol member: \ # N: y -reveal_type(fun3(z)) # E: Revealed type is 'builtins.object*' +reveal_type(fun3(z)) # N: Revealed type is 'builtins.object*' -reveal_type(fun3(z3)) # E: Revealed type is 'builtins.int*' +reveal_type(fun3(z3)) # N: Revealed type is 'builtins.int*' [builtins fixtures/list.pyi] [case testBasicCallableStructuralSubtyping] @@ -1696,7 +1696,7 @@ T = TypeVar('T') def apply_gen(f: Callable[[T], T]) -> T: pass -reveal_type(apply_gen(Add5())) # E: Revealed type is 'builtins.int*' +reveal_type(apply_gen(Add5())) # N: 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]" \ @@ -1737,7 +1737,7 @@ def inc(a: int, temp: str) -> int: def foo(f: Callable[[int], T]) -> T: return f(1) -reveal_type(foo(partial(inc, 'temp'))) # E: Revealed type is 'builtins.int*' +reveal_type(foo(partial(inc, 'temp'))) # N: Revealed type is 'builtins.int*' [builtins fixtures/list.pyi] [case testStructuralInferenceForCallable] @@ -1750,7 +1750,7 @@ class Actual: def __call__(self, arg: int) -> str: pass def fun(cb: Callable[[T], S]) -> Tuple[T, S]: pass -reveal_type(fun(Actual())) # E: Revealed type is 'Tuple[builtins.int*, builtins.str*]' +reveal_type(fun(Actual())) # N: Revealed type is 'Tuple[builtins.int*, builtins.str*]' [builtins fixtures/tuple.pyi] -- Standard protocol types (SupportsInt, Sized, etc.) @@ -1875,8 +1875,8 @@ class A: class B(A): pass -reveal_type(list(b for b in B())) # E: Revealed type is 'builtins.list[__main__.B*]' -reveal_type(list(B())) # E: Revealed type is 'builtins.list[__main__.B*]' +reveal_type(list(b for b in B())) # N: Revealed type is 'builtins.list[__main__.B*]' +reveal_type(list(B())) # N: Revealed type is 'builtins.list[__main__.B*]' [builtins fixtures/list.pyi] [case testIterableProtocolOnMetaclass] @@ -1892,8 +1892,8 @@ class E(metaclass=EMeta): class C(E): pass -reveal_type(list(c for c in C)) # E: Revealed type is 'builtins.list[__main__.C*]' -reveal_type(list(C)) # E: Revealed type is 'builtins.list[__main__.C*]' +reveal_type(list(c for c in C)) # N: Revealed type is 'builtins.list[__main__.C*]' +reveal_type(list(C)) # N: Revealed type is 'builtins.list[__main__.C*]' [builtins fixtures/list.pyi] [case testClassesGetattrWithProtocols] @@ -1919,9 +1919,9 @@ class D: pass def fun(x: P) -> None: - reveal_type(P.attr) # E: Revealed type is 'builtins.int' + reveal_type(P.attr) # N: Revealed type is 'builtins.int' def fun_p(x: PP) -> None: - reveal_type(P.attr) # E: Revealed type is 'builtins.int' + reveal_type(P.attr) # N: Revealed type is 'builtins.int' fun(C()) # E: Argument 1 to "fun" has incompatible type "C"; expected "P" \ # N: Protocol member P.attr expected settable variable, got read-only attribute @@ -2212,9 +2212,9 @@ cls: Type[Union[C, E]] issubclass(cls, PBad) # E: Only protocols that don't have non-method members can be used with issubclass() \ # N: Protocol "PBad" has non-method member(s): x if issubclass(cls, P): - reveal_type(cls) # E: Revealed type is 'Type[__main__.C]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.C]' else: - reveal_type(cls) # E: Revealed type is 'Type[__main__.E]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.E]' [builtins fixtures/isinstance.pyi] [typing fixtures/typing-full.pyi] [out] @@ -2251,7 +2251,7 @@ def call(x: int, y: str) -> Tuple[int, str]: ... def func(caller: Caller[T, S]) -> Tuple[T, S]: pass -reveal_type(func(call)) # E: Revealed type is 'Tuple[builtins.int*, builtins.str*]' +reveal_type(func(call)) # N: Revealed type is 'Tuple[builtins.int*, builtins.str*]' [builtins fixtures/tuple.pyi] [out] @@ -2396,8 +2396,8 @@ Normal = Callable[[A], D] a: Call b: Normal -reveal_type([a, b]) # E: Revealed type is 'builtins.list[def (__main__.B) -> __main__.B]' -reveal_type([b, a]) # E: Revealed type is 'builtins.list[def (__main__.B) -> __main__.B]' +reveal_type([a, b]) # N: Revealed type is 'builtins.list[def (__main__.B) -> __main__.B]' +reveal_type([b, a]) # N: Revealed type is 'builtins.list[def (__main__.B) -> __main__.B]' [builtins fixtures/list.pyi] [out] @@ -2416,8 +2416,8 @@ Normal = Callable[[D], A] def a(x: Call) -> None: ... def b(x: Normal) -> None: ... -reveal_type([a, b]) # E: Revealed type is 'builtins.list[def (x: def (__main__.B) -> __main__.B)]' -reveal_type([b, a]) # E: Revealed type is 'builtins.list[def (x: def (__main__.B) -> __main__.B)]' +reveal_type([a, b]) # N: Revealed type is 'builtins.list[def (x: def (__main__.B) -> __main__.B)]' +reveal_type([b, a]) # N: Revealed type is 'builtins.list[def (x: def (__main__.B) -> __main__.B)]' [builtins fixtures/list.pyi] [out] @@ -2427,7 +2427,7 @@ from typing import Protocol class P(Protocol): ... class C(P): ... -reveal_type(C.register(int)) # E: Revealed type is 'def () -> builtins.int' +reveal_type(C.register(int)) # N: Revealed type is 'def () -> builtins.int' [typing fixtures/typing-full.pyi] [out] diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index fcec1f1d78cc..5022c8ba50e6 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -204,7 +204,7 @@ f((0, 0)) def g(): # type: () -> None pass -reveal_type(lambda (x,): g()) # E: Revealed type is 'def (Any)' +reveal_type(lambda (x,): g()) # N: Revealed type is 'def (Any)' [out] [case testLambdaTupleArgInferenceInPython2] @@ -284,8 +284,8 @@ class M(type): class A(object): __metaclass__ = M -reveal_type(A.x) # E: Revealed type is 'builtins.int' -reveal_type(A.test()) # E: Revealed type is 'builtins.str' +reveal_type(A.x) # N: Revealed type is 'builtins.int' +reveal_type(A.test()) # N: Revealed type is 'builtins.str' [case testImportedMetaclass] import m @@ -293,8 +293,8 @@ import m class A(object): __metaclass__ = m.M -reveal_type(A.x) # E: Revealed type is 'builtins.int' -reveal_type(A.test()) # E: Revealed type is 'builtins.str' +reveal_type(A.x) # N: Revealed type is 'builtins.int' +reveal_type(A.test()) # N: Revealed type is 'builtins.str' [file m.py] class M(type): x = 0 @@ -323,7 +323,7 @@ from missing import M class A(object): __metaclass__ = M y = 0 -reveal_type(A.y) # E: Revealed type is 'builtins.int' +reveal_type(A.y) # N: Revealed type is 'builtins.int' A.x # E: "Type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] diff --git a/test-data/unit/check-python38.test b/test-data/unit/check-python38.test index 3fdebe4ca74b..7c67c2a87566 100644 --- a/test-data/unit/check-python38.test +++ b/test-data/unit/check-python38.test @@ -116,11 +116,11 @@ def f(arg: int = "ERROR", /) -> None: ... # E: Incompatible default for argumen [case testPEP570ArgTypesDefault] def f(arg: int = 0, /) -> None: - reveal_type(arg) # E: Revealed type is 'builtins.int' + reveal_type(arg) # N: Revealed type is 'builtins.int' [case testPEP570ArgTypesRequired] def f(arg: int, /) -> None: - reveal_type(arg) # E: Revealed type is 'builtins.int' + reveal_type(arg) # N: Revealed type is 'builtins.int' [case testPEP570Required] def f(arg: int, /) -> None: ... # N: "f" defined here @@ -146,36 +146,36 @@ f(p=0, p_or_kw=0, kw=0) # E: Unexpected keyword argument "p" for "f" [case testPEP570Signatures1] def f(p1: bytes, p2: float, /, p_or_kw: int, *, kw: str) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.float' - reveal_type(p_or_kw) # E: Revealed type is 'builtins.int' - reveal_type(kw) # E: Revealed type is 'builtins.str' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.float' + reveal_type(p_or_kw) # N: Revealed type is 'builtins.int' + reveal_type(kw) # N: Revealed type is 'builtins.str' [case testPEP570Signatures2] def f(p1: bytes, p2: float = 0.0, /, p_or_kw: int = 0, *, kw: str) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.float' - reveal_type(p_or_kw) # E: Revealed type is 'builtins.int' - reveal_type(kw) # E: Revealed type is 'builtins.str' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.float' + reveal_type(p_or_kw) # N: Revealed type is 'builtins.int' + reveal_type(kw) # N: Revealed type is 'builtins.str' [case testPEP570Signatures3] def f(p1: bytes, p2: float = 0.0, /, *, kw: int) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.float' - reveal_type(kw) # E: Revealed type is 'builtins.int' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.float' + reveal_type(kw) # N: Revealed type is 'builtins.int' [case testPEP570Signatures4] def f(p1: bytes, p2: int = 0, /) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.int' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.int' [case testPEP570Signatures5] def f(p1: bytes, p2: float, /, p_or_kw: int) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.float' - reveal_type(p_or_kw) # E: Revealed type is 'builtins.int' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.float' + reveal_type(p_or_kw) # N: Revealed type is 'builtins.int' [case testPEP570Signatures6] def f(p1: bytes, p2: float, /) -> None: - reveal_type(p1) # E: Revealed type is 'builtins.bytes' - reveal_type(p2) # E: Revealed type is 'builtins.float' + reveal_type(p1) # N: Revealed type is 'builtins.bytes' + reveal_type(p2) # N: Revealed type is 'builtins.float' diff --git a/test-data/unit/check-redefine.test b/test-data/unit/check-redefine.test index 69d4a53777a9..769f33cfe433 100644 --- a/test-data/unit/check-redefine.test +++ b/test-data/unit/check-redefine.test @@ -9,31 +9,31 @@ # flags: --allow-redefinition def f() -> None: x = 0 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [case testCannotConditionallyRedefineLocalWithDifferentType] # flags: --allow-redefinition def f() -> None: y = 0 - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' if int(): y = '' \ # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(y) # E: Revealed type is 'builtins.int' - reveal_type(y) # E: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' + reveal_type(y) # N: Revealed type is 'builtins.int' [case testRedefineFunctionArg] # flags: --allow-redefinition def f(x: int) -> None: g(x) x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' def g(x: int) -> None: if int(): x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' [case testRedefineAnnotationOnly] # flags: --allow-redefinition @@ -41,13 +41,13 @@ def f() -> None: x: int x = '' \ # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' def g() -> None: x: int x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [case testRedefineLocalUsingOldValue] # flags: --allow-redefinition @@ -57,10 +57,10 @@ T = TypeVar('T') def f(x: int) -> None: x = g(x) - reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str]' y = 1 y = g(y) - reveal_type(y) # E: Revealed type is 'Union[builtins.int*, builtins.str]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int*, builtins.str]' def g(x: T) -> Union[T, str]: pass @@ -71,11 +71,11 @@ def f(a: Iterable[int], b: Iterable[str]) -> None: for x in a: x = '' \ # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(x) # E: Revealed type is 'builtins.int*' + reveal_type(x) # N: Revealed type is 'builtins.int*' for x in b: x = 1 \ # E: Incompatible types in assignment (expression has type "int", variable has type "str") - reveal_type(x) # E: Revealed type is 'builtins.str*' + reveal_type(x) # N: Revealed type is 'builtins.str*' def g(a: Iterable[int]) -> None: for x in a: pass @@ -83,7 +83,7 @@ def g(a: Iterable[int]) -> None: def h(a: Iterable[int]) -> None: x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' for x in a: pass [case testCannotRedefineLocalWithinTry] @@ -97,7 +97,7 @@ def f() -> None: # E: Incompatible types in assignment (expression has type "str", variable has type "int") except: pass - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' y = 0 y y = '' @@ -112,7 +112,7 @@ def f() -> None: x g() # Might raise an exception, but we ignore this x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' y = 0 y y = '' @@ -177,9 +177,9 @@ def f() -> None: # flags: --allow-redefinition def f() -> None: x, x = 1, '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' x = object() - reveal_type(x) # E: Revealed type is 'builtins.object' + reveal_type(x) # N: Revealed type is 'builtins.object' def g() -> None: x = 1 @@ -193,7 +193,7 @@ def f() -> None: _, _ = 1, '' if 1: _, _ = '', 1 - reveal_type(_) # E: Revealed type is 'Any' + reveal_type(_) # N: Revealed type is 'Any' [case testRedefineWithBreakAndContinue] # flags: --allow-redefinition @@ -209,7 +209,7 @@ def f() -> None: break x = '' \ # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' y = '' def g() -> None: @@ -224,7 +224,7 @@ def g() -> None: continue x = '' \ # E: Incompatible types in assignment (expression has type "str", variable has type "int") - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' y = '' def h(): pass @@ -252,7 +252,7 @@ def f() -> None: def f() -> None: def x(): pass x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") - reveal_type(x) # E: Revealed type is 'def () -> Any' + reveal_type(x) # N: Revealed type is 'def () -> Any' y = 1 def y(): pass # E: Name 'y' already defined on line 6 @@ -271,7 +271,7 @@ from typing import TypeVar def f() -> None: x = TypeVar('x') x = 1 # E: Invalid assignment target - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' y = 1 # NOTE: '"int" not callable' is due to test stubs y = TypeVar('y') # E: Cannot redefine 'y' as a type variable \ @@ -291,18 +291,18 @@ def f() -> None: # flags: --allow-redefinition def f() -> None: x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' x = '' # type: object - reveal_type(x) # E: Revealed type is 'builtins.object' + reveal_type(x) # N: Revealed type is 'builtins.object' def g() -> None: x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' x: object = '' - reveal_type(x) # E: Revealed type is 'builtins.object' + reveal_type(x) # N: Revealed type is 'builtins.object' def h() -> None: x: int x = 1 - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' x: object x: object = '' # E: Name 'x' already defined on line 16 def farg(x: int) -> None: @@ -317,9 +317,9 @@ def f() -> None: x = 1 if int(): x = '' - reveal_type(x) # E: Revealed type is 'builtins.object' + reveal_type(x) # N: Revealed type is 'builtins.object' x = '' - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' if int(): x = 2 \ # E: Incompatible types in assignment (expression has type "int", variable has type "str") @@ -331,10 +331,10 @@ class A: x = 0 def f(self) -> None: - reveal_type(self.x) # E: Revealed type is 'builtins.int' + reveal_type(self.x) # N: Revealed type is 'builtins.int' self = f() self.y: str = '' - reveal_type(self.y) # E: Revealed type is 'builtins.str' + reveal_type(self.y) # N: Revealed type is 'builtins.str' def f() -> A: return A() @@ -355,10 +355,10 @@ reveal_type(x) x = '' reveal_type(x) [out] -tmp/m.py:2: error: Revealed type is 'builtins.int' -tmp/m.py:4: error: Revealed type is 'builtins.object' -tmp/m.py:6: error: Revealed type is 'builtins.str' -main:3: error: Revealed type is 'builtins.str' +tmp/m.py:2: note: Revealed type is 'builtins.int' +tmp/m.py:4: note: Revealed type is 'builtins.object' +tmp/m.py:6: note: Revealed type is 'builtins.str' +main:3: note: Revealed type is 'builtins.str' [case testRedefineGlobalForIndex] # flags: --allow-redefinition @@ -375,10 +375,10 @@ for x in it2: reveal_type(x) reveal_type(x) [out] -tmp/m.py:6: error: Revealed type is 'builtins.int*' -tmp/m.py:8: error: Revealed type is 'builtins.str*' -tmp/m.py:9: error: Revealed type is 'builtins.str*' -main:3: error: Revealed type is 'builtins.str*' +tmp/m.py:6: note: Revealed type is 'builtins.int*' +tmp/m.py:8: note: Revealed type is 'builtins.str*' +tmp/m.py:9: note: Revealed type is 'builtins.str*' +main:3: note: Revealed type is 'builtins.str*' [case testRedefineGlobalBasedOnPreviousValues] # flags: --allow-redefinition @@ -387,18 +387,18 @@ T = TypeVar('T') def f(x: T) -> Iterable[T]: pass a = 0 a = f(a) -reveal_type(a) # E: Revealed type is 'typing.Iterable[builtins.int*]' +reveal_type(a) # N: Revealed type is 'typing.Iterable[builtins.int*]' [case testRedefineGlobalWithSeparateDeclaration] # flags: --allow-redefinition x = '' -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' x: int x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' x: object x = 1 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' if int(): x = object() @@ -408,10 +408,10 @@ from typing import Iterable, TypeVar, Union T = TypeVar('T') def f(x: T) -> Iterable[Union[T, str]]: pass x = 0 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' for x in f(x): pass -reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str]' [case testNoRedefinitionIfOnlyInitialized] # flags: --allow-redefinition --no-strict-optional @@ -428,7 +428,7 @@ y = '' # E: Incompatible types in assignment (expression has type "str", variabl # flags: --allow-redefinition x: int x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' x: object [case testNoRedefinitionIfExplicitlyDisallowed] @@ -452,13 +452,13 @@ def g() -> None: [case testRedefineAsException] # flags: --allow-redefinition e = 1 -reveal_type(e) # E: Revealed type is 'builtins.int' +reveal_type(e) # N: Revealed type is 'builtins.int' try: pass except Exception as e: - reveal_type(e) # E: Revealed type is 'builtins.Exception' + reveal_type(e) # N: Revealed type is 'builtins.Exception' e = '' -reveal_type(e) # E: Revealed type is 'builtins.str' +reveal_type(e) # N: Revealed type is 'builtins.str' [builtins fixtures/exception.pyi] [case testRedefineUsingWithStatement] @@ -470,6 +470,6 @@ class B: def __enter__(self) -> str: ... def __exit__(self, x, y, z) -> None: ... with A() as x: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' with B() as x: x = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "str") diff --git a/test-data/unit/check-selftype.test b/test-data/unit/check-selftype.test index 0ad9c5eb5aca..2f2f9d1c24b8 100644 --- a/test-data/unit/check-selftype.test +++ b/test-data/unit/check-selftype.test @@ -9,10 +9,10 @@ class A: class B(A): pass -reveal_type(A().copy) # E: Revealed type is 'def () -> __main__.A*' -reveal_type(B().copy) # E: Revealed type is 'def () -> __main__.B*' -reveal_type(A().copy()) # E: Revealed type is '__main__.A*' -reveal_type(B().copy()) # E: Revealed type is '__main__.B*' +reveal_type(A().copy) # N: Revealed type is 'def () -> __main__.A*' +reveal_type(B().copy) # N: Revealed type is 'def () -> __main__.B*' +reveal_type(A().copy()) # N: Revealed type is '__main__.A*' +reveal_type(B().copy()) # N: Revealed type is '__main__.B*' [builtins fixtures/bool.pyi] @@ -55,8 +55,8 @@ class A: return A() # E: Incompatible return value type (got "A", expected "T") elif A(): return B() # E: Incompatible return value type (got "B", expected "T") - reveal_type(_type(self)) # E: Revealed type is 'Type[T`-1]' - return reveal_type(_type(self)()) # E: Revealed type is 'T`-1' + reveal_type(_type(self)) # N: Revealed type is 'Type[T`-1]' + return reveal_type(_type(self)()) # N: Revealed type is 'T`-1' class B(A): pass @@ -67,7 +67,7 @@ class C: def copy(self: Q) -> Q: if self: - return reveal_type(_type(self)(1)) # E: Revealed type is 'Q`-1' + return reveal_type(_type(self)(1)) # N: Revealed type is 'Q`-1' else: return _type(self)() # E: Too few arguments for "C" @@ -82,7 +82,7 @@ T = TypeVar('T', bound='A') class A: @classmethod def new(cls: Type[T]) -> T: - return reveal_type(cls()) # E: Revealed type is 'T`-1' + return reveal_type(cls()) # N: Revealed type is 'T`-1' class B(A): pass @@ -99,10 +99,10 @@ class C: return cls() # E: Too few arguments for "C" -reveal_type(A.new) # E: Revealed type is 'def () -> __main__.A*' -reveal_type(B.new) # E: Revealed type is 'def () -> __main__.B*' -reveal_type(A.new()) # E: Revealed type is '__main__.A*' -reveal_type(B.new()) # E: Revealed type is '__main__.B*' +reveal_type(A.new) # N: Revealed type is 'def () -> __main__.A*' +reveal_type(B.new) # N: Revealed type is 'def () -> __main__.B*' +reveal_type(A.new()) # N: Revealed type is '__main__.A*' +reveal_type(B.new()) # N: Revealed type is '__main__.B*' [builtins fixtures/classmethod.pyi] @@ -121,10 +121,10 @@ Q = TypeVar('Q', bound='C', covariant=True) class C(A): def copy(self: Q) -> Q: pass -reveal_type(C().copy) # E: Revealed type is 'def () -> __main__.C*' -reveal_type(C().copy()) # E: Revealed type is '__main__.C*' -reveal_type(cast(A, C()).copy) # E: Revealed type is 'def () -> __main__.A*' -reveal_type(cast(A, C()).copy()) # E: Revealed type is '__main__.A*' +reveal_type(C().copy) # N: Revealed type is 'def () -> __main__.C*' +reveal_type(C().copy()) # N: Revealed type is '__main__.C*' +reveal_type(cast(A, C()).copy) # N: Revealed type is 'def () -> __main__.A*' +reveal_type(cast(A, C()).copy()) # N: Revealed type is '__main__.A*' [builtins fixtures/bool.pyi] @@ -139,8 +139,8 @@ class A: Q = TypeVar('Q', bound='B', covariant=True) class B(A): def copy(self: Q) -> Q: - reveal_type(self) # E: Revealed type is 'Q`-1' - reveal_type(super().copy) # E: Revealed type is 'def () -> Q`-1' + reveal_type(self) # N: Revealed type is 'Q`-1' + reveal_type(super().copy) # N: Revealed type is 'def () -> Q`-1' return super().copy() [builtins fixtures/bool.pyi] @@ -156,18 +156,18 @@ class A: @classmethod def new(cls: Type[T], factory: Callable[[T], T]) -> T: - reveal_type(cls) # E: Revealed type is 'Type[T`-1]' - reveal_type(cls()) # E: Revealed type is 'T`-1' + reveal_type(cls) # N: Revealed type is 'Type[T`-1]' + reveal_type(cls()) # N: Revealed type is 'T`-1' cls(2) # E: Too many arguments for "A" return cls() class B(A): pass -reveal_type(A().copy) # E: Revealed type is 'def (factory: def (__main__.A*) -> __main__.A*) -> __main__.A*' -reveal_type(B().copy) # E: Revealed type is 'def (factory: def (__main__.B*) -> __main__.B*) -> __main__.B*' -reveal_type(A.new) # E: Revealed type is 'def (factory: def (__main__.A*) -> __main__.A*) -> __main__.A*' -reveal_type(B.new) # E: Revealed type is 'def (factory: def (__main__.B*) -> __main__.B*) -> __main__.B*' +reveal_type(A().copy) # N: Revealed type is 'def (factory: def (__main__.A*) -> __main__.A*) -> __main__.A*' +reveal_type(B().copy) # N: Revealed type is 'def (factory: def (__main__.B*) -> __main__.B*) -> __main__.B*' +reveal_type(A.new) # N: Revealed type is 'def (factory: def (__main__.A*) -> __main__.A*) -> __main__.A*' +reveal_type(B.new) # N: Revealed type is 'def (factory: def (__main__.B*) -> __main__.B*) -> __main__.B*' [builtins fixtures/classmethod.pyi] @@ -192,7 +192,7 @@ TB = TypeVar('TB', bound='B', covariant=True) class B(A): x = 1 def copy(self: TB) -> TB: - reveal_type(self.x) # E: Revealed type is 'builtins.int' + reveal_type(self.x) # N: Revealed type is 'builtins.int' return cast(TB, None) [builtins fixtures/bool.pyi] @@ -220,24 +220,24 @@ class C: class D(C): pass -reveal_type(D.new) # E: Revealed type is 'def () -> __main__.D*' -reveal_type(D().new) # E: Revealed type is 'def () -> __main__.D*' -reveal_type(D.new()) # E: Revealed type is '__main__.D*' -reveal_type(D().new()) # E: Revealed type is '__main__.D*' +reveal_type(D.new) # N: Revealed type is 'def () -> __main__.D*' +reveal_type(D().new) # N: Revealed type is 'def () -> __main__.D*' +reveal_type(D.new()) # N: Revealed type is '__main__.D*' +reveal_type(D().new()) # N: Revealed type is '__main__.D*' Q = TypeVar('Q', bound=C) def clone(arg: Q) -> Q: - reveal_type(arg.copy) # E: Revealed type is 'def () -> Q`-1' - reveal_type(arg.copy()) # E: Revealed type is 'Q`-1' - reveal_type(arg.new) # E: Revealed type is 'def () -> Q`-1' - reveal_type(arg.new()) # E: Revealed type is 'Q`-1' + reveal_type(arg.copy) # N: Revealed type is 'def () -> Q`-1' + reveal_type(arg.copy()) # N: Revealed type is 'Q`-1' + reveal_type(arg.new) # N: Revealed type is 'def () -> Q`-1' + reveal_type(arg.new()) # N: Revealed type is 'Q`-1' return arg.copy() def make(cls: Type[Q]) -> Q: - reveal_type(cls.new) # E: Revealed type is 'def () -> Q`-1' - reveal_type(cls().new) # E: Revealed type is 'def () -> Q`-1' - reveal_type(cls().new()) # E: Revealed type is 'Q`-1' + reveal_type(cls.new) # N: Revealed type is 'def () -> Q`-1' + reveal_type(cls().new) # N: Revealed type is 'def () -> Q`-1' + reveal_type(cls().new()) # N: Revealed type is 'Q`-1' return cls.new() [builtins fixtures/classmethod.pyi] @@ -345,11 +345,11 @@ class D: class E: def __new__(cls) -> E: - reveal_type(cls) # E: Revealed type is 'Type[__main__.E]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.E]' return cls() def __init_subclass__(cls) -> None: - reveal_type(cls) # E: Revealed type is 'Type[__main__.E]' + reveal_type(cls) # N: Revealed type is 'Type[__main__.E]' [case testSelfTypePropertyUnion] from typing import Union @@ -361,7 +361,7 @@ class B: @property def f(self: B) -> int: pass x: Union[A, B] -reveal_type(x.f) # E: Revealed type is 'builtins.int' +reveal_type(x.f) # N: Revealed type is 'builtins.int' [builtins fixtures/property.pyi] @@ -380,14 +380,14 @@ class A(K): class B(A): pass -reveal_type(A().g) # E: Revealed type is 'builtins.int' -reveal_type(A().gt) # E: Revealed type is '__main__.A*' -reveal_type(A().f()) # E: Revealed type is 'builtins.int' -reveal_type(A().ft()) # E: Revealed type is '__main__.A*' -reveal_type(B().g) # E: Revealed type is 'builtins.int' -reveal_type(B().gt) # E: Revealed type is '__main__.B*' -reveal_type(B().f()) # E: Revealed type is 'builtins.int' -reveal_type(B().ft()) # E: Revealed type is '__main__.B*' +reveal_type(A().g) # N: Revealed type is 'builtins.int' +reveal_type(A().gt) # N: Revealed type is '__main__.A*' +reveal_type(A().f()) # N: Revealed type is 'builtins.int' +reveal_type(A().ft()) # N: Revealed type is '__main__.A*' +reveal_type(B().g) # N: Revealed type is 'builtins.int' +reveal_type(B().gt) # N: Revealed type is '__main__.B*' +reveal_type(B().f()) # N: Revealed type is 'builtins.int' +reveal_type(B().ft()) # N: Revealed type is '__main__.B*' [builtins fixtures/property.pyi] @@ -405,14 +405,14 @@ class A(Tuple[int, int]): class B(A): pass -reveal_type(A().g) # E: Revealed type is 'builtins.int' -reveal_type(A().gt) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.A]' -reveal_type(A().f()) # E: Revealed type is 'builtins.int' -reveal_type(A().ft()) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.A]' -reveal_type(B().g) # E: Revealed type is 'builtins.int' -reveal_type(B().gt) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.B]' -reveal_type(B().f()) # E: Revealed type is 'builtins.int' -reveal_type(B().ft()) # E: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.B]' +reveal_type(A().g) # N: Revealed type is 'builtins.int' +reveal_type(A().gt) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.A]' +reveal_type(A().f()) # N: Revealed type is 'builtins.int' +reveal_type(A().ft()) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.A]' +reveal_type(B().g) # N: Revealed type is 'builtins.int' +reveal_type(B().gt) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.B]' +reveal_type(B().f()) # N: Revealed type is 'builtins.int' +reveal_type(B().ft()) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.B]' [builtins fixtures/property.pyi] @@ -434,18 +434,18 @@ class X(metaclass=B): def __init__(self, x: int) -> None: pass class Y(X): pass X1: Type[X] -reveal_type(X.g) # E: Revealed type is 'builtins.int' -reveal_type(X.gt) # E: Revealed type is 'def (x: builtins.int) -> __main__.X' -reveal_type(X.f()) # E: Revealed type is 'builtins.int' -reveal_type(X.ft()) # E: Revealed type is 'def (x: builtins.int) -> __main__.X' -reveal_type(Y.g) # E: Revealed type is 'builtins.int' -reveal_type(Y.gt) # E: Revealed type is 'def (x: builtins.int) -> __main__.Y' -reveal_type(Y.f()) # E: Revealed type is 'builtins.int' -reveal_type(Y.ft()) # E: Revealed type is 'def (x: builtins.int) -> __main__.Y' -reveal_type(X1.g) # E: Revealed type is 'builtins.int' -reveal_type(X1.gt) # E: Revealed type is 'Type[__main__.X]' -reveal_type(X1.f()) # E: Revealed type is 'builtins.int' -reveal_type(X1.ft()) # E: Revealed type is 'Type[__main__.X]' +reveal_type(X.g) # N: Revealed type is 'builtins.int' +reveal_type(X.gt) # N: Revealed type is 'def (x: builtins.int) -> __main__.X' +reveal_type(X.f()) # N: Revealed type is 'builtins.int' +reveal_type(X.ft()) # N: Revealed type is 'def (x: builtins.int) -> __main__.X' +reveal_type(Y.g) # N: Revealed type is 'builtins.int' +reveal_type(Y.gt) # N: Revealed type is 'def (x: builtins.int) -> __main__.Y' +reveal_type(Y.f()) # N: Revealed type is 'builtins.int' +reveal_type(Y.ft()) # N: Revealed type is 'def (x: builtins.int) -> __main__.Y' +reveal_type(X1.g) # N: Revealed type is 'builtins.int' +reveal_type(X1.gt) # N: Revealed type is 'Type[__main__.X]' +reveal_type(X1.f()) # N: Revealed type is 'builtins.int' +reveal_type(X1.ft()) # N: Revealed type is 'Type[__main__.X]' [builtins fixtures/property.pyi] @@ -467,14 +467,14 @@ class B(A[Q]): pass a: A[int] b: B[str] -reveal_type(a.g) # E: Revealed type is 'builtins.int' ---reveal_type(a.gt) # E: Revealed type is 'builtins.int' -reveal_type(a.f()) # E: Revealed type is 'builtins.int' -reveal_type(a.ft()) # E: Revealed type is '__main__.A*[builtins.int]' -reveal_type(b.g) # E: Revealed type is 'builtins.int' ---reveal_type(b.gt) # E: Revealed type is '__main__.B*[builtins.str]' -reveal_type(b.f()) # E: Revealed type is 'builtins.int' -reveal_type(b.ft()) # E: Revealed type is '__main__.B*[builtins.str]' +reveal_type(a.g) # N: Revealed type is 'builtins.int' +--reveal_type(a.gt) # N: Revealed type is 'builtins.int' +reveal_type(a.f()) # N: Revealed type is 'builtins.int' +reveal_type(a.ft()) # N: Revealed type is '__main__.A*[builtins.int]' +reveal_type(b.g) # N: Revealed type is 'builtins.int' +--reveal_type(b.gt) # N: Revealed type is '__main__.B*[builtins.str]' +reveal_type(b.f()) # N: Revealed type is 'builtins.int' +reveal_type(b.ft()) # N: Revealed type is '__main__.B*[builtins.str]' [builtins fixtures/property.pyi] @@ -501,5 +501,5 @@ class C: def x(self) -> int: return 1 ab: Union[A, B, C] -reveal_type(ab.x) # E: Revealed type is 'builtins.int' +reveal_type(ab.x) # N: Revealed type is 'builtins.int' [builtins fixtures/property.pyi] diff --git a/test-data/unit/check-serialize.test b/test-data/unit/check-serialize.test index 8c8f0d821e9f..a126554373a8 100644 --- a/test-data/unit/check-serialize.test +++ b/test-data/unit/check-serialize.test @@ -81,8 +81,8 @@ T = TypeVar('T') def f(x: T) -> T: return x [out2] -tmp/a.py:2: error: Revealed type is 'builtins.int*' -tmp/a.py:3: error: Revealed type is 'builtins.str*' +tmp/a.py:2: note: Revealed type is 'builtins.int*' +tmp/a.py:3: note: Revealed type is 'builtins.str*' [case testSerializeFunctionReturningGenericFunction] import a @@ -99,8 +99,8 @@ T = TypeVar('T') def f() -> Callable[[T], T]: pass [out2] -tmp/a.py:2: error: Revealed type is 'def () -> def [T] (T`-1) -> T`-1' -tmp/a.py:3: error: Revealed type is 'builtins.str*' +tmp/a.py:2: note: Revealed type is 'def () -> def [T] (T`-1) -> T`-1' +tmp/a.py:3: note: Revealed type is 'builtins.str*' [case testSerializeArgumentKinds] import a @@ -204,8 +204,8 @@ def f(x: int) -> int: pass @overload def f(x: str) -> str: pass [out2] -tmp/a.py:2: error: Revealed type is 'builtins.int' -tmp/a.py:3: error: Revealed type is 'builtins.str' +tmp/a.py:2: note: Revealed type is 'builtins.int' +tmp/a.py:3: note: Revealed type is 'builtins.str' [case testSerializeDecoratedFunction] import a @@ -221,7 +221,7 @@ def dec(f: Callable[[int], int]) -> Callable[[str], str]: pass @dec def f(x: int) -> int: pass [out2] -tmp/a.py:2: error: Revealed type is 'builtins.str' +tmp/a.py:2: note: Revealed type is 'builtins.str' tmp/a.py:3: error: Unexpected keyword argument "x" for "f" -- @@ -354,8 +354,8 @@ class A(Generic[T, S]): return self.x [out2] tmp/a.py:3: error: Argument 1 to "A" has incompatible type "str"; expected "int" -tmp/a.py:4: error: Revealed type is 'builtins.str*' -tmp/a.py:5: error: Revealed type is 'builtins.int*' +tmp/a.py:4: note: Revealed type is 'builtins.str*' +tmp/a.py:5: note: Revealed type is 'builtins.int*' [case testSerializeAbstractClass] import a @@ -431,7 +431,7 @@ class A: def x(self) -> int: return 0 [builtins fixtures/property.pyi] [out2] -tmp/a.py:2: error: Revealed type is 'builtins.int' +tmp/a.py:2: note: Revealed type is 'builtins.int' tmp/a.py:3: error: Property "x" defined in "A" is read-only [case testSerializeReadWriteProperty] @@ -451,7 +451,7 @@ class A: def x(self, v: int) -> None: pass [builtins fixtures/property.pyi] [out2] -tmp/a.py:2: error: Revealed type is 'builtins.int' +tmp/a.py:2: note: Revealed type is 'builtins.int' tmp/a.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testSerializeSelfType] @@ -469,8 +469,8 @@ T = TypeVar('T', bound='A') class A: def f(self: T) -> T: return self [out2] -tmp/a.py:2: error: Revealed type is 'b.A*' -tmp/a.py:4: error: Revealed type is 'a.B*' +tmp/a.py:2: note: Revealed type is 'b.A*' +tmp/a.py:4: note: Revealed type is 'a.B*' [case testSerializeInheritance] import a @@ -495,7 +495,7 @@ class C(A, B): [out2] tmp/a.py:2: error: Too many arguments for "f" of "A" tmp/a.py:3: error: Too many arguments for "g" of "B" -tmp/a.py:4: error: Revealed type is 'builtins.int' +tmp/a.py:4: note: Revealed type is 'builtins.int' tmp/a.py:7: error: Incompatible types in assignment (expression has type "C", variable has type "int") [case testSerializeGenericInheritance] @@ -514,7 +514,7 @@ class A(Generic[T]): class B(A[A[T]]): pass [out2] -tmp/a.py:3: error: Revealed type is 'b.A*[builtins.int*]' +tmp/a.py:3: note: Revealed type is 'b.A*[builtins.int*]' [case testSerializeFixedLengthTupleBaseClass] import a @@ -532,7 +532,7 @@ class A(Tuple[int, str]): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: error: Revealed type is 'Tuple[builtins.int, builtins.str]' +tmp/a.py:4: note: Revealed type is 'Tuple[builtins.int, builtins.str]' [case testSerializeVariableLengthTupleBaseClass] import a @@ -550,7 +550,7 @@ class A(Tuple[int, ...]): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: error: Revealed type is 'Tuple[builtins.int*, builtins.int*]' +tmp/a.py:4: note: Revealed type is 'Tuple[builtins.int*, builtins.int*]' [case testSerializePlainTupleBaseClass] import a @@ -568,7 +568,7 @@ class A(tuple): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: error: Revealed type is 'Tuple[Any, Any]' +tmp/a.py:4: note: Revealed type is 'Tuple[Any, Any]' [case testSerializeNamedTupleBaseClass] import a @@ -587,8 +587,8 @@ class A(NamedTuple('N', [('x', int), ('y', str)])): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: error: Revealed type is 'Tuple[builtins.int, builtins.str]' -tmp/a.py:5: error: Revealed type is 'Tuple[builtins.int, builtins.str]' +tmp/a.py:4: note: Revealed type is 'Tuple[builtins.int, builtins.str]' +tmp/a.py:5: note: Revealed type is 'Tuple[builtins.int, builtins.str]' [case testSerializeAnyBaseClass] import a @@ -606,7 +606,7 @@ class B(A): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:2: error: Too many arguments for "f" of "B" -tmp/a.py:3: error: Revealed type is 'Any' +tmp/a.py:3: note: Revealed type is 'Any' [case testSerializeIndirectAnyBaseClass] import a @@ -628,7 +628,7 @@ class C(B): [out2] tmp/a.py:2: error: Too many arguments for "f" of "B" tmp/a.py:3: error: Too many arguments for "g" of "C" -tmp/a.py:4: error: Revealed type is 'Any' +tmp/a.py:4: note: Revealed type is 'Any' [case testSerializeNestedClass] import a @@ -711,13 +711,13 @@ class C: self.b = A(0) # type: A self.c = A [out1] -main:2: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' -main:3: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' -main:4: error: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:2: note: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:3: note: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:4: note: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]' [out2] -main:2: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' -main:3: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' -main:4: error: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:2: note: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:3: note: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]' +main:4: note: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]' -- -- Strict optional @@ -737,7 +737,7 @@ from typing import Optional x: Optional[int] def f(x: int) -> None: pass [out2] -tmp/a.py:2: error: Revealed type is 'Union[builtins.int, None]' +tmp/a.py:2: note: Revealed type is 'Union[builtins.int, None]' tmp/a.py:3: error: Argument 1 to "f" has incompatible type "Optional[int]"; expected "int" -- @@ -750,9 +750,9 @@ reveal_type(b.x) [file b.py] x: NonExistent # type: ignore [out1] -main:2: error: Revealed type is 'Any' +main:2: note: Revealed type is 'Any' [out2] -main:2: error: Revealed type is 'Any' +main:2: note: Revealed type is 'Any' [case testSerializeIgnoredInvalidType] import b @@ -761,9 +761,9 @@ reveal_type(b.x) A = 0 x: A # type: ignore [out1] -main:2: error: Revealed type is 'A?' +main:2: note: Revealed type is 'A?' [out2] -main:2: error: Revealed type is 'A?' +main:2: note: Revealed type is 'A?' [case testSerializeIgnoredMissingBaseClass] import b @@ -772,11 +772,11 @@ reveal_type(b.B().x) [file b.py] class B(A): pass # type: ignore [out1] -main:2: error: Revealed type is 'b.B' -main:3: error: Revealed type is 'Any' +main:2: note: Revealed type is 'b.B' +main:3: note: Revealed type is 'Any' [out2] -main:2: error: Revealed type is 'b.B' -main:3: error: Revealed type is 'Any' +main:2: note: Revealed type is 'b.B' +main:3: note: Revealed type is 'Any' [case testSerializeIgnoredInvalidBaseClass] import b @@ -786,11 +786,11 @@ reveal_type(b.B().x) A = 0 class B(A): pass # type: ignore [out1] -main:2: error: Revealed type is 'b.B' -main:3: error: Revealed type is 'Any' +main:2: note: Revealed type is 'b.B' +main:3: note: Revealed type is 'Any' [out2] -main:2: error: Revealed type is 'b.B' -main:3: error: Revealed type is 'Any' +main:2: note: Revealed type is 'b.B' +main:3: note: Revealed type is 'Any' [case testSerializeIgnoredImport] import a @@ -804,8 +804,8 @@ reveal_type(b.x) import m # type: ignore from m import x # type: ignore [out2] -tmp/a.py:2: error: Revealed type is 'Any' -tmp/a.py:3: error: Revealed type is 'Any' +tmp/a.py:2: note: Revealed type is 'Any' +tmp/a.py:3: note: Revealed type is 'Any' -- -- TypeVar @@ -823,7 +823,7 @@ reveal_type(f) from typing import TypeVar T = TypeVar('T') [out2] -tmp/a.py:3: error: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' +tmp/a.py:3: note: Revealed type is 'def [b.T] (x: b.T`-1) -> b.T`-1' [case testSerializeBoundedTypeVar] import a @@ -839,8 +839,8 @@ from typing import TypeVar T = TypeVar('T', bound=int) def g(x: T) -> T: return x [out2] -tmp/a.py:3: error: Revealed type is 'def [b.T <: builtins.int] (x: b.T`-1) -> b.T`-1' -tmp/a.py:4: error: Revealed type is 'def [T <: builtins.int] (x: T`-1) -> T`-1' +tmp/a.py:3: note: Revealed type is 'def [b.T <: builtins.int] (x: b.T`-1) -> b.T`-1' +tmp/a.py:4: note: Revealed type is 'def [T <: builtins.int] (x: T`-1) -> T`-1' [case testSerializeTypeVarWithValues] import a @@ -856,8 +856,8 @@ from typing import TypeVar T = TypeVar('T', int, str) def g(x: T) -> T: return x [out2] -tmp/a.py:3: error: Revealed type is 'def [b.T in (builtins.int, builtins.str)] (x: b.T`-1) -> b.T`-1' -tmp/a.py:4: error: Revealed type is 'def [T in (builtins.int, builtins.str)] (x: T`-1) -> T`-1' +tmp/a.py:3: note: Revealed type is 'def [b.T in (builtins.int, builtins.str)] (x: b.T`-1) -> b.T`-1' +tmp/a.py:4: note: Revealed type is 'def [T in (builtins.int, builtins.str)] (x: T`-1) -> T`-1' [case testSerializeTypeVarInClassBody] import a @@ -872,7 +872,7 @@ from typing import TypeVar class A: T = TypeVar('T', int, str) [out2] -tmp/a.py:3: error: Revealed type is 'def [A.T in (builtins.int, builtins.str)] (x: A.T`-1) -> A.T`-1' +tmp/a.py:3: note: Revealed type is 'def [A.T in (builtins.int, builtins.str)] (x: A.T`-1) -> A.T`-1' -- -- NewType @@ -927,8 +927,8 @@ x: N [out2] tmp/a.py:5: error: Incompatible types in assignment (expression has type "Tuple[int]", variable has type "N") tmp/a.py:6: error: Incompatible types in assignment (expression has type "Tuple[int]", variable has type "N") -tmp/a.py:9: error: Revealed type is 'Tuple[builtins.int, fallback=b.N]' -tmp/a.py:10: error: Revealed type is 'builtins.int' +tmp/a.py:9: note: Revealed type is 'Tuple[builtins.int, fallback=b.N]' +tmp/a.py:10: note: Revealed type is 'builtins.int' tmp/a.py:11: error: Argument "x" to "N" has incompatible type "str"; expected "int" -- @@ -973,15 +973,15 @@ Ty = Type[int] Ty2 = type [builtins fixtures/list.pyi] [out2] -tmp/a.py:9: error: Revealed type is 'b.DD' -tmp/a.py:10: error: Revealed type is 'Any' -tmp/a.py:11: error: Revealed type is 'Union[builtins.int, builtins.str]' -tmp/a.py:12: error: Revealed type is 'builtins.list[builtins.int]' -tmp/a.py:13: error: Revealed type is 'Tuple[builtins.int, builtins.str]' -tmp/a.py:14: error: Revealed type is 'def (builtins.int) -> builtins.str' -tmp/a.py:15: error: Revealed type is 'Type[builtins.int]' -tmp/a.py:17: error: Revealed type is 'def (*Any, **Any) -> builtins.str' -tmp/a.py:19: error: Revealed type is 'builtins.type' +tmp/a.py:9: note: Revealed type is 'b.DD' +tmp/a.py:10: note: Revealed type is 'Any' +tmp/a.py:11: note: Revealed type is 'Union[builtins.int, builtins.str]' +tmp/a.py:12: note: Revealed type is 'builtins.list[builtins.int]' +tmp/a.py:13: note: Revealed type is 'Tuple[builtins.int, builtins.str]' +tmp/a.py:14: note: Revealed type is 'def (builtins.int) -> builtins.str' +tmp/a.py:15: note: Revealed type is 'Type[builtins.int]' +tmp/a.py:17: note: Revealed type is 'def (*Any, **Any) -> builtins.str' +tmp/a.py:19: note: Revealed type is 'builtins.type' [case testSerializeGenericTypeAlias] import b @@ -994,9 +994,9 @@ X = TypeVar('X') Y = Tuple[X, str] [builtins fixtures/tuple.pyi] [out1] -main:4: error: Revealed type is 'Tuple[builtins.int, builtins.str]' +main:4: note: Revealed type is 'Tuple[builtins.int, builtins.str]' [out2] -main:4: error: Revealed type is 'Tuple[builtins.int, builtins.str]' +main:4: note: Revealed type is 'Tuple[builtins.int, builtins.str]' [case testSerializeTuple] # Don't repreat types tested by testSerializeTypeAliases here. @@ -1013,8 +1013,8 @@ x: Tuple[int, ...] y: tuple [builtins fixtures/tuple.pyi] [out2] -tmp/a.py:2: error: Revealed type is 'builtins.tuple[builtins.int]' -tmp/a.py:3: error: Revealed type is 'builtins.tuple[Any]' +tmp/a.py:2: note: Revealed type is 'builtins.tuple[builtins.int]' +tmp/a.py:3: note: Revealed type is 'builtins.tuple[Any]' [case testSerializeNone] import a @@ -1026,7 +1026,7 @@ reveal_type(b.x) [file b.py] x: None [out2] -tmp/a.py:2: error: Revealed type is 'None' +tmp/a.py:2: note: Revealed type is 'None' -- -- TypedDict @@ -1047,13 +1047,13 @@ class C: self.c = A [builtins fixtures/dict.pyi] [out1] -main:2: error: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' -main:3: error: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' -main:4: error: Revealed type is 'def () -> ntcrash.C.A@4' +main:2: note: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' +main:3: note: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' +main:4: note: Revealed type is 'def () -> ntcrash.C.A@4' [out2] -main:2: error: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' -main:3: error: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' -main:4: error: Revealed type is 'def () -> ntcrash.C.A@4' +main:2: note: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' +main:3: note: Revealed type is 'TypedDict('ntcrash.C.A@4', {'x': builtins.int})' +main:4: note: Revealed type is 'def () -> ntcrash.C.A@4' [case testSerializeNonTotalTypedDict] from m import d @@ -1064,9 +1064,9 @@ D = TypedDict('D', {'x': int, 'y': str}, total=False) d: D [builtins fixtures/dict.pyi] [out1] -main:2: error: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})' +main:2: note: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})' [out2] -main:2: error: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})' +main:2: note: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})' -- -- Modules @@ -1110,10 +1110,10 @@ from c import A class A: pass [out1] main:2: error: Too many arguments for "A" -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [out2] main:2: error: Too many arguments for "A" -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [case testSerializeFromImportedClassAs] import b @@ -1125,10 +1125,10 @@ from c import A as B class A: pass [out1] main:2: error: Too many arguments for "A" -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [out2] main:2: error: Too many arguments for "A" -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [case testSerializeFromImportedModule] import b @@ -1191,10 +1191,10 @@ def g(x: int) -> None: pass class A: pass [out1] main:3: error: Too few arguments for "g" -main:5: error: Revealed type is 'd.A' +main:5: note: Revealed type is 'd.A' [out2] main:3: error: Too few arguments for "g" -main:5: error: Revealed type is 'd.A' +main:5: note: Revealed type is 'd.A' [case testSerializeImportInClassBody] import b @@ -1222,9 +1222,9 @@ from typing import Any class A: pass B = A [out1] -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [out2] -main:3: error: Revealed type is 'c.A' +main:3: note: Revealed type is 'c.A' [case testSerializeStarImport] import a @@ -1242,7 +1242,7 @@ def f() -> None: pass class A: pass [out2] tmp/a.py:2: error: Too many arguments for "f" -tmp/a.py:4: error: Revealed type is 'c.A' +tmp/a.py:4: note: Revealed type is 'c.A' [case testSerializeRelativeImport] import b.c @@ -1274,9 +1274,9 @@ class Test: self.foo = o [builtins fixtures/callable.pyi] [out1] -tmp/a.py:2: error: Revealed type is 'b.' +tmp/a.py:2: note: Revealed type is 'b.' [out2] -tmp/a.py:2: error: Revealed type is 'b.' +tmp/a.py:2: note: Revealed type is 'b.' [case testSerializeForwardReferenceToAliasInProperty] import a @@ -1298,7 +1298,7 @@ class A: C = str [builtins fixtures/property.pyi] [out2] -tmp/a.py:2: error: Revealed type is 'builtins.str' +tmp/a.py:2: note: Revealed type is 'builtins.str' [case testSerializeForwardReferenceToImportedAliasInProperty] # flags: --new-semantic-analyzer @@ -1322,7 +1322,7 @@ from m import C C = str [builtins fixtures/property.pyi] [out2] -tmp/a.py:2: error: Revealed type is 'builtins.str' +tmp/a.py:2: note: Revealed type is 'builtins.str' [case testSerializeNestedClassStuff] # flags: --verbose diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 892337116ea7..e51079e18e76 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -180,7 +180,7 @@ for z in x: # type: int pass for w in x: # type: Union[int, str] - reveal_type(w) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(w) # N: Revealed type is 'Union[builtins.int, builtins.str]' for v in x: # type: int, int # E: Syntax error in type annotation # N: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn) pass @@ -689,31 +689,31 @@ def variadic(exc: Tuple[Type[E1], ...]) -> None: try: pass except exc as e: - reveal_type(e) # E: Revealed type is '__main__.E1' + reveal_type(e) # N: Revealed type is '__main__.E1' def union(exc: Union[Type[E1], Type[E2]]) -> None: try: pass except exc as e: - reveal_type(e) # E: Revealed type is 'Union[__main__.E1, __main__.E2]' + reveal_type(e) # N: Revealed type is 'Union[__main__.E1, __main__.E2]' def tuple_in_union(exc: Union[Type[E1], Tuple[Type[E2], Type[E3]]]) -> None: try: pass except exc as e: - reveal_type(e) # E: Revealed type is 'Union[__main__.E1, __main__.E2, __main__.E3]' + reveal_type(e) # N: Revealed type is 'Union[__main__.E1, __main__.E2, __main__.E3]' def variadic_in_union(exc: Union[Type[E1], Tuple[Type[E2], ...]]) -> None: try: pass except exc as e: - reveal_type(e) # E: Revealed type is 'Union[__main__.E1, __main__.E2]' + reveal_type(e) # N: Revealed type is 'Union[__main__.E1, __main__.E2]' def nested_union(exc: Union[Type[E1], Union[Type[E2], Type[E3]]]) -> None: try: pass except exc as e: - reveal_type(e) # E: Revealed type is 'Union[__main__.E1, __main__.E2, __main__.E3]' + reveal_type(e) # N: Revealed type is 'Union[__main__.E1, __main__.E2, __main__.E3]' def error_in_union(exc: Union[Type[E1], int]) -> None: try: @@ -739,19 +739,19 @@ class NotBaseDerived: pass try: pass except BaseException as e1: - reveal_type(e1) # E: Revealed type is 'builtins.BaseException' + reveal_type(e1) # N: Revealed type is 'builtins.BaseException' except (E1, BaseException) as e2: - reveal_type(e2) # E: Revealed type is 'Union[Any, builtins.BaseException]' + reveal_type(e2) # N: Revealed type is 'Union[Any, builtins.BaseException]' except (E1, E2) as e3: - reveal_type(e3) # E: Revealed type is 'Union[Any, __main__.E2]' + reveal_type(e3) # N: Revealed type is 'Union[Any, __main__.E2]' except (E1, E2, BaseException) as e4: - reveal_type(e4) # E: Revealed type is 'Union[Any, builtins.BaseException]' + reveal_type(e4) # N: Revealed type is 'Union[Any, builtins.BaseException]' try: pass except E1 as e1: - reveal_type(e1) # E: Revealed type is 'Any' + reveal_type(e1) # N: Revealed type is 'Any' except E2 as e2: - reveal_type(e2) # E: Revealed type is '__main__.E2' + reveal_type(e2) # N: Revealed type is '__main__.E2' except NotBaseDerived as e3: # E: Exception type must be derived from BaseException pass except (NotBaseDerived, E1) as e4: # E: Exception type must be derived from BaseException @@ -845,8 +845,8 @@ def f(*arg: BaseException) -> int: x = f() [builtins fixtures/exception.pyi] [out] -main:11: error: Revealed type is 'builtins.int' -main:16: error: Revealed type is 'builtins.str' +main:11: note: Revealed type is 'builtins.int' +main:16: note: Revealed type is 'builtins.str' [case testExceptionVariableReuseInDeferredNode5] class EA(BaseException): @@ -869,8 +869,8 @@ def f(*arg: BaseException) -> int: x = f() [builtins fixtures/exception.pyi] [out] -main:10: error: Revealed type is 'builtins.int' -main:16: error: Revealed type is 'builtins.str' +main:10: note: Revealed type is 'builtins.int' +main:16: note: Revealed type is 'builtins.str' [case testExceptionVariableReuseInDeferredNode6] class EA(BaseException): @@ -893,8 +893,8 @@ def f(*arg: BaseException) -> int: x = f() [builtins fixtures/exception.pyi] [out] -main:10: error: Revealed type is 'builtins.int' -main:15: error: Revealed type is 'builtins.str' +main:10: note: Revealed type is 'builtins.int' +main:15: note: Revealed type is 'builtins.str' [case testArbitraryExpressionAsExceptionType] import typing @@ -989,7 +989,7 @@ def h(e: Type[int]): except e: pass [builtins fixtures/exception.pyi] [out] -main:9: error: Revealed type is 'builtins.BaseException' +main:9: note: Revealed type is 'builtins.BaseException' main:12: error: Exception type must be derived from BaseException @@ -1247,7 +1247,7 @@ T = TypeVar('T') def f(a: T) -> Generator[int, str, T]: pass def g() -> Generator[int, str, float]: r = yield from f('') - reveal_type(r) # E: Revealed type is 'builtins.str*' + reveal_type(r) # N: Revealed type is 'builtins.str*' return 3.14 [case testYieldFromTupleStatement] @@ -1370,7 +1370,7 @@ with A() as c: # type: int, int # E: Syntax error in type annotation # N: Sugg pass with A() as d: # type: Union[int, str] - reveal_type(d) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(d) # N: Revealed type is 'Union[builtins.int, builtins.str]' [case testWithStmtTupleTypeComment] @@ -1572,15 +1572,15 @@ main:8: error: Incompatible types in assignment (expression has type "A", variab [case testAugmentedAssignmentIntFloat] weight0 = 65.5 -reveal_type(weight0) # E: Revealed type is 'builtins.float' +reveal_type(weight0) # N: Revealed type is 'builtins.float' if int(): weight0 = 65 - reveal_type(weight0) # E: Revealed type is 'builtins.int' + reveal_type(weight0) # N: Revealed type is 'builtins.int' weight0 *= 'a' # E: Incompatible types in assignment (expression has type "str", variable has type "float") weight0 *= 0.5 - reveal_type(weight0) # E: Revealed type is 'builtins.float' + reveal_type(weight0) # N: Revealed type is 'builtins.float' weight0 *= object() # E: Unsupported operand types for * ("float" and "object") - reveal_type(weight0) # E: Revealed type is 'builtins.float' + reveal_type(weight0) # N: Revealed type is 'builtins.float' [builtins fixtures/float.pyi] @@ -1588,28 +1588,28 @@ if int(): class A: def __init__(self) -> None: self.weight0 = 65.5 - reveal_type(self.weight0) # E: Revealed type is 'builtins.float' + reveal_type(self.weight0) # N: Revealed type is 'builtins.float' self.weight0 = 65 - reveal_type(self.weight0) # E: Revealed type is 'builtins.int' + reveal_type(self.weight0) # N: Revealed type is 'builtins.int' self.weight0 *= 'a' # E: Incompatible types in assignment (expression has type "str", variable has type "float") self.weight0 *= 0.5 - reveal_type(self.weight0) # E: Revealed type is 'builtins.float' + reveal_type(self.weight0) # N: Revealed type is 'builtins.float' self.weight0 *= object() # E: Unsupported operand types for * ("float" and "object") - reveal_type(self.weight0) # E: Revealed type is 'builtins.float' + reveal_type(self.weight0) # N: Revealed type is 'builtins.float' [builtins fixtures/float.pyi] [case testAugmentedAssignmentIntFloatDict] from typing import Dict d = {'weight0': 65.5} -reveal_type(d['weight0']) # E: Revealed type is 'builtins.float*' +reveal_type(d['weight0']) # N: Revealed type is 'builtins.float*' d['weight0'] = 65 -reveal_type(d['weight0']) # E: Revealed type is 'builtins.float*' +reveal_type(d['weight0']) # N: Revealed type is 'builtins.float*' d['weight0'] *= 'a' # E: Unsupported operand types for * ("float" and "str") d['weight0'] *= 0.5 -reveal_type(d['weight0']) # E: Revealed type is 'builtins.float*' +reveal_type(d['weight0']) # N: Revealed type is 'builtins.float*' d['weight0'] *= object() # E: Unsupported operand types for * ("float" and "object") -reveal_type(d['weight0']) # E: Revealed type is 'builtins.float*' +reveal_type(d['weight0']) # N: Revealed type is 'builtins.float*' [builtins fixtures/floatdict.pyi] @@ -1618,7 +1618,7 @@ from typing import List, NamedTuple lst: List[N] for i in lst: - reveal_type(i.x) # E: Revealed type is 'builtins.int' + reveal_type(i.x) # N: Revealed type is 'builtins.int' a: str = i[0] # E: Incompatible types in assignment (expression has type "int", variable has type "str") N = NamedTuple('N', [('x', int)]) @@ -1630,7 +1630,7 @@ from typing import List, NamedTuple lst: List[M] for i in lst: # type: N - reveal_type(i.x) # E: Revealed type is 'builtins.int' + reveal_type(i.x) # N: Revealed type is 'builtins.int' a: str = i[0] # E: Incompatible types in assignment (expression has type "int", variable has type "str") N = NamedTuple('N', [('x', int)]) diff --git a/test-data/unit/check-super.test b/test-data/unit/check-super.test index 89fd9b4504fb..31398f9ff835 100644 --- a/test-data/unit/check-super.test +++ b/test-data/unit/check-super.test @@ -93,7 +93,7 @@ B(1) B(1, 'x') [builtins fixtures/__new__.pyi] -reveal_type(C.a) # E: Revealed type is 'Any' +reveal_type(C.a) # N: Revealed type is 'Any' [out] [case testSuperWithUnknownBase] @@ -118,8 +118,8 @@ class B: def f(self) -> None: pass class C(B): def h(self, x) -> None: - reveal_type(super(x, x).f) # E: Revealed type is 'def ()' - reveal_type(super(C, x).f) # E: Revealed type is 'def ()' + reveal_type(super(x, x).f) # N: Revealed type is 'def ()' + reveal_type(super(C, x).f) # N: Revealed type is 'def ()' [case testSuperInUnannotatedMethod] class C: @@ -137,10 +137,10 @@ class B(A): @classmethod def g(cls, x) -> None: - reveal_type(super(cls, x).f) # E: Revealed type is 'def () -> builtins.object' + reveal_type(super(cls, x).f) # N: Revealed type is 'def () -> builtins.object' def h(self, t: Type[B]) -> None: - reveal_type(super(t, self).f) # E: Revealed type is 'def () -> builtins.object' + reveal_type(super(t, self).f) # N: Revealed type is 'def () -> builtins.object' [builtins fixtures/classmethod.pyi] [case testSuperWithTypeTypeAsSecondArgument] @@ -164,7 +164,7 @@ class C(B): def f(self) -> int: pass def g(self: T) -> T: - reveal_type(super(C, self).f) # E: Revealed type is 'def () -> builtins.float' + reveal_type(super(C, self).f) # N: Revealed type is 'def () -> builtins.float' return self [case testSuperWithTypeVarValues1] diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 8246372a58fe..43ef6d5eaa14 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -192,8 +192,8 @@ if int(): t1[2] # E: Tuple index out of range t1[3] # E: Tuple index out of range t2[1] # E: Tuple index out of range -reveal_type(t1[n]) # E: Revealed type is 'Union[__main__.A, __main__.B]' -reveal_type(t3[n:]) # E: Revealed type is 'Union[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E]' +reveal_type(t1[n]) # N: Revealed type is 'Union[__main__.A, __main__.B]' +reveal_type(t3[n:]) # N: Revealed type is 'Union[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E]' if int(): b = t1[(0)] # E: Incompatible types in assignment (expression has type "A", variable has type "B") @@ -270,8 +270,8 @@ t2 = None # type: Tuple[A, B, A] a, b = None, None # type: (A, B) (a1, b1) = None, None # type: Tuple[A, B] -reveal_type(a1) # E: Revealed type is '__main__.A' -reveal_type(b1) # E: Revealed type is '__main__.B' +reveal_type(a1) # N: Revealed type is '__main__.A' +reveal_type(b1) # N: Revealed type is '__main__.B' if int(): a, a = t1 # E: Incompatible types in assignment (expression has type "B", variable has type "A") @@ -298,10 +298,10 @@ def avoid_confusing_test_parser() -> None: [a, b] = None, None # type: (A, B) [a1, b1] = None, None # type: Tuple[A, B] - reveal_type(a) # E: Revealed type is '__main__.A' - reveal_type(b) # E: Revealed type is '__main__.B' - reveal_type(a1) # E: Revealed type is '__main__.A' - reveal_type(b1) # E: Revealed type is '__main__.B' + reveal_type(a) # N: Revealed type is '__main__.A' + reveal_type(b) # N: Revealed type is '__main__.B' + reveal_type(a1) # N: Revealed type is '__main__.A' + reveal_type(b1) # N: Revealed type is '__main__.B' if int(): [a, a] = t1 # E: Incompatible types in assignment (expression has type "B", variable has type "A") @@ -312,8 +312,8 @@ def avoid_confusing_test_parser() -> None: [a, b, a1] = t2 [a2, b2] = t1 - reveal_type(a2) # E: Revealed type is '__main__.A' - reveal_type(b2) # E: Revealed type is '__main__.B' + reveal_type(a2) # N: Revealed type is '__main__.A' + reveal_type(b2) # N: Revealed type is '__main__.B' class A: pass class B: pass @@ -330,8 +330,8 @@ def avoid_confusing_test_parser(): [a, b] = None, None # type: Tuple[A, B] [a1, b1] = None, None # type: Tuple[A, B] - reveal_type(a1) # E: Revealed type is '__main__.A' - reveal_type(b1) # E: Revealed type is '__main__.B' + reveal_type(a1) # N: Revealed type is '__main__.A' + reveal_type(b1) # N: Revealed type is '__main__.B' if int(): [a, a] = t1 # E: Incompatible types in assignment (expression has type "B", variable has type "A") @@ -342,8 +342,8 @@ def avoid_confusing_test_parser(): [a, b, a1] = t2 [a2, b2] = t1 - reveal_type(a2) # E: Revealed type is '__main__.A' - reveal_type(b2) # E: Revealed type is '__main__.B' + reveal_type(a2) # N: Revealed type is '__main__.A' + reveal_type(b2) # N: Revealed type is '__main__.B' class A: pass class B: pass @@ -671,11 +671,11 @@ c1, *c2 = c d1, *d2 = d e1, *e2 = e -reveal_type(a2) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(b2) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(c2) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(d2) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(e2) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a2) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(b2) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(c2) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(d2) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(e2) # N: Revealed type is 'builtins.list[builtins.int]' [builtins fixtures/tuple.pyi] -- Nested tuple assignment @@ -870,8 +870,8 @@ from typing import Tuple class A(Tuple[int, str]): pass x, y = A() -reveal_type(x) # E: Revealed type is 'builtins.int' -reveal_type(y) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.str' x1 = A()[0] # type: int x2 = A()[1] # type: int # E: Incompatible types in assignment (expression has type "str", variable has type "int") @@ -971,20 +971,20 @@ a = () a = (1, 2) b = (*a, '') -reveal_type(b) # E: Revealed type is 'Tuple[builtins.int, builtins.int, builtins.str]' +reveal_type(b) # N: Revealed type is 'Tuple[builtins.int, builtins.int, builtins.str]' [case testTupleWithStarExpr2] a = [1] b = (0, *a) -reveal_type(b) # E: Revealed type is 'builtins.tuple[builtins.int*]' +reveal_type(b) # N: Revealed type is 'builtins.tuple[builtins.int*]' [builtins fixtures/tuple.pyi] [case testTupleWithStarExpr3] a = [''] b = (0, *a) -reveal_type(b) # E: Revealed type is 'builtins.tuple[builtins.object*]' +reveal_type(b) # N: Revealed type is 'builtins.tuple[builtins.object*]' c = (*a, '') -reveal_type(c) # E: Revealed type is 'builtins.tuple[builtins.str*]' +reveal_type(c) # N: Revealed type is 'builtins.tuple[builtins.str*]' [builtins fixtures/tuple.pyi] [case testTupleWithStarExpr4] @@ -1000,15 +1000,15 @@ class B: pass def f(x: Union[B, Tuple[A, A]]) -> None: if isinstance(x, tuple): - reveal_type(x) # E: Revealed type is 'Tuple[__main__.A, __main__.A]' + reveal_type(x) # N: Revealed type is 'Tuple[__main__.A, __main__.A]' else: - reveal_type(x) # E: Revealed type is '__main__.B' + reveal_type(x) # N: Revealed type is '__main__.B' def g(x: Union[str, Tuple[str, str]]) -> None: if isinstance(x, tuple): - reveal_type(x) # E: Revealed type is 'Tuple[builtins.str, builtins.str]' + reveal_type(x) # N: Revealed type is 'Tuple[builtins.str, builtins.str]' else: - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/tuple.pyi] [out] @@ -1019,21 +1019,21 @@ from typing import Tuple, Union Pair = Tuple[int, int] Variant = Union[int, Pair] def tuplify(v: Variant) -> None: - reveal_type(v) # E: Revealed type is 'Union[builtins.int, Tuple[builtins.int, builtins.int]]' + reveal_type(v) # N: Revealed type is 'Union[builtins.int, Tuple[builtins.int, builtins.int]]' if not isinstance(v, tuple): - reveal_type(v) # E: Revealed type is 'builtins.int' + reveal_type(v) # N: Revealed type is 'builtins.int' v = (v, v) - reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' - reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' - reveal_type(v[0]) # E: Revealed type is 'builtins.int' + reveal_type(v) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' + reveal_type(v) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' + reveal_type(v[0]) # N: Revealed type is 'builtins.int' Pair2 = Tuple[int, str] Variant2 = Union[int, Pair2] def tuplify2(v: Variant2) -> None: if isinstance(v, tuple): - reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.str]' + reveal_type(v) # N: Revealed type is 'Tuple[builtins.int, builtins.str]' else: - reveal_type(v) # E: Revealed type is 'builtins.int' + reveal_type(v) # N: Revealed type is 'builtins.int' [builtins fixtures/tuple.pyi] [out] @@ -1041,10 +1041,10 @@ def tuplify2(v: Variant2) -> None: from typing import Tuple, Union def good(blah: Union[Tuple[int, int], int]) -> None: - reveal_type(blah) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]' + reveal_type(blah) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]' if isinstance(blah, tuple): - reveal_type(blah) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' - reveal_type(blah) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]' + reveal_type(blah) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' + reveal_type(blah) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]' [builtins fixtures/tuple.pyi] [out] @@ -1119,7 +1119,7 @@ f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[]" t = (0, "") x = 0 y = "" -reveal_type(t[x]) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(t[x]) # N: Revealed type is 'Union[builtins.int, builtins.str]' t[y] # E: Invalid tuple index type (actual type "str", expected type "Union[int, slice]") [builtins fixtures/tuple.pyi] @@ -1127,7 +1127,7 @@ t[y] # E: Invalid tuple index type (actual type "str", expected type "Union[int t = (0, "") x = 0 y = "" -reveal_type(t[x:]) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(t[x:]) # N: Revealed type is 'Union[builtins.int, builtins.str]' t[y:] # E: Slice index must be an integer or None [builtins fixtures/tuple.pyi] @@ -1141,7 +1141,7 @@ def f(x: Base[T]) -> T: pass class DT(Tuple[str, str], Base[int]): pass -reveal_type(f(DT())) # E: Revealed type is 'builtins.int*' +reveal_type(f(DT())) # N: Revealed type is 'builtins.int*' [builtins fixtures/tuple.pyi] [out] @@ -1162,7 +1162,7 @@ t.f() from typing import Tuple def foo(o: CallableTuple) -> int: - reveal_type(o) # E: Revealed type is 'Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple]' + reveal_type(o) # N: Revealed type is 'Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple]' return o(1, 2) class CallableTuple(Tuple[str, int]): @@ -1175,7 +1175,7 @@ class CallableTuple(Tuple[str, int]): from typing import Sequence s: Sequence[str] s = tuple() -reveal_type(s) # E: Revealed type is 'builtins.tuple[builtins.str]' +reveal_type(s) # N: Revealed type is 'builtins.tuple[builtins.str]' [builtins fixtures/tuple.pyi] @@ -1184,7 +1184,7 @@ from typing import Iterable, Tuple x: Iterable[int] = () y: Tuple[int, ...] = (1, 2, 3) x = y -reveal_type(x) # E: Revealed type is 'builtins.tuple[builtins.int]' +reveal_type(x) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/tuple.pyi] @@ -1193,7 +1193,7 @@ from typing import Iterable, Tuple x: Iterable[int] = () y: Tuple[int, int] = (1, 2) x = y -reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, builtins.int]' +reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, builtins.int]' [case testTupleOverlapDifferentTuples] from typing import Optional, Tuple @@ -1204,9 +1204,9 @@ possibles: Tuple[int, Tuple[A]] x: Optional[Tuple[B]] if x in possibles: - reveal_type(x) # E: Revealed type is 'Tuple[__main__.B]' + reveal_type(x) # N: Revealed type is 'Tuple[__main__.B]' else: - reveal_type(x) # E: Revealed type is 'Union[Tuple[__main__.B], None]' + reveal_type(x) # N: Revealed type is 'Union[Tuple[__main__.B], None]' [builtins fixtures/tuple.pyi] @@ -1214,11 +1214,11 @@ else: from typing import Union, Tuple tup: Union[Tuple[int, str], Tuple[int, int, str]] -reveal_type(tup[0]) # E: Revealed type is 'builtins.int' -reveal_type(tup[1]) # E: Revealed type is 'Union[builtins.str, builtins.int]' -reveal_type(tup[2]) # E: Revealed type is 'Union[Any, builtins.str]' \ +reveal_type(tup[0]) # N: Revealed type is 'builtins.int' +reveal_type(tup[1]) # N: Revealed type is 'Union[builtins.str, builtins.int]' +reveal_type(tup[2]) # N: Revealed type is 'Union[Any, builtins.str]' \ # E: Tuple index out of range -reveal_type(tup[:]) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.str], Tuple[builtins.int, builtins.int, builtins.str]]' +reveal_type(tup[:]) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.str], Tuple[builtins.int, builtins.int, builtins.str]]' [builtins fixtures/tuple.pyi] @@ -1226,10 +1226,10 @@ reveal_type(tup[:]) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.s from typing import Union, Tuple, List tup: Union[Tuple[int, str], List[int]] -reveal_type(tup[0]) # E: Revealed type is 'builtins.int' -reveal_type(tup[1]) # E: Revealed type is 'Union[builtins.str, builtins.int*]' -reveal_type(tup[2]) # E: Revealed type is 'Union[Any, builtins.int*]' \ +reveal_type(tup[0]) # N: Revealed type is 'builtins.int' +reveal_type(tup[1]) # N: Revealed type is 'Union[builtins.str, builtins.int*]' +reveal_type(tup[2]) # N: Revealed type is 'Union[Any, builtins.int*]' \ # E: Tuple index out of range -reveal_type(tup[:]) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.str], builtins.list[builtins.int*]]' +reveal_type(tup[:]) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.str], builtins.list[builtins.int*]]' [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index bada7486bd6e..1b1cb66218fd 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -134,7 +134,7 @@ class C(Generic[T]): A = List[T] # E: Can't use bound type variable "T" to define generic alias x: C.A -reveal_type(x) # E: Revealed type is 'builtins.list[Any]' +reveal_type(x) # N: Revealed type is 'builtins.list[Any]' def f(x: T) -> T: A = List[T] # E: Can't use bound type variable "T" to define generic alias @@ -152,18 +152,18 @@ f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "str" from typing import Tuple, Callable EmptyTuple = Tuple[()] x = None # type: EmptyTuple -reveal_type(x) # E: Revealed type is 'Tuple[]' +reveal_type(x) # N: Revealed type is 'Tuple[]' EmptyTupleCallable = Callable[[Tuple[()]], None] f = None # type: EmptyTupleCallable -reveal_type(f) # E: Revealed type is 'def (Tuple[])' +reveal_type(f) # N: Revealed type is 'def (Tuple[])' [builtins fixtures/list.pyi] [case testForwardTypeAlias] def f(p: 'Alias') -> None: pass -reveal_type(f) # E: Revealed type is 'def (p: builtins.int)' +reveal_type(f) # N: Revealed type is 'def (p: builtins.int)' Alias = int [out] @@ -172,7 +172,7 @@ from typing import TypeVar, Tuple def f(p: 'Alias[str]') -> None: pass -reveal_type(f) # E: Revealed type is 'def (p: Tuple[builtins.int, builtins.str])' +reveal_type(f) # N: Revealed type is 'def (p: Tuple[builtins.int, builtins.str])' T = TypeVar('T') Alias = Tuple[int, T] [out] @@ -208,7 +208,7 @@ from typing import List x: A A = List[B] B = List[int] -reveal_type(x) # E: Revealed type is 'builtins.list[builtins.list[builtins.int]]' +reveal_type(x) # N: Revealed type is 'builtins.list[builtins.list[builtins.int]]' [builtins fixtures/list.pyi] [out] @@ -218,7 +218,7 @@ x: A A = List[B] class B(NamedTuple): x: str -reveal_type(x[0].x) # E: Revealed type is 'builtins.str' +reveal_type(x[0].x) # N: Revealed type is 'builtins.str' [builtins fixtures/list.pyi] [out] @@ -228,16 +228,16 @@ reveal_type(x[0].x) # E: Revealed type is 'builtins.str' from typing import List, Union, Dict x: JSON JSON = Union[int, str, List[JSON], Dict[str, JSON]] # type: ignore -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any], builtins.dict[builtins.str, Any]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any], builtins.dict[builtins.str, Any]]' if isinstance(x, list): - reveal_type(x) # E: Revealed type is 'builtins.list[Any]' + reveal_type(x) # N: Revealed type is 'builtins.list[Any]' [builtins fixtures/isinstancelist.pyi] [out] [case testForwardRefToTypeVar] # flags: --new-semantic-analyzer from typing import TypeVar, List -reveal_type(a) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int]' a: A[int] A = List[T] T = TypeVar('T') @@ -252,7 +252,7 @@ T = TypeVar('T') def f(x: T) -> List[T]: y: A[T] - reveal_type(y) # E: Revealed type is 'builtins.list[T`-1]' + reveal_type(y) # N: Revealed type is 'builtins.list[T`-1]' return [x] + y A = List[T] @@ -266,7 +266,7 @@ from typing import List, TypeVar def f() -> None: X = List[int] x: A[X] - reveal_type(x) # E: Revealed type is 'builtins.list[builtins.list[builtins.int]]' + reveal_type(x) # N: Revealed type is 'builtins.list[builtins.list[builtins.int]]' T = TypeVar('T') A = List[T] @@ -277,9 +277,9 @@ A = List[T] from typing import Union void = type(None) x: void -reveal_type(x) # E: Revealed type is 'None' +reveal_type(x) # N: Revealed type is 'None' y: Union[int, void] -reveal_type(y) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/bool.pyi] [case testNoneAliasStrict] @@ -299,8 +299,8 @@ C = Callable T = Tuple c: C t: T -reveal_type(c) # E: Revealed type is 'def (*Any, **Any) -> Any' -reveal_type(t) # E: Revealed type is 'builtins.tuple[Any]' +reveal_type(c) # N: Revealed type is 'def (*Any, **Any) -> Any' +reveal_type(t) # N: Revealed type is 'builtins.tuple[Any]' bad: C[int] # E: Bad number of arguments for type alias, expected: 0, given: 1 also_bad: T[int] # E: Bad number of arguments for type alias, expected: 0, given: 1 [builtins fixtures/tuple.pyi] @@ -318,21 +318,21 @@ class N: B = C[int] x: N.A[C] -reveal_type(x) # E: Revealed type is '__main__.C[__main__.C[Any]]' +reveal_type(x) # N: Revealed type is '__main__.C[__main__.C[Any]]' xx = N.A[C]() -reveal_type(xx) # E: Revealed type is '__main__.C[__main__.C*[Any]]' +reveal_type(xx) # N: Revealed type is '__main__.C[__main__.C*[Any]]' y = N.A() -reveal_type(y) # E: Revealed type is '__main__.C[Any]' +reveal_type(y) # N: Revealed type is '__main__.C[Any]' M = N b = M.A[int]() -reveal_type(b) # E: Revealed type is '__main__.C[builtins.int*]' +reveal_type(b) # N: Revealed type is '__main__.C[builtins.int*]' n: Type[N] w = n.B() -reveal_type(w) # E: Revealed type is '__main__.C[builtins.int]' +reveal_type(w) # N: Revealed type is '__main__.C[builtins.int]' [out] [case testTypeAliasesToNamedTuple] @@ -349,25 +349,25 @@ class Cls: A1('no') # E: Argument 1 to "C" has incompatible type "str"; expected "int" a1 = A1(1) -reveal_type(a1) # E: Revealed type is 'Tuple[builtins.int, fallback=nt.C]' +reveal_type(a1) # N: Revealed type is 'Tuple[builtins.int, fallback=nt.C]' A2(0) # E: Argument 1 to "D" has incompatible type "int"; expected "str" a2 = A2('yes') -reveal_type(a2) # E: Revealed type is 'Tuple[builtins.str, fallback=nt.D]' +reveal_type(a2) # N: Revealed type is 'Tuple[builtins.str, fallback=nt.D]' a3 = A3() -reveal_type(a3) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=nt.E]' +reveal_type(a3) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=nt.E]' Cls.A1('no') # E: Argument 1 has incompatible type "str"; expected "int" ca1 = Cls.A1(1) -reveal_type(ca1) # E: Revealed type is 'Tuple[builtins.int, fallback=nt.C]' +reveal_type(ca1) # N: Revealed type is 'Tuple[builtins.int, fallback=nt.C]' Cls.A2(0) # E: Argument 1 has incompatible type "int"; expected "str" ca2 = Cls.A2('yes') -reveal_type(ca2) # E: Revealed type is 'Tuple[builtins.str, fallback=nt.D]' +reveal_type(ca2) # N: Revealed type is 'Tuple[builtins.str, fallback=nt.D]' ca3 = Cls.A3() -reveal_type(ca3) # E: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=nt.E]' +reveal_type(ca3) # N: Revealed type is 'Tuple[builtins.int, builtins.str, fallback=nt.E]' [file nt.pyi] from typing import NamedTuple, Tuple @@ -437,8 +437,8 @@ class C: class D(C): ... -reveal_type(D.meth(1)) # E: Revealed type is 'Union[__main__.D*, builtins.int]' -reveal_type(D().meth(1)) # E: Revealed type is 'Union[__main__.D*, builtins.int]' +reveal_type(D.meth(1)) # N: Revealed type is 'Union[__main__.D*, builtins.int]' +reveal_type(D().meth(1)) # N: Revealed type is 'Union[__main__.D*, builtins.int]' [builtins fixtures/classmethod.pyi] [out] @@ -484,9 +484,9 @@ MYPY = False if MYPY: from t2 import A x: A -reveal_type(x) # E: Revealed type is 't2.D' +reveal_type(x) # N: Revealed type is 't2.D' -reveal_type(A) # E: Revealed type is 'def () -> t2.D' +reveal_type(A) # N: Revealed type is 'def () -> t2.D' A() [file t2.py] import t @@ -505,22 +505,22 @@ U = TypeVar('U') AnInt = FlexibleAlias[T, int] x: AnInt[str] -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' TwoArgs = FlexibleAlias[Tuple[T, U], bool] TwoArgs2 = FlexibleAlias[Tuple[T, U], List[U]] def welp(x: TwoArgs[str, int]) -> None: - reveal_type(x) # E: Revealed type is 'builtins.bool' + reveal_type(x) # N: Revealed type is 'builtins.bool' def welp2(x: TwoArgs2[str, int]) -> None: - reveal_type(x) # E: Revealed type is 'builtins.list[builtins.int]' + reveal_type(x) # N: Revealed type is 'builtins.list[builtins.int]' Id = FlexibleAlias[T, T] def take_id(x: Id[int]) -> None: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' def id(x: Id[T]) -> T: return x @@ -533,11 +533,11 @@ def id(x: Id[T]) -> T: # But this does Indirection2 = FlexibleAlias[T, AnInt[T]] z: Indirection2[str] -reveal_type(z) # E: Revealed type is 'builtins.int' +reveal_type(z) # N: Revealed type is 'builtins.int' Indirection3 = FlexibleAlias[Tuple[T, U], AnInt[T]] w: Indirection3[str, int] -reveal_type(w) # E: Revealed type is 'builtins.int' +reveal_type(w) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] @@ -557,10 +557,10 @@ else: class A: x: Bogus[str] -reveal_type(A().x) # E: Revealed type is 'Any' +reveal_type(A().x) # N: Revealed type is 'Any' def foo(x: Bogus[int]) -> None: - reveal_type(x) # E: Revealed type is 'Any' + reveal_type(x) # N: Revealed type is 'Any' [builtins fixtures/dict.pyi] @@ -580,10 +580,10 @@ else: class A: x: Bogus[str] -reveal_type(A().x) # E: Revealed type is 'builtins.str' +reveal_type(A().x) # N: Revealed type is 'builtins.str' def foo(x: Bogus[int]) -> None: - reveal_type(x) # E: Revealed type is 'builtins.int' + reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] @@ -593,7 +593,7 @@ C = C class C: # type: ignore pass x: C -reveal_type(x) # E: Revealed type is '__main__.C' +reveal_type(x) # N: Revealed type is '__main__.C' [out] [case testOverrideByIdemAliasCorrectTypeReversed] @@ -601,14 +601,14 @@ class C: pass C = C # type: ignore x: C -reveal_type(x) # E: Revealed type is '__main__.C' +reveal_type(x) # N: Revealed type is '__main__.C' [out] [case testOverrideByIdemAliasCorrectTypeImported] from other import C as B C = B x: C -reveal_type(x) # E: Revealed type is 'other.C' +reveal_type(x) # N: Revealed type is 'other.C' [file other.py] class C: pass @@ -624,6 +624,6 @@ except BaseException: try: pass except E as e: - reveal_type(e) # E: Revealed type is '__main__.E' + reveal_type(e) # N: Revealed type is '__main__.E' [builtins fixtures/exception.pyi] [out] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 7d26186e53d7..390c656d734b 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -4,9 +4,9 @@ from mypy_extensions import TypedDict Point = TypedDict('Point', {'x': int, 'y': int}) p = Point(x=42, y=1337) -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' # Use values() to check fallback value type. -reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(p.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -14,9 +14,9 @@ reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*] from mypy_extensions import TypedDict Point = TypedDict('Point', {'x': int, 'y': int}) p = Point(dict(x=42, y=1337)) -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' # Use values() to check fallback value type. -reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(p.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -24,9 +24,9 @@ reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*] from mypy_extensions import TypedDict Point = TypedDict('Point', {'x': int, 'y': int}) p = Point({'x': 42, 'y': 1337}) -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' # Use values() to check fallback value type. -reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(p.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -35,8 +35,8 @@ from typing import TypeVar, Union from mypy_extensions import TypedDict EmptyDict = TypedDict('EmptyDict', {}) p = EmptyDict() -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.EmptyDict', {})' -reveal_type(p.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.EmptyDict', {})' +reveal_type(p.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -86,7 +86,7 @@ class Point(TypedDict): y: int p = Point(x=42, y=1337) -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] [case testCanCreateTypedDictWithSubclass] @@ -99,8 +99,8 @@ class Point2D(Point1D): y: int r: Point1D p: Point2D -reveal_type(r) # E: Revealed type is 'TypedDict('__main__.Point1D', {'x': builtins.int})' -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' +reveal_type(r) # N: Revealed type is 'TypedDict('__main__.Point1D', {'x': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] [case testCanCreateTypedDictWithSubclass2] @@ -113,7 +113,7 @@ class Point2D(TypedDict, Point1D): # We also allow to include TypedDict in bases y: int p: Point2D -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] [case testCanCreateTypedDictClassEmpty] @@ -124,7 +124,7 @@ class EmptyDict(TypedDict): pass p = EmptyDict() -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.EmptyDict', {})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.EmptyDict', {})' [builtins fixtures/dict.pyi] @@ -167,7 +167,7 @@ class Point2D(Point1D, A): # E: All bases of a new TypedDict must be TypedDict t y: int p: Point2D -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point2D', {'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] [case testCannotCreateTypedDictWithClassWithOtherStuff] @@ -181,7 +181,7 @@ class Point(TypedDict): z = int # E: Invalid statement in TypedDict definition; expected "field_name: field_type" p = Point(x=42, y=1337, z='whatever') -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int, 'z': Any})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int, 'z': Any})' [builtins fixtures/dict.pyi] [case testCanCreateTypedDictTypeWithUnderscoreItemName] @@ -198,7 +198,7 @@ class Point(TypedDict): _y: int p: Point -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, '_y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, '_y': builtins.int})' [builtins fixtures/dict.pyi] [case testCannotCreateTypedDictWithClassOverwriting] @@ -210,7 +210,7 @@ class Bad(TypedDict): x: str # E: Duplicate TypedDict field "x" b: Bad -reveal_type(b) # E: Revealed type is 'TypedDict('__main__.Bad', {'x': builtins.int})' +reveal_type(b) # N: Revealed type is 'TypedDict('__main__.Bad', {'x': builtins.int})' [builtins fixtures/dict.pyi] [case testCannotCreateTypedDictWithClassOverwriting2] @@ -225,7 +225,7 @@ class Bad(Point1, Point2): # E: Cannot overwrite TypedDict field "x" while mergi pass b: Bad -reveal_type(b) # E: Revealed type is 'TypedDict('__main__.Bad', {'x': builtins.int})' +reveal_type(b) # N: Revealed type is 'TypedDict('__main__.Bad', {'x': builtins.int})' [builtins fixtures/dict.pyi] [case testCannotCreateTypedDictWithClassOverwriting2] @@ -238,7 +238,7 @@ class Point2(Point1): x: float # E: Cannot overwrite TypedDict field "x" while extending p2: Point2 -reveal_type(p2) # E: Revealed type is 'TypedDict('__main__.Point2', {'x': builtins.int})' +reveal_type(p2) # N: Revealed type is 'TypedDict('__main__.Point2', {'x': builtins.int})' [builtins fixtures/dict.pyi] @@ -321,7 +321,7 @@ from typing import Any, Mapping Point = TypedDict('Point', {'x': float, 'y': float}) def create_point() -> Point: return Point(x=1, y=2) -reveal_type(Point(x=1, y=2)) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.float, 'y': builtins.float})' +reveal_type(Point(x=1, y=2)) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.float, 'y': builtins.float})' [builtins fixtures/dict.pyi] [case testTypedDictDoesNotAcceptsFloatForInt] @@ -350,7 +350,7 @@ def create_point(something: Any) -> Point: from mypy_extensions import TypedDict from typing import List D = TypedDict('D', {'x': List[int]}) -reveal_type(D(x=[])) # E: Revealed type is 'TypedDict('__main__.D', {'x': builtins.list[builtins.int]})' +reveal_type(D(x=[])) # N: Revealed type is 'TypedDict('__main__.D', {'x': builtins.list[builtins.int]})' [builtins fixtures/dict.pyi] [case testCannotConvertTypedDictToDictOrMutableMapping] @@ -436,8 +436,8 @@ def fun(arg: StrMap[T]) -> T: return arg['whatever'] a: A b: B -reveal_type(fun(a)) # E: Revealed type is 'builtins.object*' -reveal_type(fun(b)) # E: Revealed type is 'builtins.object*' +reveal_type(fun(a)) # N: Revealed type is 'builtins.object*' +reveal_type(fun(b)) # N: Revealed type is 'builtins.object*' [builtins fixtures/dict.pyi] [out] @@ -450,9 +450,9 @@ Point3D = TypedDict('Point3D', {'x': int, 'y': int, 'z': int}) p1 = TaggedPoint(type='2d', x=0, y=0) p2 = Point3D(x=1, y=1, z=1) joined_points = [p1, p2][0] -reveal_type(p1.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' -reveal_type(p2.values()) # E: Revealed type is 'typing.Iterable[builtins.object*]' -reveal_type(joined_points) # E: Revealed type is 'TypedDict({'x': builtins.int, 'y': builtins.int})' +reveal_type(p1.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(p2.values()) # N: Revealed type is 'typing.Iterable[builtins.object*]' +reveal_type(joined_points) # N: Revealed type is 'TypedDict({'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -463,9 +463,9 @@ CellWithObject = TypedDict('CellWithObject', {'value': object, 'meta': object}) c1 = CellWithInt(value=1, meta=42) c2 = CellWithObject(value=2, meta='turtle doves') joined_cells = [c1, c2] -reveal_type(c1) # E: Revealed type is 'TypedDict('__main__.CellWithInt', {'value': builtins.object, 'meta': builtins.int})' -reveal_type(c2) # E: Revealed type is 'TypedDict('__main__.CellWithObject', {'value': builtins.object, 'meta': builtins.object})' -reveal_type(joined_cells) # E: Revealed type is 'builtins.list[TypedDict({'value': builtins.object})]' +reveal_type(c1) # N: Revealed type is 'TypedDict('__main__.CellWithInt', {'value': builtins.object, 'meta': builtins.int})' +reveal_type(c2) # N: Revealed type is 'TypedDict('__main__.CellWithObject', {'value': builtins.object, 'meta': builtins.object})' +reveal_type(joined_cells) # N: Revealed type is 'builtins.list[TypedDict({'value': builtins.object})]' [builtins fixtures/dict.pyi] [case testJoinOfDisjointTypedDictsIsEmptyTypedDict] @@ -475,9 +475,9 @@ Cell = TypedDict('Cell', {'value': object}) d1 = Point(x=0, y=0) d2 = Cell(value='pear tree') joined_dicts = [d1, d2] -reveal_type(d1) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' -reveal_type(d2) # E: Revealed type is 'TypedDict('__main__.Cell', {'value': builtins.object})' -reveal_type(joined_dicts) # E: Revealed type is 'builtins.list[TypedDict({})]' +reveal_type(d1) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(d2) # N: Revealed type is 'TypedDict('__main__.Cell', {'value': builtins.object})' +reveal_type(joined_dicts) # N: Revealed type is 'builtins.list[TypedDict({})]' [builtins fixtures/dict.pyi] [case testJoinOfTypedDictWithCompatibleMappingIsMapping] @@ -488,8 +488,8 @@ left = Cell(value=42) right = {'score': 999} # type: Mapping[str, int] joined1 = [left, right] joined2 = [right, left] -reveal_type(joined1) # E: Revealed type is 'builtins.list[typing.Mapping*[builtins.str, builtins.object]]' -reveal_type(joined2) # E: Revealed type is 'builtins.list[typing.Mapping*[builtins.str, builtins.object]]' +reveal_type(joined1) # N: Revealed type is 'builtins.list[typing.Mapping*[builtins.str, builtins.object]]' +reveal_type(joined2) # N: Revealed type is 'builtins.list[typing.Mapping*[builtins.str, builtins.object]]' [builtins fixtures/dict.pyi] [case testJoinOfTypedDictWithCompatibleMappingSupertypeIsSupertype] @@ -500,8 +500,8 @@ left = Cell(value=42) right = {'score': 999} # type: Sized joined1 = [left, right] joined2 = [right, left] -reveal_type(joined1) # E: Revealed type is 'builtins.list[typing.Sized*]' -reveal_type(joined2) # E: Revealed type is 'builtins.list[typing.Sized*]' +reveal_type(joined1) # N: Revealed type is 'builtins.list[typing.Sized*]' +reveal_type(joined2) # N: Revealed type is 'builtins.list[typing.Sized*]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -513,8 +513,8 @@ left = Cell(value=42) right = 42 joined1 = [left, right] joined2 = [right, left] -reveal_type(joined1) # E: Revealed type is 'builtins.list[builtins.object*]' -reveal_type(joined2) # E: Revealed type is 'builtins.list[builtins.object*]' +reveal_type(joined1) # N: Revealed type is 'builtins.list[builtins.object*]' +reveal_type(joined2) # N: Revealed type is 'builtins.list[builtins.object*]' [builtins fixtures/dict.pyi] @@ -528,7 +528,7 @@ YZ = TypedDict('YZ', {'y': int, 'z': int}) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: XY, y: YZ) -> None: pass -reveal_type(f(g)) # E: Revealed type is 'TypedDict({'x': builtins.int, 'y': builtins.int, 'z': builtins.int})' +reveal_type(f(g)) # N: Revealed type is 'TypedDict({'x': builtins.int, 'y': builtins.int, 'z': builtins.int})' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictsWithIncompatibleCommonKeysIsUninhabited] @@ -540,7 +540,7 @@ YbZ = TypedDict('YbZ', {'y': object, 'z': int}) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: XYa, y: YbZ) -> None: pass -reveal_type(f(g)) # E: Revealed type is '' +reveal_type(f(g)) # N: Revealed type is '' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictsWithNoCommonKeysHasAllKeysAndNewFallback] @@ -551,7 +551,7 @@ Z = TypedDict('Z', {'z': int}) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: X, y: Z) -> None: pass -reveal_type(f(g)) # E: Revealed type is 'TypedDict({'x': builtins.int, 'z': builtins.int})' +reveal_type(f(g)) # N: Revealed type is 'TypedDict({'x': builtins.int, 'z': builtins.int})' [builtins fixtures/dict.pyi] # TODO: It would be more accurate for the meet to be TypedDict instead. @@ -564,7 +564,7 @@ M = Mapping[str, int] T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: X, y: M) -> None: pass -reveal_type(f(g)) # E: Revealed type is '' +reveal_type(f(g)) # N: Revealed type is '' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictWithIncompatibleMappingIsUninhabited] @@ -576,7 +576,7 @@ M = Mapping[str, str] T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: X, y: M) -> None: pass -reveal_type(f(g)) # E: Revealed type is '' +reveal_type(f(g)) # N: Revealed type is '' [builtins fixtures/dict.pyi] # TODO: It would be more accurate for the meet to be TypedDict instead. @@ -589,7 +589,7 @@ I = Iterable[str] T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: X, y: I) -> None: pass -reveal_type(f(g)) # E: Revealed type is '' +reveal_type(f(g)) # N: Revealed type is '' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictsWithNonTotal] @@ -600,7 +600,7 @@ YZ = TypedDict('YZ', {'y': int, 'z': int}, total=False) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: XY, y: YZ) -> None: pass -reveal_type(f(g)) # E: Revealed type is 'TypedDict({'x'?: builtins.int, 'y'?: builtins.int, 'z'?: builtins.int})' +reveal_type(f(g)) # N: Revealed type is 'TypedDict({'x'?: builtins.int, 'y'?: builtins.int, 'z'?: builtins.int})' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictsWithNonTotalAndTotal] @@ -611,7 +611,7 @@ YZ = TypedDict('YZ', {'y': int, 'z': int}) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: XY, y: YZ) -> None: pass -reveal_type(f(g)) # E: Revealed type is 'TypedDict({'x'?: builtins.int, 'y': builtins.int, 'z': builtins.int})' +reveal_type(f(g)) # N: Revealed type is 'TypedDict({'x'?: builtins.int, 'y': builtins.int, 'z': builtins.int})' [builtins fixtures/dict.pyi] [case testMeetOfTypedDictsWithIncompatibleNonTotalAndTotal] @@ -623,7 +623,7 @@ YZ = TypedDict('YZ', {'y': int, 'z': int}) T = TypeVar('T') def f(x: Callable[[T, T], None]) -> T: pass def g(x: XY, y: YZ) -> None: pass -reveal_type(f(g)) # E: Revealed type is '' +reveal_type(f(g)) # N: Revealed type is '' [builtins fixtures/dict.pyi] @@ -636,7 +636,7 @@ T = TypeVar('T') def f(x: Iterable[T]) -> T: pass A = TypedDict('A', {'x': int}) a: A -reveal_type(f(a)) # E: Revealed type is 'builtins.str*' +reveal_type(f(a)) # N: Revealed type is 'builtins.str*' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -649,9 +649,9 @@ reveal_type(f(a)) # E: Revealed type is 'builtins.str*' from mypy_extensions import TypedDict TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int}) p = TaggedPoint(type='2d', x=42, y=1337) -reveal_type(p['type']) # E: Revealed type is 'builtins.str' -reveal_type(p['x']) # E: Revealed type is 'builtins.int' -reveal_type(p['y']) # E: Revealed type is 'builtins.int' +reveal_type(p['type']) # N: Revealed type is 'builtins.str' +reveal_type(p['x']) # N: Revealed type is 'builtins.int' +reveal_type(p['y']) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] [case testCanGetItemOfTypedDictWithValidBytesOrUnicodeLiteralKey] @@ -659,8 +659,8 @@ reveal_type(p['y']) # E: Revealed type is 'builtins.int' from mypy_extensions import TypedDict Cell = TypedDict('Cell', {'value': int}) c = Cell(value=42) -reveal_type(c['value']) # E: Revealed type is 'builtins.int' -reveal_type(c[u'value']) # E: Revealed type is 'builtins.int' +reveal_type(c['value']) # N: Revealed type is 'builtins.int' +reveal_type(c[u'value']) # N: Revealed type is 'builtins.int' [builtins_py2 fixtures/dict.pyi] [case testCannotGetItemOfTypedDictWithInvalidStringLiteralKey] @@ -735,7 +735,7 @@ from mypy_extensions import TypedDict D = TypedDict('D', {'x': int}) d: object if isinstance(d, D): # E: Cannot use isinstance() with a TypedDict type - reveal_type(d) # E: Revealed type is '__main__.D' + reveal_type(d) # N: Revealed type is '__main__.D' issubclass(object, D) # E: Cannot use issubclass() with a TypedDict type [builtins fixtures/isinstancelist.pyi] @@ -783,15 +783,15 @@ e = E(a='') f = F(x=1) g = G(a=cast(Any, 1)) # Work around #2610 -reveal_type(u(d, d)) # E: Revealed type is 'TypedDict('__main__.D', {'a': builtins.int, 'b': builtins.int})' -reveal_type(u(c, d)) # E: Revealed type is 'TypedDict('__main__.C', {'a': builtins.int})' -reveal_type(u(d, c)) # E: Revealed type is 'TypedDict('__main__.C', {'a': builtins.int})' -reveal_type(u(c, e)) # E: Revealed type is 'Union[TypedDict('__main__.E', {'a': builtins.str}), TypedDict('__main__.C', {'a': builtins.int})]' -reveal_type(u(e, c)) # E: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.E', {'a': builtins.str})]' -reveal_type(u(c, f)) # E: Revealed type is 'Union[TypedDict('__main__.F', {'x': builtins.int}), TypedDict('__main__.C', {'a': builtins.int})]' -reveal_type(u(f, c)) # E: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.F', {'x': builtins.int})]' -reveal_type(u(c, g)) # E: Revealed type is 'Union[TypedDict('__main__.G', {'a': Any}), TypedDict('__main__.C', {'a': builtins.int})]' -reveal_type(u(g, c)) # E: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.G', {'a': Any})]' +reveal_type(u(d, d)) # N: Revealed type is 'TypedDict('__main__.D', {'a': builtins.int, 'b': builtins.int})' +reveal_type(u(c, d)) # N: Revealed type is 'TypedDict('__main__.C', {'a': builtins.int})' +reveal_type(u(d, c)) # N: Revealed type is 'TypedDict('__main__.C', {'a': builtins.int})' +reveal_type(u(c, e)) # N: Revealed type is 'Union[TypedDict('__main__.E', {'a': builtins.str}), TypedDict('__main__.C', {'a': builtins.int})]' +reveal_type(u(e, c)) # N: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.E', {'a': builtins.str})]' +reveal_type(u(c, f)) # N: Revealed type is 'Union[TypedDict('__main__.F', {'x': builtins.int}), TypedDict('__main__.C', {'a': builtins.int})]' +reveal_type(u(f, c)) # N: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.F', {'x': builtins.int})]' +reveal_type(u(c, g)) # N: Revealed type is 'Union[TypedDict('__main__.G', {'a': Any}), TypedDict('__main__.C', {'a': builtins.int})]' +reveal_type(u(g, c)) # N: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), TypedDict('__main__.G', {'a': Any})]' [builtins fixtures/dict.pyi] [case testTypedDictUnionSimplification2] @@ -810,11 +810,11 @@ m_s_s: Mapping[str, str] m_i_i: Mapping[int, int] m_s_a: Mapping[str, Any] -reveal_type(u(c, m_s_o)) # E: Revealed type is 'typing.Mapping*[builtins.str, builtins.object]' -reveal_type(u(m_s_o, c)) # E: Revealed type is 'typing.Mapping*[builtins.str, builtins.object]' -reveal_type(u(c, m_s_s)) # E: Revealed type is 'Union[typing.Mapping*[builtins.str, builtins.str], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' -reveal_type(u(c, m_i_i)) # E: Revealed type is 'Union[typing.Mapping*[builtins.int, builtins.int], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' -reveal_type(u(c, m_s_a)) # E: Revealed type is 'Union[typing.Mapping*[builtins.str, Any], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' +reveal_type(u(c, m_s_o)) # N: Revealed type is 'typing.Mapping*[builtins.str, builtins.object]' +reveal_type(u(m_s_o, c)) # N: Revealed type is 'typing.Mapping*[builtins.str, builtins.object]' +reveal_type(u(c, m_s_s)) # N: Revealed type is 'Union[typing.Mapping*[builtins.str, builtins.str], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' +reveal_type(u(c, m_i_i)) # N: Revealed type is 'Union[typing.Mapping*[builtins.int, builtins.int], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' +reveal_type(u(c, m_s_a)) # N: Revealed type is 'Union[typing.Mapping*[builtins.str, Any], TypedDict('__main__.C', {'a': builtins.int, 'b': builtins.int})]' [builtins fixtures/dict.pyi] @@ -892,11 +892,11 @@ from mypy_extensions import TypedDict class A: pass D = TypedDict('D', {'x': int, 'y': str}) d: D -reveal_type(d.get('x')) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(d.get('y')) # E: Revealed type is 'Union[builtins.str, None]' -reveal_type(d.get('x', A())) # E: Revealed type is 'Union[builtins.int, __main__.A]' -reveal_type(d.get('x', 1)) # E: Revealed type is 'builtins.int' -reveal_type(d.get('y', None)) # E: Revealed type is 'Union[builtins.str, None]' +reveal_type(d.get('x')) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(d.get('y')) # N: Revealed type is 'Union[builtins.str, None]' +reveal_type(d.get('x', A())) # N: Revealed type is 'Union[builtins.int, __main__.A]' +reveal_type(d.get('x', 1)) # N: Revealed type is 'builtins.int' +reveal_type(d.get('y', None)) # N: Revealed type is 'Union[builtins.str, None]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -907,10 +907,10 @@ from mypy_extensions import TypedDict class A: pass D = TypedDict('D', {'x': List[int], 'y': int}) d: D -reveal_type(d.get('x', [])) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(d.get('x', [])) # N: Revealed type is 'builtins.list[builtins.int]' d.get('x', ['x']) # E: List item 0 has incompatible type "str"; expected "int" a = [''] -reveal_type(d.get('x', a)) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str*]]' +reveal_type(d.get('x', a)) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str*]]' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -927,10 +927,10 @@ d.get('x', 1, 2) # E: No overload variant of "get" of "Mapping" matches argument # N: def get(self, k: str) -> object \ # N: def [V] get(self, k: str, default: Union[int, V]) -> object x = d.get('z') # E: TypedDict "D" has no key 'z' -reveal_type(x) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' s = '' y = d.get(s) -reveal_type(y) # E: Revealed type is 'builtins.object*' +reveal_type(y) # N: Revealed type is 'builtins.object*' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -946,7 +946,7 @@ from mypy_extensions import TypedDict D = TypedDict('D', {'x': int, 'y': str}) E = TypedDict('E', {'d': D}) p = E(d=D(x=0, y='')) -reveal_type(p.get('d', {'x': 1, 'y': ''})) # E: Revealed type is 'TypedDict('__main__.D', {'x': builtins.int, 'y': builtins.str})' +reveal_type(p.get('d', {'x': 1, 'y': ''})) # N: Revealed type is 'TypedDict('__main__.D', {'x': builtins.int, 'y': builtins.str})' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -965,11 +965,11 @@ C = TypedDict('C', {'a': int}) D = TypedDict('D', {'x': C, 'y': str}) d: D reveal_type(d.get('x', {})) \ - # E: Revealed type is 'TypedDict('__main__.C', {'a'?: builtins.int})' + # N: Revealed type is 'TypedDict('__main__.C', {'a'?: builtins.int})' reveal_type(d.get('x', None)) \ - # E: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), None]' -reveal_type(d.get('x', {}).get('a')) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(d.get('x', {})['a']) # E: Revealed type is 'builtins.int' + # N: Revealed type is 'Union[TypedDict('__main__.C', {'a': builtins.int}), None]' +reveal_type(d.get('x', {}).get('a')) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(d.get('x', {})['a']) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -981,7 +981,7 @@ from mypy_extensions import TypedDict D = TypedDict('D', {'x': int, 'y': str}, total=True) d: D reveal_type(d) \ - # E: Revealed type is 'TypedDict('__main__.D', {'x': builtins.int, 'y': builtins.str})' + # N: Revealed type is 'TypedDict('__main__.D', {'x': builtins.int, 'y': builtins.str})' [builtins fixtures/dict.pyi] [case testTypedDictWithInvalidTotalArgument] @@ -996,7 +996,7 @@ D = TypedDict('D', {'x': int}, False) # E: Unexpected arguments to TypedDict() from mypy_extensions import TypedDict D = TypedDict('D', {'x': int, 'y': str}, total=False) def f(d: D) -> None: - reveal_type(d) # E: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' + reveal_type(d) # N: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' f({}) f({'x': 1}) f({'y': ''}) @@ -1009,8 +1009,8 @@ f({'x': ''}) # E: Incompatible types (expression has type "str", TypedDict item from mypy_extensions import TypedDict D = TypedDict('D', {'x': int, 'y': str}, total=False) def f(d: D) -> None: pass -reveal_type(D()) # E: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' -reveal_type(D(x=1)) # E: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' +reveal_type(D()) # N: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' +reveal_type(D(x=1)) # N: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' f(D(y='')) f(D(x=1, y='')) f(D(x=1, z='')) # E: Extra key 'z' for TypedDict "D" @@ -1021,10 +1021,10 @@ f(D(x='')) # E: Incompatible types (expression has type "str", TypedDict item "x from mypy_extensions import TypedDict D = TypedDict('D', {'x': int, 'y': str}, total=False) d: D -reveal_type(d['x']) # E: Revealed type is 'builtins.int' -reveal_type(d['y']) # E: Revealed type is 'builtins.str' -reveal_type(d.get('x')) # E: Revealed type is 'builtins.int' -reveal_type(d.get('y')) # E: Revealed type is 'builtins.str' +reveal_type(d['x']) # N: Revealed type is 'builtins.int' +reveal_type(d['y']) # N: Revealed type is 'builtins.str' +reveal_type(d.get('x')) # N: Revealed type is 'builtins.int' +reveal_type(d.get('y')) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -1059,15 +1059,15 @@ a: A b: B c: C reveal_type(j(a, b)) \ - # E: Revealed type is 'TypedDict({})' + # N: Revealed type is 'TypedDict({})' reveal_type(j(b, b)) \ - # E: Revealed type is 'TypedDict({'x'?: builtins.int})' + # N: Revealed type is 'TypedDict({'x'?: builtins.int})' reveal_type(j(c, c)) \ - # E: Revealed type is 'TypedDict({'x'?: builtins.int, 'y'?: builtins.str})' + # N: Revealed type is 'TypedDict({'x'?: builtins.int, 'y'?: builtins.str})' reveal_type(j(b, c)) \ - # E: Revealed type is 'TypedDict({'x'?: builtins.int})' + # N: Revealed type is 'TypedDict({'x'?: builtins.int})' reveal_type(j(c, b)) \ - # E: Revealed type is 'TypedDict({'x'?: builtins.int})' + # N: Revealed type is 'TypedDict({'x'?: builtins.int})' [builtins fixtures/dict.pyi] [case testTypedDictClassWithTotalArgument] @@ -1076,7 +1076,7 @@ class D(TypedDict, total=False): x: int y: str d: D -reveal_type(d) # E: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' +reveal_type(d) # N: Revealed type is 'TypedDict('__main__.D', {'x'?: builtins.int, 'y'?: builtins.str})' [builtins fixtures/dict.pyi] [case testTypedDictClassWithInvalidTotalArgument] @@ -1099,7 +1099,7 @@ class B(TypedDict, A, total=False): class C(TypedDict, B, total=True): z: str c: C -reveal_type(c) # E: Revealed type is 'TypedDict('__main__.C', {'x': builtins.int, 'y'?: builtins.int, 'z': builtins.str})' +reveal_type(c) # N: Revealed type is 'TypedDict('__main__.C', {'x': builtins.int, 'y'?: builtins.int, 'z': builtins.str})' [builtins fixtures/dict.pyi] [case testNonTotalTypedDictInErrorMessages] @@ -1187,8 +1187,8 @@ def f(x: int) -> int: ... def f(x): pass a: A -reveal_type(f(a)) # E: Revealed type is 'builtins.str' -reveal_type(f(1)) # E: Revealed type is 'builtins.int' +reveal_type(f(a)) # N: Revealed type is 'builtins.str' +reveal_type(f(1)) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -1251,8 +1251,8 @@ def f(x): pass a: A b: B -reveal_type(f(a)) # E: Revealed type is 'builtins.int' -reveal_type(f(1)) # E: Revealed type is 'builtins.str' +reveal_type(f(a)) # N: Revealed type is 'builtins.int' +reveal_type(f(1)) # N: Revealed type is 'builtins.str' f(b) # E: Argument 1 to "f" has incompatible type "B"; expected "A" [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -1295,8 +1295,8 @@ def f(x): pass a: A b: B -reveal_type(f(a)) # E: Revealed type is 'builtins.int' -reveal_type(f(b)) # E: Revealed type is 'builtins.str' +reveal_type(f(a)) # N: Revealed type is 'builtins.int' +reveal_type(f(b)) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] @@ -1310,7 +1310,7 @@ X = TypedDict('X', {'b': 'B', 'c': 'C'}) class B: pass class C(B): pass x: X -reveal_type(x) # E: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' +reveal_type(x) # N: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' m1: Mapping[str, object] = x m2: Mapping[str, B] = x # E: Incompatible types in assignment (expression has type "X", variable has type "Mapping[str, B]") [builtins fixtures/dict.pyi] @@ -1324,7 +1324,7 @@ class X(TypedDict): class B: pass class C(B): pass x: X -reveal_type(x) # E: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' +reveal_type(x) # N: Revealed type is 'TypedDict('__main__.X', {'b': __main__.B, 'c': __main__.C})' m1: Mapping[str, object] = x m2: Mapping[str, B] = x # E: Incompatible types in assignment (expression has type "X", variable has type "Mapping[str, B]") [builtins fixtures/dict.pyi] @@ -1335,8 +1335,8 @@ from mypy_extensions import TypedDict X = TypedDict('X', {'a': 'A'}) A = TypedDict('A', {'b': int}) x: X -reveal_type(x) # E: Revealed type is 'TypedDict('__main__.X', {'a': TypedDict('__main__.A', {'b': builtins.int})})' -reveal_type(x['a']['b']) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'TypedDict('__main__.X', {'a': TypedDict('__main__.A', {'b': builtins.int})})' +reveal_type(x['a']['b']) # N: Revealed type is 'builtins.int' [builtins fixtures/dict.pyi] [case testSelfRecursiveTypedDictInheriting] @@ -1351,7 +1351,7 @@ class Movie(MovieBase): # type: ignore # warning about recursive not fully suppo director: 'Movie' m: Movie -reveal_type(m['director']['name']) # E: Revealed type is 'builtins.str' +reveal_type(m['director']['name']) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [out] @@ -1367,7 +1367,7 @@ class HelpCommand(Command): pass hc = HelpCommand(subcommands=[]) -reveal_type(hc) # E: Revealed type is 'TypedDict('__main__.HelpCommand', {'subcommands': builtins.list[TypedDict('__main__.Command', {'subcommands': builtins.list[Any]})]})' +reveal_type(hc) # N: Revealed type is 'TypedDict('__main__.HelpCommand', {'subcommands': builtins.list[TypedDict('__main__.Command', {'subcommands': builtins.list[Any]})]})' [builtins fixtures/list.pyi] [out] @@ -1402,8 +1402,8 @@ def f(x: a.N) -> None: reveal_type(x['a']) [builtins fixtures/dict.pyi] [out] -tmp/b.py:4: error: Revealed type is 'TypedDict('a.N', {'a': builtins.str})' -tmp/b.py:5: error: Revealed type is 'builtins.str' +tmp/b.py:4: note: Revealed type is 'TypedDict('a.N', {'a': builtins.str})' +tmp/b.py:5: note: Revealed type is 'builtins.str' [case testTypedDictImportCycle] # flags: --new-semantic-analyzer @@ -1414,9 +1414,9 @@ class C: from b import tp x: tp -reveal_type(x['x']) # E: Revealed type is 'builtins.int' +reveal_type(x['x']) # N: Revealed type is 'builtins.int' -reveal_type(tp) # E: Revealed type is 'def () -> b.tp' +reveal_type(tp) # N: Revealed type is 'def () -> b.tp' tp(x='no') # E: Incompatible types (expression has type "str", TypedDict item "x" has type "int") [file b.py] @@ -1459,7 +1459,7 @@ def f1(x: T, y: S) -> Union[T, S]: ... A = TypedDict('A', {'y': int, 'x': str}) a: A -reveal_type(f1(**a)) # E: Revealed type is 'Union[builtins.str*, builtins.int*]' +reveal_type(f1(**a)) # N: Revealed type is 'Union[builtins.str*, builtins.int*]' [case testTypedDictAsStarStarArgCalleeKwargs] from mypy_extensions import TypedDict @@ -1512,14 +1512,14 @@ from mypy_extensions import TypedDict A = TypedDict('A', {'x': int, 'y': List[int]}) a: A -reveal_type(a.copy()) # E: Revealed type is 'TypedDict('__main__.A', {'x': builtins.int, 'y': builtins.list[builtins.int]})' +reveal_type(a.copy()) # N: Revealed type is 'TypedDict('__main__.A', {'x': builtins.int, 'y': builtins.list[builtins.int]})' a.has_key('x') # E: "A" has no attribute "has_key" # TODO: Better error message a.clear() # E: "A" has no attribute "clear" a.setdefault('invalid', 1) # E: TypedDict "A" has no key 'invalid' -reveal_type(a.setdefault('x', 1)) # E: Revealed type is 'builtins.int' -reveal_type(a.setdefault('y', [])) # E: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a.setdefault('x', 1)) # N: Revealed type is 'builtins.int' +reveal_type(a.setdefault('y', [])) # N: Revealed type is 'builtins.list[builtins.int]' a.setdefault('y', '') # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "List[int]" x = '' a.setdefault(x, 1) # E: Expected TypedDict key to be string literal @@ -1542,8 +1542,8 @@ a.update(d) # E: Argument 1 to "update" of "TypedDict" has incompatible type "Di from mypy_extensions import TypedDict A = TypedDict('A', {'x': int}) a = A(x=1) -reveal_type(a.copy()) # E: Revealed type is 'TypedDict('__main__.A', {'x': builtins.int})' -reveal_type(a.has_key('y')) # E: Revealed type is 'builtins.bool' +reveal_type(a.copy()) # N: Revealed type is 'TypedDict('__main__.A', {'x': builtins.int})' +reveal_type(a.has_key('y')) # N: Revealed type is 'builtins.bool' a.clear() # E: "A" has no attribute "clear" [builtins_py2 fixtures/dict.pyi] @@ -1556,10 +1556,10 @@ B = TypedDict('B', {'x': int}) a: A b: B -reveal_type(a.pop('x')) # E: Revealed type is 'builtins.int' -reveal_type(a.pop('y', [])) # E: Revealed type is 'builtins.list[builtins.int]' -reveal_type(a.pop('x', '')) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(a.pop('x', (1, 2))) # E: Revealed type is 'Union[builtins.int, Tuple[builtins.int, builtins.int]]' +reveal_type(a.pop('x')) # N: Revealed type is 'builtins.int' +reveal_type(a.pop('y', [])) # N: Revealed type is 'builtins.list[builtins.int]' +reveal_type(a.pop('x', '')) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(a.pop('x', (1, 2))) # N: Revealed type is 'Union[builtins.int, Tuple[builtins.int, builtins.int]]' a.pop('invalid', '') # E: TypedDict "A" has no key 'invalid' b.pop('x') # E: Key 'x' of TypedDict "B" cannot be deleted x = '' @@ -1598,5 +1598,5 @@ class Point(TypedDict): y: int p = Point(x=42, y=1337) -reveal_type(p) # E: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' +reveal_type(p) # N: Revealed type is 'TypedDict('__main__.Point', {'x': builtins.int, 'y': builtins.int})' [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 64f48070a137..80b764141e47 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -327,8 +327,8 @@ class C(Generic[X]): self.x = x # type: X ci: C[int] cs: C[str] -reveal_type(ci.x) # E: Revealed type is 'builtins.int*' -reveal_type(cs.x) # E: Revealed type is 'builtins.str*' +reveal_type(ci.x) # N: Revealed type is 'builtins.int*' +reveal_type(cs.x) # N: Revealed type is 'builtins.str*' [case testAttributeInGenericTypeWithTypevarValuesUsingInference1] from typing import TypeVar, Generic @@ -338,8 +338,8 @@ class C(Generic[X]): self.x = x # E: Need type annotation for 'x' ci: C[int] cs: C[str] -reveal_type(ci.x) # E: Revealed type is 'Any' -reveal_type(cs.x) # E: Revealed type is 'Any' +reveal_type(ci.x) # N: Revealed type is 'Any' +reveal_type(cs.x) # N: Revealed type is 'Any' [case testAttributeInGenericTypeWithTypevarValuesUsingInference2] from typing import TypeVar, Generic @@ -347,11 +347,11 @@ X = TypeVar('X', int, str) class C(Generic[X]): def f(self, x: X) -> None: self.x = 1 - reveal_type(self.x) # E: Revealed type is 'builtins.int' + reveal_type(self.x) # N: Revealed type is 'builtins.int' ci: C[int] cs: C[str] -reveal_type(ci.x) # E: Revealed type is 'builtins.int' -reveal_type(cs.x) # E: Revealed type is 'builtins.int' +reveal_type(ci.x) # N: Revealed type is 'builtins.int' +reveal_type(cs.x) # N: Revealed type is 'builtins.int' [case testAttributeInGenericTypeWithTypevarValuesUsingInference3] from typing import TypeVar, Generic @@ -362,8 +362,8 @@ class C(Generic[X]): self.y = self.x # E: Need type annotation for 'y' ci: C[int] cs: C[str] -reveal_type(ci.y) # E: Revealed type is 'Any' -reveal_type(cs.y) # E: Revealed type is 'Any' +reveal_type(ci.y) # N: Revealed type is 'Any' +reveal_type(cs.y) # N: Revealed type is 'Any' [case testInferredAttributeInGenericClassBodyWithTypevarValues] from typing import TypeVar, Generic @@ -465,9 +465,9 @@ class A: self.x = x # E: Need type annotation for 'x' self.y = [x] # E: Need type annotation for 'y' self.z = 1 -reveal_type(A().x) # E: Revealed type is 'Any' -reveal_type(A().y) # E: Revealed type is 'Any' -reveal_type(A().z) # E: Revealed type is 'builtins.int' +reveal_type(A().x) # N: Revealed type is 'Any' +reveal_type(A().y) # N: Revealed type is 'Any' +reveal_type(A().z) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index 74061daf7326..6c3e39697cd1 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -41,9 +41,9 @@ from typing import Any, Union def func(v: Union[int, Any]) -> None: if isinstance(v, int): - reveal_type(v) # E: Revealed type is 'builtins.int' + reveal_type(v) # N: Revealed type is 'builtins.int' else: - reveal_type(v) # E: Revealed type is 'Any' + reveal_type(v) # N: Revealed type is 'Any' [builtins fixtures/isinstance.pyi] [out] @@ -204,14 +204,14 @@ def u(x: T, y: S) -> Union[S, T]: pass a = None # type: Any -reveal_type(u(C(), None)) # E: Revealed type is '__main__.C*' -reveal_type(u(None, C())) # E: Revealed type is '__main__.C*' +reveal_type(u(C(), None)) # N: Revealed type is '__main__.C*' +reveal_type(u(None, C())) # N: Revealed type is '__main__.C*' -reveal_type(u(C(), a)) # E: Revealed type is 'Union[Any, __main__.C*]' -reveal_type(u(a, C())) # E: Revealed type is 'Union[__main__.C*, Any]' +reveal_type(u(C(), a)) # N: Revealed type is 'Union[Any, __main__.C*]' +reveal_type(u(a, C())) # N: Revealed type is 'Union[__main__.C*, Any]' -reveal_type(u(C(), C())) # E: Revealed type is '__main__.C*' -reveal_type(u(a, a)) # E: Revealed type is 'Any' +reveal_type(u(C(), C())) # N: Revealed type is '__main__.C*' +reveal_type(u(a, a)) # N: Revealed type is 'Any' [case testUnionSimplificationSpecialCase2] from typing import Any, TypeVar, Union @@ -223,8 +223,8 @@ S = TypeVar('S') def u(x: T, y: S) -> Union[S, T]: pass def f(x: T) -> None: - reveal_type(u(C(), x)) # E: Revealed type is 'Union[T`-1, __main__.C*]' - reveal_type(u(x, C())) # E: Revealed type is 'Union[__main__.C*, T`-1]' + reveal_type(u(C(), x)) # N: Revealed type is 'Union[T`-1, __main__.C*]' + reveal_type(u(x, C())) # N: Revealed type is 'Union[__main__.C*, T`-1]' [case testUnionSimplificationSpecialCase3] from typing import Any, TypeVar, Generic, Union @@ -239,7 +239,7 @@ class M(Generic[V]): def f(x: M[C]) -> None: y = x.get(None) - reveal_type(y) # E: Revealed type is '__main__.C' + reveal_type(y) # N: Revealed type is '__main__.C' [case testUnionSimplificationSpecialCases] from typing import Any, TypeVar, Union @@ -253,32 +253,32 @@ def u(x: T, y: S) -> Union[S, T]: pass a = None # type: Any # Base-class-Any and None, simplify -reveal_type(u(C(), None)) # E: Revealed type is '__main__.C*' -reveal_type(u(None, C())) # E: Revealed type is '__main__.C*' +reveal_type(u(C(), None)) # N: Revealed type is '__main__.C*' +reveal_type(u(None, C())) # N: Revealed type is '__main__.C*' # Normal instance type and None, simplify -reveal_type(u(1, None)) # E: Revealed type is 'builtins.int*' -reveal_type(u(None, 1)) # E: Revealed type is 'builtins.int*' +reveal_type(u(1, None)) # N: Revealed type is 'builtins.int*' +reveal_type(u(None, 1)) # N: Revealed type is 'builtins.int*' # Normal instance type and base-class-Any, no simplification -reveal_type(u(C(), 1)) # E: Revealed type is 'Union[builtins.int*, __main__.C*]' -reveal_type(u(1, C())) # E: Revealed type is 'Union[__main__.C*, builtins.int*]' +reveal_type(u(C(), 1)) # N: Revealed type is 'Union[builtins.int*, __main__.C*]' +reveal_type(u(1, C())) # N: Revealed type is 'Union[__main__.C*, builtins.int*]' # Normal instance type and Any, no simplification -reveal_type(u(1, a)) # E: Revealed type is 'Union[Any, builtins.int*]' -reveal_type(u(a, 1)) # E: Revealed type is 'Union[builtins.int*, Any]' +reveal_type(u(1, a)) # N: Revealed type is 'Union[Any, builtins.int*]' +reveal_type(u(a, 1)) # N: Revealed type is 'Union[builtins.int*, Any]' # Any and base-class-Any, no simplificaiton -reveal_type(u(C(), a)) # E: Revealed type is 'Union[Any, __main__.C*]' -reveal_type(u(a, C())) # E: Revealed type is 'Union[__main__.C*, Any]' +reveal_type(u(C(), a)) # N: Revealed type is 'Union[Any, __main__.C*]' +reveal_type(u(a, C())) # N: Revealed type is 'Union[__main__.C*, Any]' # Two normal instance types, simplify -reveal_type(u(1, object())) # E: Revealed type is 'builtins.object*' -reveal_type(u(object(), 1)) # E: Revealed type is 'builtins.object*' +reveal_type(u(1, object())) # N: Revealed type is 'builtins.object*' +reveal_type(u(object(), 1)) # N: Revealed type is 'builtins.object*' # Two normal instance types, no simplification -reveal_type(u(1, '')) # E: Revealed type is 'Union[builtins.str*, builtins.int*]' -reveal_type(u('', 1)) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(u(1, '')) # N: Revealed type is 'Union[builtins.str*, builtins.int*]' +reveal_type(u('', 1)) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [case testUnionSimplificationWithDuplicateItems] from typing import Any, TypeVar, Union @@ -292,11 +292,11 @@ def u(x: T, y: S, z: R) -> Union[R, S, T]: pass a = None # type: Any -reveal_type(u(1, 1, 1)) # E: Revealed type is 'builtins.int*' -reveal_type(u(C(), C(), None)) # E: Revealed type is '__main__.C*' -reveal_type(u(a, a, 1)) # E: Revealed type is 'Union[builtins.int*, Any]' -reveal_type(u(a, C(), a)) # E: Revealed type is 'Union[Any, __main__.C*]' -reveal_type(u('', 1, 1)) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(u(1, 1, 1)) # N: Revealed type is 'builtins.int*' +reveal_type(u(C(), C(), None)) # N: Revealed type is '__main__.C*' +reveal_type(u(a, a, 1)) # N: Revealed type is 'Union[builtins.int*, Any]' +reveal_type(u(a, C(), a)) # N: Revealed type is 'Union[Any, __main__.C*]' +reveal_type(u('', 1, 1)) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [case testUnionAndBinaryOperation] from typing import Union @@ -316,7 +316,7 @@ C = NamedTuple('C', [('x', int)]) def foo(a: Union[A, B, C]): if isinstance(a, (B, C)): - reveal_type(a) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]' + reveal_type(a) # N: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]' a.x a.y # E: Item "B" of "Union[B, C]" has no attribute "y" \ # E: Item "C" of "Union[B, C]" has no attribute "y" @@ -329,10 +329,10 @@ T = TypeVar('T') S = TypeVar('S') def u(x: T, y: S) -> Union[S, T]: pass -reveal_type(u(1, 2.3)) # E: Revealed type is 'builtins.float*' -reveal_type(u(2.3, 1)) # E: Revealed type is 'builtins.float*' -reveal_type(u(False, 2.2)) # E: Revealed type is 'builtins.float*' -reveal_type(u(2.2, False)) # E: Revealed type is 'builtins.float*' +reveal_type(u(1, 2.3)) # N: Revealed type is 'builtins.float*' +reveal_type(u(2.3, 1)) # N: Revealed type is 'builtins.float*' +reveal_type(u(False, 2.2)) # N: Revealed type is 'builtins.float*' +reveal_type(u(2.2, False)) # N: Revealed type is 'builtins.float*' [builtins fixtures/primitives.pyi] [case testSimplifyingUnionWithTypeTypes1] @@ -347,20 +347,20 @@ t_s = None # type: Type[str] t_a = None # type: Type[Any] # Two identical items -reveal_type(u(t_o, t_o)) # E: Revealed type is 'Type[builtins.object]' -reveal_type(u(t_s, t_s)) # E: Revealed type is 'Type[builtins.str]' -reveal_type(u(t_a, t_a)) # E: Revealed type is 'Type[Any]' -reveal_type(u(type, type)) # E: Revealed type is 'def (x: builtins.object) -> builtins.type' +reveal_type(u(t_o, t_o)) # N: Revealed type is 'Type[builtins.object]' +reveal_type(u(t_s, t_s)) # N: Revealed type is 'Type[builtins.str]' +reveal_type(u(t_a, t_a)) # N: Revealed type is 'Type[Any]' +reveal_type(u(type, type)) # N: Revealed type is 'def (x: builtins.object) -> builtins.type' # One type, other non-type -reveal_type(u(t_s, 1)) # E: Revealed type is 'Union[builtins.int*, Type[builtins.str]]' -reveal_type(u(1, t_s)) # E: Revealed type is 'Union[Type[builtins.str], builtins.int*]' -reveal_type(u(type, 1)) # E: Revealed type is 'Union[builtins.int*, def (x: builtins.object) -> builtins.type]' -reveal_type(u(1, type)) # E: Revealed type is 'Union[def (x: builtins.object) -> builtins.type, builtins.int*]' -reveal_type(u(t_a, 1)) # E: Revealed type is 'Union[builtins.int*, Type[Any]]' -reveal_type(u(1, t_a)) # E: Revealed type is 'Union[Type[Any], builtins.int*]' -reveal_type(u(t_o, 1)) # E: Revealed type is 'Union[builtins.int*, Type[builtins.object]]' -reveal_type(u(1, t_o)) # E: Revealed type is 'Union[Type[builtins.object], builtins.int*]' +reveal_type(u(t_s, 1)) # N: Revealed type is 'Union[builtins.int*, Type[builtins.str]]' +reveal_type(u(1, t_s)) # N: Revealed type is 'Union[Type[builtins.str], builtins.int*]' +reveal_type(u(type, 1)) # N: Revealed type is 'Union[builtins.int*, def (x: builtins.object) -> builtins.type]' +reveal_type(u(1, type)) # N: Revealed type is 'Union[def (x: builtins.object) -> builtins.type, builtins.int*]' +reveal_type(u(t_a, 1)) # N: Revealed type is 'Union[builtins.int*, Type[Any]]' +reveal_type(u(1, t_a)) # N: Revealed type is 'Union[Type[Any], builtins.int*]' +reveal_type(u(t_o, 1)) # N: Revealed type is 'Union[builtins.int*, Type[builtins.object]]' +reveal_type(u(1, t_o)) # N: Revealed type is 'Union[Type[builtins.object], builtins.int*]' [case testSimplifyingUnionWithTypeTypes2] from typing import TypeVar, Union, Type, Any @@ -375,26 +375,26 @@ t_a = None # type: Type[Any] t = None # type: type # Union with object -reveal_type(u(t_o, object())) # E: Revealed type is 'builtins.object*' -reveal_type(u(object(), t_o)) # E: Revealed type is 'builtins.object*' -reveal_type(u(t_s, object())) # E: Revealed type is 'builtins.object*' -reveal_type(u(object(), t_s)) # E: Revealed type is 'builtins.object*' -reveal_type(u(t_a, object())) # E: Revealed type is 'builtins.object*' -reveal_type(u(object(), t_a)) # E: Revealed type is 'builtins.object*' +reveal_type(u(t_o, object())) # N: Revealed type is 'builtins.object*' +reveal_type(u(object(), t_o)) # N: Revealed type is 'builtins.object*' +reveal_type(u(t_s, object())) # N: Revealed type is 'builtins.object*' +reveal_type(u(object(), t_s)) # N: Revealed type is 'builtins.object*' +reveal_type(u(t_a, object())) # N: Revealed type is 'builtins.object*' +reveal_type(u(object(), t_a)) # N: Revealed type is 'builtins.object*' # Union between type objects -reveal_type(u(t_o, t_a)) # E: Revealed type is 'Union[Type[Any], Type[builtins.object]]' -reveal_type(u(t_a, t_o)) # E: Revealed type is 'Union[Type[builtins.object], Type[Any]]' -reveal_type(u(t_s, t_o)) # E: Revealed type is 'Type[builtins.object]' -reveal_type(u(t_o, t_s)) # E: Revealed type is 'Type[builtins.object]' -reveal_type(u(t_o, type)) # E: Revealed type is 'Type[builtins.object]' -reveal_type(u(type, t_o)) # E: Revealed type is 'Type[builtins.object]' -reveal_type(u(t_a, t)) # E: Revealed type is 'builtins.type*' -reveal_type(u(t, t_a)) # E: Revealed type is 'builtins.type*' +reveal_type(u(t_o, t_a)) # N: Revealed type is 'Union[Type[Any], Type[builtins.object]]' +reveal_type(u(t_a, t_o)) # N: Revealed type is 'Union[Type[builtins.object], Type[Any]]' +reveal_type(u(t_s, t_o)) # N: Revealed type is 'Type[builtins.object]' +reveal_type(u(t_o, t_s)) # N: Revealed type is 'Type[builtins.object]' +reveal_type(u(t_o, type)) # N: Revealed type is 'Type[builtins.object]' +reveal_type(u(type, t_o)) # N: Revealed type is 'Type[builtins.object]' +reveal_type(u(t_a, t)) # N: Revealed type is 'builtins.type*' +reveal_type(u(t, t_a)) # N: Revealed type is 'builtins.type*' # The following should arguably not be simplified, but it's unclear how to fix then # without causing regressions elsewhere. -reveal_type(u(t_o, t)) # E: Revealed type is 'builtins.type*' -reveal_type(u(t, t_o)) # E: Revealed type is 'builtins.type*' +reveal_type(u(t_o, t)) # N: Revealed type is 'builtins.type*' +reveal_type(u(t, t_o)) # N: Revealed type is 'builtins.type*' [case testNotSimplifyingUnionWithMetaclass] from typing import TypeVar, Union, Type, Any @@ -410,11 +410,11 @@ def u(x: T, y: S) -> Union[S, T]: pass a: Any t_a: Type[A] -reveal_type(u(M(*a), t_a)) # E: Revealed type is '__main__.M*' -reveal_type(u(t_a, M(*a))) # E: Revealed type is '__main__.M*' +reveal_type(u(M(*a), t_a)) # N: Revealed type is '__main__.M*' +reveal_type(u(t_a, M(*a))) # N: Revealed type is '__main__.M*' -reveal_type(u(M2(*a), t_a)) # E: Revealed type is 'Union[Type[__main__.A], __main__.M2*]' -reveal_type(u(t_a, M2(*a))) # E: Revealed type is 'Union[__main__.M2*, Type[__main__.A]]' +reveal_type(u(M2(*a), t_a)) # N: Revealed type is 'Union[Type[__main__.A], __main__.M2*]' +reveal_type(u(t_a, M2(*a))) # N: Revealed type is 'Union[__main__.M2*, Type[__main__.A]]' [case testSimplifyUnionWithCallable] from typing import TypeVar, Union, Any, Callable @@ -435,21 +435,21 @@ i_C: Callable[[int], C] # TODO: Test argument names and kinds once we have flexible callable types. -reveal_type(u(D_C, D_C)) # E: Revealed type is 'def (__main__.D) -> __main__.C' +reveal_type(u(D_C, D_C)) # N: Revealed type is 'def (__main__.D) -> __main__.C' -reveal_type(u(A_C, D_C)) # E: Revealed type is 'Union[def (__main__.D) -> __main__.C, def (Any) -> __main__.C]' -reveal_type(u(D_C, A_C)) # E: Revealed type is 'Union[def (Any) -> __main__.C, def (__main__.D) -> __main__.C]' +reveal_type(u(A_C, D_C)) # N: Revealed type is 'Union[def (__main__.D) -> __main__.C, def (Any) -> __main__.C]' +reveal_type(u(D_C, A_C)) # N: Revealed type is 'Union[def (Any) -> __main__.C, def (__main__.D) -> __main__.C]' -reveal_type(u(D_A, D_C)) # E: Revealed type is 'Union[def (__main__.D) -> __main__.C, def (__main__.D) -> Any]' -reveal_type(u(D_C, D_A)) # E: Revealed type is 'Union[def (__main__.D) -> Any, def (__main__.D) -> __main__.C]' +reveal_type(u(D_A, D_C)) # N: Revealed type is 'Union[def (__main__.D) -> __main__.C, def (__main__.D) -> Any]' +reveal_type(u(D_C, D_A)) # N: Revealed type is 'Union[def (__main__.D) -> Any, def (__main__.D) -> __main__.C]' -reveal_type(u(D_C, C_C)) # E: Revealed type is 'def (__main__.D) -> __main__.C' -reveal_type(u(C_C, D_C)) # E: Revealed type is 'def (__main__.D) -> __main__.C' +reveal_type(u(D_C, C_C)) # N: Revealed type is 'def (__main__.D) -> __main__.C' +reveal_type(u(C_C, D_C)) # N: Revealed type is 'def (__main__.D) -> __main__.C' -reveal_type(u(D_C, D_D)) # E: Revealed type is 'def (__main__.D) -> __main__.C' -reveal_type(u(D_D, D_C)) # E: Revealed type is 'def (__main__.D) -> __main__.C' +reveal_type(u(D_C, D_D)) # N: Revealed type is 'def (__main__.D) -> __main__.C' +reveal_type(u(D_D, D_C)) # N: Revealed type is 'def (__main__.D) -> __main__.C' -reveal_type(u(D_C, i_C)) # E: Revealed type is 'Union[def (builtins.int) -> __main__.C, def (__main__.D) -> __main__.C]' +reveal_type(u(D_C, i_C)) # N: Revealed type is 'Union[def (builtins.int) -> __main__.C, def (__main__.D) -> __main__.C]' [case testUnionOperatorMethodSpecialCase] from typing import Union @@ -463,17 +463,17 @@ class E: [case testUnionSimplificationWithBoolIntAndFloat] from typing import List, Union l = reveal_type([]) # type: List[Union[bool, int, float]] \ - # E: Revealed type is 'builtins.list[builtins.float]' + # N: Revealed type is 'builtins.list[builtins.float]' reveal_type(l) \ - # E: Revealed type is 'builtins.list[Union[builtins.bool, builtins.int, builtins.float]]' + # N: Revealed type is 'builtins.list[Union[builtins.bool, builtins.int, builtins.float]]' [builtins fixtures/list.pyi] [case testUnionSimplificationWithBoolIntAndFloat2] from typing import List, Union l = reveal_type([]) # type: List[Union[bool, int, float, str]] \ - # E: Revealed type is 'builtins.list[Union[builtins.float, builtins.str]]' + # N: Revealed type is 'builtins.list[Union[builtins.float, builtins.str]]' reveal_type(l) \ - # E: Revealed type is 'builtins.list[Union[builtins.bool, builtins.int, builtins.float, builtins.str]]' + # N: Revealed type is 'builtins.list[Union[builtins.bool, builtins.int, builtins.float, builtins.str]]' [builtins fixtures/list.pyi] [case testNestedUnionsProcessedCorrectly] @@ -485,9 +485,9 @@ class C: pass def foo(bar: Union[Union[A, B], C]) -> None: if isinstance(bar, A): - reveal_type(bar) # E: Revealed type is '__main__.A' + reveal_type(bar) # N: Revealed type is '__main__.A' else: - reveal_type(bar) # E: Revealed type is 'Union[__main__.B, __main__.C]' + reveal_type(bar) # N: Revealed type is 'Union[__main__.B, __main__.C]' [builtins fixtures/isinstance.pyi] [out] @@ -498,8 +498,8 @@ a: Any if bool(): x = a # TODO: Maybe we should infer Any as the type instead. - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/bool.pyi] [case testAssignAnyToUnionWithAny] @@ -508,8 +508,8 @@ x: Union[int, Any] a: Any if bool(): x = a - reveal_type(x) # E: Revealed type is 'Any' -reveal_type(x) # E: Revealed type is 'Union[builtins.int, Any]' + reveal_type(x) # N: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, Any]' [builtins fixtures/bool.pyi] [case testUnionMultiassignSingle] @@ -517,19 +517,19 @@ from typing import Union, Tuple, Any a: Union[Tuple[int], Tuple[float]] (a1,) = a -reveal_type(a1) # E: Revealed type is 'builtins.float' +reveal_type(a1) # N: Revealed type is 'builtins.float' b: Union[Tuple[int], Tuple[str]] (b1,) = b -reveal_type(b1) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(b1) # N: Revealed type is 'Union[builtins.int, builtins.str]' [case testUnionMultiassignDouble] from typing import Union, Tuple c: Union[Tuple[int, int], Tuple[int, float]] (c1, c2) = c -reveal_type(c1) # E: Revealed type is 'builtins.int' -reveal_type(c2) # E: Revealed type is 'builtins.float' +reveal_type(c1) # N: Revealed type is 'builtins.int' +reveal_type(c2) # N: Revealed type is 'builtins.float' [case testUnionMultiassignGeneric] from typing import Union, Tuple, TypeVar @@ -540,16 +540,16 @@ def pack_two(x: T, y: S) -> Union[Tuple[T, T], Tuple[S, S]]: pass (x, y) = pack_two(1, 'a') -reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [case testUnionMultiassignAny] from typing import Union, Tuple, Any d: Union[Any, Tuple[float, float]] (d1, d2) = d -reveal_type(d1) # E: Revealed type is 'Union[Any, builtins.float]' -reveal_type(d2) # E: Revealed type is 'Union[Any, builtins.float]' +reveal_type(d1) # N: Revealed type is 'Union[Any, builtins.float]' +reveal_type(d2) # N: Revealed type is 'Union[Any, builtins.float]' e: Union[Any, Tuple[float, float], int] (e1, e2) = e # E: 'builtins.int' object is not iterable @@ -562,7 +562,7 @@ class B(A): pass class C(A): pass a: Union[List[B], List[C]] x, y = a -reveal_type(x) # E: Revealed type is 'Union[__main__.B*, __main__.C*]' +reveal_type(x) # N: Revealed type is 'Union[__main__.B*, __main__.C*]' [builtins fixtures/list.pyi] [case testUnionMultiassignRebind] @@ -574,11 +574,11 @@ class C(A): pass obj: object a: Union[List[B], List[C]] obj, new = a -reveal_type(obj) # E: Revealed type is 'Union[__main__.B*, __main__.C*]' -reveal_type(new) # E: Revealed type is 'Union[__main__.B*, __main__.C*]' +reveal_type(obj) # N: Revealed type is 'Union[__main__.B*, __main__.C*]' +reveal_type(new) # N: Revealed type is 'Union[__main__.B*, __main__.C*]' obj = 1 -reveal_type(obj) # E: Revealed type is 'builtins.int' +reveal_type(obj) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] [case testUnionMultiassignAlreadyDeclared] @@ -593,21 +593,21 @@ b: Union[Tuple[float, int], Tuple[int, int]] b1: object b2: int (b1, b2) = b -reveal_type(b1) # E: Revealed type is 'builtins.float' -reveal_type(b2) # E: Revealed type is 'builtins.int' +reveal_type(b1) # N: Revealed type is 'builtins.float' +reveal_type(b2) # N: Revealed type is 'builtins.int' c: Union[Tuple[int, int], Tuple[int, int]] c1: object c2: int (c1, c2) = c -reveal_type(c1) # E: Revealed type is 'builtins.int' -reveal_type(c2) # E: Revealed type is 'builtins.int' +reveal_type(c1) # N: Revealed type is 'builtins.int' +reveal_type(c2) # N: Revealed type is 'builtins.int' d: Union[Tuple[int, int], Tuple[int, float]] d1: object (d1, d2) = d -reveal_type(d1) # E: Revealed type is 'builtins.int' -reveal_type(d2) # E: Revealed type is 'builtins.float' +reveal_type(d1) # N: Revealed type is 'builtins.int' +reveal_type(d2) # N: Revealed type is 'builtins.float' [case testUnionMultiassignIndexed] from typing import Union, Tuple, List @@ -620,8 +620,8 @@ b: B a: Union[Tuple[int, int], Tuple[int, object]] (x[0], b.x) = a -reveal_type(x[0]) # E: Revealed type is 'builtins.int*' -reveal_type(b.x) # E: Revealed type is 'builtins.object' +reveal_type(x[0]) # N: Revealed type is 'builtins.int*' +reveal_type(b.x) # N: Revealed type is 'builtins.object' [builtins fixtures/list.pyi] [case testUnionMultiassignIndexedWithError] @@ -637,8 +637,8 @@ b: B a: Union[Tuple[int, int], Tuple[int, object]] (x[0], b.x) = a # E: Incompatible types in assignment (expression has type "int", target has type "A") \ # E: Incompatible types in assignment (expression has type "object", variable has type "int") -reveal_type(x[0]) # E: Revealed type is '__main__.A*' -reveal_type(b.x) # E: Revealed type is 'builtins.int' +reveal_type(x[0]) # N: Revealed type is '__main__.A*' +reveal_type(b.x) # N: Revealed type is 'builtins.int' [builtins fixtures/list.pyi] [case testUnionMultiassignPacked] @@ -649,9 +649,9 @@ a1: int a2: object (a1, *xs, a2) = a -reveal_type(a1) # E: Revealed type is 'builtins.int' -reveal_type(xs) # E: Revealed type is 'builtins.list[builtins.int*]' -reveal_type(a2) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(a1) # N: Revealed type is 'builtins.int' +reveal_type(xs) # N: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(a2) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/list.pyi] [case testUnpackingUnionOfListsInFunction] @@ -665,8 +665,8 @@ def f(x: bool) -> Union[List[int], List[str]]: def g(x: bool) -> None: a, b = f(x) - reveal_type(a) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' - reveal_type(b) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(a) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(b) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [builtins fixtures/list.pyi] [case testUnionOfVariableLengthTupleUnpacking] @@ -680,8 +680,8 @@ x = make_tuple() a, b = x # E: Too many values to unpack (2 expected, 3 provided) a, b, c = x # E: Need more than 2 values to unpack (3 expected) c, *d = x -reveal_type(c) # E: Revealed type is 'builtins.int' -reveal_type(d) # E: Revealed type is 'builtins.list[builtins.int*]' +reveal_type(c) # N: Revealed type is 'builtins.int' +reveal_type(d) # N: Revealed type is 'builtins.list[builtins.int*]' [builtins fixtures/tuple.pyi] [case testUnionOfNonIterableUnpacking] @@ -690,8 +690,8 @@ bad: Union[int, str] x, y = bad # E: 'builtins.int' object is not iterable \ # E: 'builtins.str' object is not iterable -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(y) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(y) # N: Revealed type is 'Any' [out] [case testUnionAlwaysTooMany] @@ -699,8 +699,8 @@ from typing import Union, Tuple bad: Union[Tuple[int, int, int], Tuple[str, str, str]] x, y = bad # E: Too many values to unpack (2 expected, 3 provided) -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(y) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(y) # N: Revealed type is 'Any' [builtins fixtures/tuple.pyi] [out] @@ -709,10 +709,10 @@ from typing import Union, Tuple bad: Union[Tuple[int, int, int], Tuple[str, str, str]] x, y, z, w = bad # E: Need more than 3 values to unpack (4 expected) -reveal_type(x) # E: Revealed type is 'Any' -reveal_type(y) # E: Revealed type is 'Any' -reveal_type(z) # E: Revealed type is 'Any' -reveal_type(w) # E: Revealed type is 'Any' +reveal_type(x) # N: Revealed type is 'Any' +reveal_type(y) # N: Revealed type is 'Any' +reveal_type(z) # N: Revealed type is 'Any' +reveal_type(w) # N: Revealed type is 'Any' [builtins fixtures/tuple.pyi] [out] @@ -721,9 +721,9 @@ from typing import Union, Tuple good: Union[Tuple[int, int], Tuple[str, str]] x, y = t = good -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(t) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(t) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]' [builtins fixtures/tuple.pyi] [out] @@ -732,9 +732,9 @@ from typing import Union, Tuple good: Union[Tuple[int, int], Tuple[str, str]] t = x, y = good -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(t) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(t) # N: Revealed type is 'Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]' [builtins fixtures/tuple.pyi] [out] @@ -743,10 +743,10 @@ from typing import Union, Tuple good: Union[Tuple[int, int], Tuple[str, str]] x, y = a, b = good -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(a) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(b) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(a) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(b) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/tuple.pyi] [out] @@ -755,9 +755,9 @@ from typing import Union, List good: Union[List[int], List[str]] lst = x, y = good -reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' -reveal_type(lst) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(lst) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' [builtins fixtures/list.pyi] [out] @@ -766,10 +766,10 @@ from typing import Union, List good: Union[List[int], List[str]] x, *y, z = lst = good -reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' -reveal_type(y) # E: Revealed type is 'Union[builtins.list[builtins.int*], builtins.list[builtins.str*]]' -reveal_type(z) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' -reveal_type(lst) # E: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(y) # N: Revealed type is 'Union[builtins.list[builtins.int*], builtins.list[builtins.str*]]' +reveal_type(z) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' +reveal_type(lst) # N: Revealed type is 'Union[builtins.list[builtins.int], builtins.list[builtins.str]]' [builtins fixtures/list.pyi] [out] @@ -783,15 +783,15 @@ class NTStr(NamedTuple): y: str t1: NTInt -reveal_type(t1.__iter__) # E: Revealed type is 'def () -> typing.Iterator[builtins.int*]' +reveal_type(t1.__iter__) # N: Revealed type is 'def () -> typing.Iterator[builtins.int*]' nt: Union[NTInt, NTStr] -reveal_type(nt.__iter__) # E: Revealed type is 'Union[def () -> typing.Iterator[builtins.int*], def () -> typing.Iterator[builtins.str*]]' +reveal_type(nt.__iter__) # N: Revealed type is 'Union[def () -> typing.Iterator[builtins.int*], def () -> typing.Iterator[builtins.str*]]' for nx in nt: - reveal_type(nx) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(nx) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' t: Union[Tuple[int, int], Tuple[str, str]] for x in t: - reveal_type(x) # E: Revealed type is 'Union[builtins.int*, builtins.str*]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int*, builtins.str*]' [builtins fixtures/for.pyi] [out] @@ -800,13 +800,13 @@ from typing import Union, List, Tuple t: Union[List[Tuple[int, int]], List[Tuple[str, str]]] for x, y in t: - reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' - reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' t2: List[Union[Tuple[int, int], Tuple[str, str]]] for x2, y2 in t2: - reveal_type(x2) # E: Revealed type is 'Union[builtins.int, builtins.str]' - reveal_type(y2) # E: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(x2) # N: Revealed type is 'Union[builtins.int, builtins.str]' + reveal_type(y2) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/for.pyi] [out] @@ -822,16 +822,16 @@ t1: Union[Tuple[A, A], Tuple[B, B]] t2: Union[Tuple[int, int], Tuple[str, str]] x, y = t1 -reveal_type(x) # E: Revealed type is 'Union[__main__.A, __main__.B]' -reveal_type(y) # E: Revealed type is 'Union[__main__.A, __main__.B]' +reveal_type(x) # N: Revealed type is 'Union[__main__.A, __main__.B]' +reveal_type(y) # N: Revealed type is 'Union[__main__.A, __main__.B]' x, y = t2 -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' x, y = object(), object() -reveal_type(x) # E: Revealed type is 'builtins.object' -reveal_type(y) # E: Revealed type is 'builtins.object' +reveal_type(x) # N: Revealed type is 'builtins.object' +reveal_type(y) # N: Revealed type is 'builtins.object' [builtins fixtures/tuple.pyi] [out] @@ -840,9 +840,9 @@ from typing import Union, Tuple t: Union[Tuple[int, Tuple[int, int]], Tuple[str, Tuple[str, str]]] x, (y, z) = t -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(z) # E: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(z) # N: Revealed type is 'Union[builtins.int, builtins.str]' [builtins fixtures/tuple.pyi] [out] @@ -854,9 +854,9 @@ class B: pass t: Union[Tuple[int, Union[Tuple[int, int], Tuple[A, A]]], Tuple[str, Union[Tuple[str, str], Tuple[B, B]]]] x, (y, z) = t -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' -reveal_type(z) # E: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' +reveal_type(z) # N: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' [builtins fixtures/tuple.pyi] [out] @@ -872,9 +872,9 @@ z: object t: Union[Tuple[int, Union[Tuple[int, int], Tuple[A, A]]], Tuple[str, Union[Tuple[str, str], Tuple[B, B]]]] x, (y, z) = t -reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]' -reveal_type(y) # E: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' -reveal_type(z) # E: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' +reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]' +reveal_type(y) # N: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' +reveal_type(z) # N: Revealed type is 'Union[builtins.int, __main__.A, builtins.str, __main__.B]' [builtins fixtures/tuple.pyi] [out] @@ -889,7 +889,7 @@ x, _ = d.get(a, (None, None)) for y in x: pass # E: Item "None" of "Optional[List[Tuple[str, str]]]" has no attribute "__iter__" (not iterable) if x: for s, t in x: - reveal_type(s) # E: Revealed type is 'builtins.str' + reveal_type(s) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [out] @@ -905,7 +905,7 @@ x, _ = d.get(a, (None, None)) for y in x: pass # E: Item "None" of "Optional[List[Tuple[str, str]]]" has no attribute "__iter__" (not iterable) if x: for s, t in x: - reveal_type(s) # E: Revealed type is 'builtins.str' + reveal_type(s) # N: Revealed type is 'builtins.str' [builtins fixtures/dict.pyi] [out] @@ -917,7 +917,7 @@ x: object a: Any d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, (None, None)) -reveal_type(x) # E: Revealed type is 'Union[builtins.list[Tuple[builtins.str, builtins.str]], None]' +reveal_type(x) # N: Revealed type is 'Union[builtins.list[Tuple[builtins.str, builtins.str]], None]' if x: for y in x: pass @@ -931,7 +931,7 @@ from typing import Dict, Tuple, List, Any a: Any d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, ([], [])) -reveal_type(x) # E: Revealed type is 'Union[builtins.list[Tuple[builtins.str, builtins.str]], builtins.list[]]' +reveal_type(x) # N: Revealed type is 'Union[builtins.list[Tuple[builtins.str, builtins.str]], builtins.list[]]' for y in x: pass [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 7ac01734480d..593f24523242 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -165,7 +165,7 @@ else: def foo(): # type: () -> str return '' -reveal_type(foo()) # E: Revealed type is 'builtins.str' +reveal_type(foo()) # N: Revealed type is 'builtins.str' [builtins_py2 fixtures/ops.pyi] [out] @@ -175,7 +175,7 @@ if sys.version_info[0] >= 3: def foo() -> int: return 0 else: def foo() -> str: return '' -reveal_type(foo()) # E: Revealed type is 'builtins.int' +reveal_type(foo()) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [out] @@ -189,7 +189,7 @@ else: def foo(): # type: () -> str return '' -reveal_type(foo()) # E: Revealed type is 'builtins.str' +reveal_type(foo()) # N: Revealed type is 'builtins.str' [builtins_py2 fixtures/ops.pyi] [out] @@ -199,7 +199,7 @@ if not (sys.version_info[0] < 3): def foo() -> int: return 0 else: def foo() -> str: return '' -reveal_type(foo()) # E: Revealed type is 'builtins.int' +reveal_type(foo()) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [out] @@ -364,7 +364,7 @@ class C: def foo(self) -> int: return 0 else: def foo(self) -> str: return '' -reveal_type(C().foo()) # E: Revealed type is 'builtins.int' +reveal_type(C().foo()) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [out] @@ -375,7 +375,7 @@ def foo() -> None: x = '' else: x = 0 - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -387,7 +387,7 @@ class C: x = '' else: x = 0 - reveal_type(x) # E: Revealed type is 'builtins.str' + reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -458,7 +458,7 @@ if sys.version_info == (3, 5): x = "foo" else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -469,7 +469,7 @@ if sys.version_info == (3, 6): x = "foo" else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [out] @@ -480,7 +480,7 @@ if sys.platform == 'linux': x = "foo" else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -491,7 +491,7 @@ if sys.platform == 'linux': x = "foo" else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [out] @@ -502,7 +502,7 @@ if sys.platform.startswith('win'): x = "foo" else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [out] @@ -519,14 +519,14 @@ e = (PY2 or PY3) and 's' f = (PY3 or PY2) and 's' g = (PY2 or PY3) or 's' h = (PY3 or PY2) or 's' -reveal_type(a) # E: Revealed type is 'builtins.bool' -reveal_type(b) # E: Revealed type is 'builtins.str' -reveal_type(c) # E: Revealed type is 'builtins.str' -reveal_type(d) # E: Revealed type is 'builtins.bool' -reveal_type(e) # E: Revealed type is 'builtins.str' -reveal_type(f) # E: Revealed type is 'builtins.str' -reveal_type(g) # E: Revealed type is 'builtins.bool' -reveal_type(h) # E: Revealed type is 'builtins.bool' +reveal_type(a) # N: Revealed type is 'builtins.bool' +reveal_type(b) # N: Revealed type is 'builtins.str' +reveal_type(c) # N: Revealed type is 'builtins.str' +reveal_type(d) # N: Revealed type is 'builtins.bool' +reveal_type(e) # N: Revealed type is 'builtins.str' +reveal_type(f) # N: Revealed type is 'builtins.str' +reveal_type(g) # N: Revealed type is 'builtins.bool' +reveal_type(h) # N: Revealed type is 'builtins.bool' [builtins fixtures/ops.pyi] [out] @@ -540,12 +540,12 @@ if PY2 and sys.platform == 'linux': x = 'foo' else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.int' +reveal_type(x) # N: Revealed type is 'builtins.int' if sys.platform == 'linux' and PY2: y = 'foo' else: y = 3 -reveal_type(y) # E: Revealed type is 'builtins.int' +reveal_type(y) # N: Revealed type is 'builtins.int' [builtins fixtures/ops.pyi] [case testShortCircuitOrWithConditionalAssignment] @@ -558,12 +558,12 @@ if PY2 or sys.platform == 'linux': x = 'foo' else: x = 3 -reveal_type(x) # E: Revealed type is 'builtins.str' +reveal_type(x) # N: Revealed type is 'builtins.str' if sys.platform == 'linux' or PY2: y = 'foo' else: y = 3 -reveal_type(y) # E: Revealed type is 'builtins.str' +reveal_type(y) # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] [case testShortCircuitNoEvaluation] @@ -609,13 +609,13 @@ class A: pass class B(A): pass x = A() -reveal_type(x) # E: Revealed type is '__main__.A' +reveal_type(x) # N: Revealed type is '__main__.A' if typing.TYPE_CHECKING: assert isinstance(x, B) - reveal_type(x) # E: Revealed type is '__main__.B' + reveal_type(x) # N: Revealed type is '__main__.B' -reveal_type(x) # E: Revealed type is '__main__.B' +reveal_type(x) # N: Revealed type is '__main__.B' [builtins fixtures/isinstancelist.pyi] @@ -627,21 +627,21 @@ from typing import Any Parent: Any class Child(Parent): def foo(self) -> int: - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' if self is None: reveal_type(self) return None - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' return 3 def bar(self) -> int: if 1: self = super(Child, self).something() - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' if self is None: reveal_type(self) return None - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' return 3 [builtins fixtures/isinstance.pyi] @@ -652,30 +652,30 @@ from typing import Any Parent: Any class Child(Parent): def foo(self) -> int: - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' if self is None: - reveal_type(self) # E: Revealed type is 'None' + reveal_type(self) # N: Revealed type is 'None' return None - reveal_type(self) # E: Revealed type is '__main__.Child' + reveal_type(self) # N: Revealed type is '__main__.Child' return 3 [builtins fixtures/isinstance.pyi] [case testUnreachableAfterToplevelAssert] import sys -reveal_type(0) # E: Revealed type is 'builtins.int' +reveal_type(0) # N: Revealed type is 'builtins.int' assert sys.platform == 'lol' reveal_type('') # No error here :-) [builtins fixtures/ops.pyi] [case testUnreachableAfterToplevelAssert2] import sys -reveal_type(0) # E: Revealed type is 'builtins.int' +reveal_type(0) # N: Revealed type is 'builtins.int' assert sys.version_info[0] == 1 reveal_type('') # No error here :-) [builtins fixtures/ops.pyi] [case testUnreachableAfterToplevelAssert3] -reveal_type(0) # E: Revealed type is 'builtins.int' +reveal_type(0) # N: Revealed type is 'builtins.int' MYPY = False assert not MYPY reveal_type('') # No error here :-) @@ -683,7 +683,7 @@ reveal_type('') # No error here :-) [case testUnreachableAfterToplevelAssert4] # flags: --always-false NOPE -reveal_type(0) # E: Revealed type is 'builtins.int' +reveal_type(0) # N: Revealed type is 'builtins.int' NOPE = False assert NOPE reveal_type('') # No error here :-) @@ -712,6 +712,6 @@ def bar() -> None: pass import sys if sys.version_info[0] >= 2: assert sys.platform == 'lol' - reveal_type('') # E: Revealed type is 'builtins.str' -reveal_type('') # E: Revealed type is 'builtins.str' + reveal_type('') # N: Revealed type is 'builtins.str' +reveal_type('') # N: Revealed type is 'builtins.str' [builtins fixtures/ops.pyi] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index cad333eb2746..ceca1fe57c94 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -123,7 +123,7 @@ T4 = TypeVar('T4') def f(a: T1, b: T2, c: T3, d: T4) -> Tuple[T1, T2, T3, T4]: ... x: Tuple[int, str] y: Tuple[float, bool] -reveal_type(f(*x, *y)) # E: Revealed type is 'Tuple[builtins.int*, builtins.str*, builtins.float*, builtins.bool*]' +reveal_type(f(*x, *y)) # N: Revealed type is 'Tuple[builtins.int*, builtins.str*, builtins.float*, builtins.bool*]' [builtins fixtures/list.pyi] [case testCallVarargsFunctionWithIterableAndPositional] @@ -625,9 +625,9 @@ from typing import TypeVar T = TypeVar('T') def f(*args: T) -> T: ... -reveal_type(f(*(1, None))) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(f(1, *(None, 1))) # E: Revealed type is 'Union[builtins.int, None]' -reveal_type(f(1, *(1, None))) # E: Revealed type is 'Union[builtins.int, None]' +reveal_type(f(*(1, None))) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(f(1, *(None, 1))) # N: Revealed type is 'Union[builtins.int, None]' +reveal_type(f(1, *(1, None))) # N: Revealed type is 'Union[builtins.int, None]' [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 73acfabd8991..c45ae9ddae9e 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -391,8 +391,8 @@ follow_imports = skip [file a.py] / # No error reported [out] -main.py:2: error: Revealed type is 'Any' -main.py:4: error: Revealed type is 'Any' +main.py:2: note: Revealed type is 'Any' +main.py:4: note: Revealed type is 'Any' [case testConfigFollowImportsError] # cmd: mypy main.py @@ -409,8 +409,8 @@ follow_imports = error [out] main.py:1: error: Import of 'a' ignored main.py:1: note: (Using --follow-imports=error, module not passed on command line) -main.py:2: error: Revealed type is 'Any' -main.py:4: error: Revealed type is 'Any' +main.py:2: note: Revealed type is 'Any' +main.py:4: note: Revealed type is 'Any' [case testConfigFollowImportsSelective] # cmd: mypy main.py @@ -447,10 +447,10 @@ bla bla normal.py:2: error: Unsupported operand types for + ("int" and "str") main.py:4: error: Import of 'error' ignored main.py:4: note: (Using --follow-imports=error, module not passed on command line) -main.py:5: error: Revealed type is 'builtins.int' -main.py:6: error: Revealed type is 'builtins.int' -main.py:7: error: Revealed type is 'Any' -main.py:8: error: Revealed type is 'Any' +main.py:5: note: Revealed type is 'builtins.int' +main.py:6: note: Revealed type is 'builtins.int' +main.py:7: note: Revealed type is 'Any' +main.py:8: note: Revealed type is 'Any' [case testConfigSilentMissingImportsOff] # cmd: mypy main.py @@ -463,7 +463,7 @@ ignore_missing_imports = False [out] main.py:1: error: Cannot find module named 'missing' main.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports -main.py:2: error: Revealed type is 'Any' +main.py:2: note: Revealed type is 'Any' [case testConfigSilentMissingImportsOn] # cmd: mypy main.py @@ -474,7 +474,7 @@ reveal_type(missing.x) # Expect Any [[mypy] ignore_missing_imports = True [out] -main.py:2: error: Revealed type is 'Any' +main.py:2: note: Revealed type is 'Any' [case testConfigNoErrorForUnknownXFlagInSubsection] # cmd: mypy -c pass diff --git a/test-data/unit/errorstream.test b/test-data/unit/errorstream.test index 6877a2098f88..c2497ba17a92 100644 --- a/test-data/unit/errorstream.test +++ b/test-data/unit/errorstream.test @@ -47,8 +47,8 @@ x = 1 + 1 [out] ==== Errors flushed ==== -b.py:3: error: Revealed type is 'builtins.int' +b.py:3: note: Revealed type is 'builtins.int' b.py:5: error: Unsupported operand types for / ("int" and "str") ==== Errors flushed ==== a.py:2: error: Unsupported operand types for + ("int" and "str") -a.py:4: error: Revealed type is 'builtins.int' +a.py:4: note: Revealed type is 'builtins.int' diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index d4d667e5c755..b8daaeb366e5 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -996,11 +996,11 @@ reveal_type(b.A) class A: pass [out] == -a.py:2: error: Revealed type is 'Any' -a.py:3: error: Revealed type is 'Any' +a.py:2: note: Revealed type is 'Any' +a.py:3: note: Revealed type is 'Any' == -a.py:2: error: Revealed type is 'Any' -a.py:3: error: Revealed type is 'Any' +a.py:2: note: Revealed type is 'Any' +a.py:3: note: Revealed type is 'Any' [case testSkipImportsWithinPackage] # cmd: mypy a/b.py @@ -1019,7 +1019,7 @@ import x 1 + '' [out] == -a/b.py:3: error: Revealed type is 'Any' +a/b.py:3: note: Revealed type is 'Any' == a/b.py:3: error: Unsupported operand types for + ("int" and "str") @@ -1905,7 +1905,7 @@ reveal_type(b.x) [out] == == -a.py:2: error: Revealed type is 'builtins.str' +a.py:2: note: Revealed type is 'builtins.str' [case testModuleToPackage] [file a.py] @@ -1923,7 +1923,7 @@ reveal_type(b.x) [out] == == -a.py:2: error: Revealed type is 'builtins.int' +a.py:2: note: Revealed type is 'builtins.int' [case testQualifiedSubpackage1] [file c/__init__.py] diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index 4886f78d1268..3ca3eec68e12 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -1776,7 +1776,7 @@ class B: [out] == == -a.py:4: error: Revealed type is 'builtins.int' +a.py:4: note: Revealed type is 'builtins.int' [case testStripRevealType] import a @@ -1786,9 +1786,9 @@ def f() -> int: pass [file a.py.2] def f() -> str: pass [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' == -main:2: error: Revealed type is 'builtins.str' +main:2: note: Revealed type is 'builtins.str' [case testDecoratorTypeAfterReprocessing] import a @@ -1809,13 +1809,13 @@ def f() -> Iterator[None]: 2: , __main__ 3: , __main__, a [out] -main:2: error: Revealed type is 'contextlib.GeneratorContextManager[None]' +main:2: note: Revealed type is 'contextlib.GeneratorContextManager[None]' == a.py:3: error: Cannot find module named 'b' a.py:3: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports -main:2: error: Revealed type is 'contextlib.GeneratorContextManager[None]' +main:2: note: Revealed type is 'contextlib.GeneratorContextManager[None]' == -main:2: error: Revealed type is 'contextlib.GeneratorContextManager[None]' +main:2: note: Revealed type is 'contextlib.GeneratorContextManager[None]' [case testDecoratorSpecialCase1] import a @@ -2567,9 +2567,9 @@ class Wrapper: def foo(cls, x: str) -> str: ... [builtins fixtures/classmethod.pyi] [out] -main:3: error: Revealed type is 'builtins.int' +main:3: note: Revealed type is 'builtins.int' == -main:3: error: Revealed type is 'Any' +main:3: note: Revealed type is 'Any' main:3: error: No overload variant of "foo" of "Wrapper" matches argument type "int" main:3: note: Possible overload variants: main:3: note: def foo(cls: Wrapper, x: int) -> int @@ -3814,9 +3814,9 @@ def f(x: a.A): reveal_type(f) [builtins fixtures/dict.pyi] [out] -b.py:4: error: Revealed type is 'def (x: builtins.str) -> Any' +b.py:4: note: Revealed type is 'def (x: builtins.str) -> Any' == -b.py:4: error: Revealed type is 'def (x: builtins.dict[Any, builtins.int]) -> Any' +b.py:4: note: Revealed type is 'def (x: builtins.dict[Any, builtins.int]) -> Any' [case testAliasFineChangedNumberOfTypeVars] import b @@ -7743,7 +7743,7 @@ A = NamedTuple('A', F) # type: ignore [builtins fixtures/list.pyi] [out] == -b.py:3: error: Revealed type is 'Tuple[, fallback=a.A]' +b.py:3: note: Revealed type is 'Tuple[, fallback=a.A]' [case testImportOnTopOfAlias1] from a import A @@ -8356,8 +8356,8 @@ B = func m.py:4: error: Invalid type "a.A" == m.py:4: error: Invalid type "a.A" -m.py:5: error: Revealed type is 'A?' -m.py:7: error: Revealed type is 'A?' +m.py:5: note: Revealed type is 'A?' +m.py:7: note: Revealed type is 'A?' [case testAliasForwardFunctionDirect] # flags: --ignore-missing-imports @@ -8400,12 +8400,12 @@ x: Literal[1] = 1 from typing_extensions import Literal x: Literal[1] = 2 [out] -main:2: error: Revealed type is 'builtins.int' +main:2: note: Revealed type is 'builtins.int' == -main:2: error: Revealed type is 'Literal[1]' +main:2: note: Revealed type is 'Literal[1]' == mod.py:2: error: Incompatible types in assignment (expression has type "Literal[2]", variable has type "Literal[1]") -main:2: error: Revealed type is 'Literal[1]' +main:2: note: Revealed type is 'Literal[1]' [case testLiteralFineGrainedFunctionConversion] from mod import foo @@ -8461,9 +8461,9 @@ def foo(x: int) -> str: ... def foo(x: Literal['bar']) -> int: ... def foo(x): pass [out] -main:2: error: Revealed type is 'builtins.str' +main:2: note: Revealed type is 'builtins.str' == -main:2: error: Revealed type is 'Literal['foo']' +main:2: note: Revealed type is 'Literal['foo']' [case testLiteralFineGrainedChainedDefinitions] from mod1 import foo @@ -8542,9 +8542,9 @@ bar = 3 from typing_extensions import Literal bar: Literal[3] = 3 [out] -main:2: error: Revealed type is 'builtins.int*' +main:2: note: Revealed type is 'builtins.int*' == -main:2: error: Revealed type is 'Literal[3]' +main:2: note: Revealed type is 'Literal[3]' [case testLiteralFineGrainedChainedViaFinal] from mod1 import foo @@ -8588,11 +8588,11 @@ def bar() -> Literal[u"foo"]: pass from typing_extensions import Literal def bar() -> Literal[b"foo"]: pass [out] -main:2: error: Revealed type is 'Literal['foo']' +main:2: note: Revealed type is 'Literal['foo']' == -main:2: error: Revealed type is 'Literal['foo']' +main:2: note: Revealed type is 'Literal['foo']' == -main:2: error: Revealed type is 'Literal[b'foo']' +main:2: note: Revealed type is 'Literal[b'foo']' [case testLiteralFineGrainedStringConversionPython2] # flags: --python-version 2.7 @@ -8629,15 +8629,15 @@ def bar(): # type: () -> Literal[u"foo"] pass [out] -main:3: error: Revealed type is 'Literal['foo']' +main:3: note: Revealed type is 'Literal['foo']' == -main:3: error: Revealed type is 'Literal['foo']' +main:3: note: Revealed type is 'Literal['foo']' == -main:3: error: Revealed type is 'Literal[u'foo']' +main:3: note: Revealed type is 'Literal[u'foo']' == -main:3: error: Revealed type is 'Literal['foo']' +main:3: note: Revealed type is 'Literal['foo']' == -main:3: error: Revealed type is 'Literal[u'foo']' +main:3: note: Revealed type is 'Literal[u'foo']' [case testReprocessModuleTopLevelWhileMethodDefinesAttr] import a diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 285f8e48714d..64f0d63eb656 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -500,5 +500,5 @@ def test() -> None: def bad(arg: P) -> T: pass [out] -_program.py:8: error: Revealed type is 'def [T] (arg: P?) -> T`-1' +_program.py:8: note: Revealed type is 'def [T] (arg: P?) -> T`-1' _program.py:12: error: Invalid type "_testForwardRefToBadAsyncShouldNotCrash.P" diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 53690433764b..972d3361b66b 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -282,10 +282,10 @@ reveal_type(open('x', 'rb')) mode = 'rb' reveal_type(open('x', mode)) [out] -_program.py:1: error: Revealed type is 'typing.TextIO' -_program.py:2: error: Revealed type is 'typing.TextIO' -_program.py:3: error: Revealed type is 'typing.BinaryIO' -_program.py:5: error: Revealed type is 'typing.IO[Any]' +_program.py:1: note: Revealed type is 'typing.TextIO' +_program.py:2: note: Revealed type is 'typing.TextIO' +_program.py:3: note: Revealed type is 'typing.BinaryIO' +_program.py:5: note: Revealed type is 'typing.IO[Any]' [case testOpenReturnTypeInferenceSpecialCases] reveal_type(open()) @@ -294,11 +294,11 @@ reveal_type(open(file='x', mode='rb')) mode = 'rb' reveal_type(open(mode=mode, file='r')) [out] -_testOpenReturnTypeInferenceSpecialCases.py:1: error: Revealed type is 'typing.TextIO' +_testOpenReturnTypeInferenceSpecialCases.py:1: note: Revealed type is 'typing.TextIO' _testOpenReturnTypeInferenceSpecialCases.py:1: error: Too few arguments for "open" -_testOpenReturnTypeInferenceSpecialCases.py:2: error: Revealed type is 'typing.BinaryIO' -_testOpenReturnTypeInferenceSpecialCases.py:3: error: Revealed type is 'typing.BinaryIO' -_testOpenReturnTypeInferenceSpecialCases.py:5: error: Revealed type is 'typing.IO[Any]' +_testOpenReturnTypeInferenceSpecialCases.py:2: note: Revealed type is 'typing.BinaryIO' +_testOpenReturnTypeInferenceSpecialCases.py:3: note: Revealed type is 'typing.BinaryIO' +_testOpenReturnTypeInferenceSpecialCases.py:5: note: Revealed type is 'typing.IO[Any]' [case testGenericPatterns] from typing import Pattern @@ -873,13 +873,13 @@ o6 = t.Deque[int]() reveal_type(o6) [out] -_testCollectionsAliases.py:5: error: Revealed type is 'collections.Counter[builtins.int]' +_testCollectionsAliases.py:5: note: Revealed type is 'collections.Counter[builtins.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*]' -_testCollectionsAliases.py:18: error: Revealed type is 'collections.ChainMap[builtins.int*, builtins.str*]' -_testCollectionsAliases.py:21: error: Revealed type is 'collections.deque[builtins.int*]' +_testCollectionsAliases.py:9: note: Revealed type is 'collections.ChainMap[builtins.int, builtins.str]' +_testCollectionsAliases.py:12: note: Revealed type is 'collections.deque[builtins.int]' +_testCollectionsAliases.py:15: note: Revealed type is 'collections.Counter[builtins.int*]' +_testCollectionsAliases.py:18: note: Revealed type is 'collections.ChainMap[builtins.int*, builtins.str*]' +_testCollectionsAliases.py:21: note: Revealed type is 'collections.deque[builtins.int*]' [case testChainMapUnimported] ChainMap[int, str]() @@ -1030,10 +1030,10 @@ reveal_type(g) with f('') as s: reveal_type(s) [out] -_program.py:13: error: Revealed type is 'def (x: builtins.int) -> contextlib.GeneratorContextManager[builtins.str*]' -_program.py:14: error: Revealed type is 'def (*x: builtins.str) -> contextlib.GeneratorContextManager[builtins.int*]' +_program.py:13: note: Revealed type is 'def (x: builtins.int) -> contextlib.GeneratorContextManager[builtins.str*]' +_program.py:14: note: Revealed type is 'def (*x: builtins.str) -> contextlib.GeneratorContextManager[builtins.int*]' _program.py:16: error: Argument 1 to "f" has incompatible type "str"; expected "int" -_program.py:17: error: Revealed type is 'builtins.str*' +_program.py:17: note: Revealed type is 'builtins.str*' [case testTypedDictGet] # Test that TypedDict get plugin works with typeshed stubs @@ -1049,14 +1049,14 @@ d.get() s = '' reveal_type(d.get(s)) [out] -_testTypedDictGet.py:7: error: Revealed type is 'builtins.int' -_testTypedDictGet.py:8: error: Revealed type is 'builtins.str' +_testTypedDictGet.py:7: note: Revealed type is 'builtins.int' +_testTypedDictGet.py:8: note: Revealed type is 'builtins.str' _testTypedDictGet.py:9: error: TypedDict "D" has no key 'z' _testTypedDictGet.py:10: error: All overload variants of "get" of "Mapping" require at least one argument _testTypedDictGet.py:10: note: Possible overload variants: _testTypedDictGet.py:10: note: def get(self, k: str) -> object _testTypedDictGet.py:10: note: def [_T] get(self, k: str, default: object) -> object -_testTypedDictGet.py:12: error: Revealed type is 'builtins.object*' +_testTypedDictGet.py:12: note: Revealed type is 'builtins.object*' [case testTypedDictMappingMethods] from mypy_extensions import TypedDict @@ -1081,18 +1081,18 @@ Cell2 = TypedDict('Cell2', {'value': int}, total=False) c2 = Cell2() reveal_type(c2.pop('value')) [out] -_testTypedDictMappingMethods.py:5: error: Revealed type is 'builtins.str*' -_testTypedDictMappingMethods.py:6: error: Revealed type is 'typing.Iterator[builtins.str*]' -_testTypedDictMappingMethods.py:7: error: Revealed type is 'builtins.int' -_testTypedDictMappingMethods.py:8: error: Revealed type is 'builtins.bool' -_testTypedDictMappingMethods.py:9: error: Revealed type is 'typing.AbstractSet[builtins.str*]' -_testTypedDictMappingMethods.py:10: error: Revealed type is 'typing.AbstractSet[Tuple[builtins.str*, builtins.object*]]' -_testTypedDictMappingMethods.py:11: error: Revealed type is 'typing.ValuesView[builtins.object*]' -_testTypedDictMappingMethods.py:12: error: Revealed type is 'TypedDict('_testTypedDictMappingMethods.Cell', {'value': builtins.int})' -_testTypedDictMappingMethods.py:13: error: Revealed type is 'builtins.int' +_testTypedDictMappingMethods.py:5: note: Revealed type is 'builtins.str*' +_testTypedDictMappingMethods.py:6: note: Revealed type is 'typing.Iterator[builtins.str*]' +_testTypedDictMappingMethods.py:7: note: Revealed type is 'builtins.int' +_testTypedDictMappingMethods.py:8: note: Revealed type is 'builtins.bool' +_testTypedDictMappingMethods.py:9: note: Revealed type is 'typing.AbstractSet[builtins.str*]' +_testTypedDictMappingMethods.py:10: note: Revealed type is 'typing.AbstractSet[Tuple[builtins.str*, builtins.object*]]' +_testTypedDictMappingMethods.py:11: note: Revealed type is 'typing.ValuesView[builtins.object*]' +_testTypedDictMappingMethods.py:12: note: Revealed type is 'TypedDict('_testTypedDictMappingMethods.Cell', {'value': builtins.int})' +_testTypedDictMappingMethods.py:13: note: Revealed type is 'builtins.int' _testTypedDictMappingMethods.py:15: error: Unexpected TypedDict key 'invalid' _testTypedDictMappingMethods.py:16: error: Key 'value' of TypedDict "Cell" cannot be deleted -_testTypedDictMappingMethods.py:21: error: Revealed type is 'builtins.int' +_testTypedDictMappingMethods.py:21: note: Revealed type is 'builtins.int' [case testCrashOnComplexCheckWithNamedTupleNext] from typing import NamedTuple @@ -1135,9 +1135,9 @@ async def main() -> None: reveal_type(a_y) reveal_type(asyncio.gather(*[asyncio.sleep(1), asyncio.sleep(1)])) [out] -_testAsyncioGatherPreciseType.py:9: error: Revealed type is 'builtins.str' -_testAsyncioGatherPreciseType.py:10: error: Revealed type is 'builtins.str' -_testAsyncioGatherPreciseType.py:11: error: Revealed type is 'asyncio.futures.Future[builtins.tuple[Any]]' +_testAsyncioGatherPreciseType.py:9: note: Revealed type is 'builtins.str' +_testAsyncioGatherPreciseType.py:10: note: Revealed type is 'builtins.str' +_testAsyncioGatherPreciseType.py:11: note: Revealed type is 'asyncio.futures.Future[builtins.tuple[Any]]' [case testMultipleInheritanceWorksWithTupleTypeGeneric] from typing import SupportsAbs, NamedTuple @@ -1168,12 +1168,12 @@ for a, b in x.items(): reveal_type(a) reveal_type(b) [out] -_testNoCrashOnGenericUnionUnpacking.py:6: error: Revealed type is 'builtins.str' -_testNoCrashOnGenericUnionUnpacking.py:7: error: Revealed type is 'builtins.str' -_testNoCrashOnGenericUnionUnpacking.py:10: error: Revealed type is 'Union[builtins.str, builtins.int]' -_testNoCrashOnGenericUnionUnpacking.py:11: error: Revealed type is 'Union[builtins.str, builtins.int]' -_testNoCrashOnGenericUnionUnpacking.py:15: error: Revealed type is 'Union[builtins.int*, builtins.str*]' -_testNoCrashOnGenericUnionUnpacking.py:16: error: Revealed type is 'Union[builtins.int*, builtins.str*]' +_testNoCrashOnGenericUnionUnpacking.py:6: note: Revealed type is 'builtins.str' +_testNoCrashOnGenericUnionUnpacking.py:7: note: Revealed type is 'builtins.str' +_testNoCrashOnGenericUnionUnpacking.py:10: note: Revealed type is 'Union[builtins.str, builtins.int]' +_testNoCrashOnGenericUnionUnpacking.py:11: note: Revealed type is 'Union[builtins.str, builtins.int]' +_testNoCrashOnGenericUnionUnpacking.py:15: note: Revealed type is 'Union[builtins.int*, builtins.str*]' +_testNoCrashOnGenericUnionUnpacking.py:16: note: Revealed type is 'Union[builtins.int*, builtins.str*]' [case testMetaclassOpAccess] from typing import Type @@ -1199,8 +1199,8 @@ other = 4 + get_c_type() + 5 reveal_type(res) reveal_type(other) [out] -_testMetaclassOpAccess.py:21: error: Revealed type is 'Type[_testMetaclassOpAccess.A]' -_testMetaclassOpAccess.py:22: error: Revealed type is 'Type[_testMetaclassOpAccess.C]' +_testMetaclassOpAccess.py:21: note: Revealed type is 'Type[_testMetaclassOpAccess.A]' +_testMetaclassOpAccess.py:22: note: Revealed type is 'Type[_testMetaclassOpAccess.C]' [case testMetaclassOpAccessUnion] from typing import Type, Union @@ -1220,7 +1220,7 @@ bar: Type[Union[A, B]] res = bar * 4 reveal_type(res) [out] -_testMetaclassOpAccessUnion.py:16: error: Revealed type is 'Union[builtins.str, builtins.int]' +_testMetaclassOpAccessUnion.py:16: note: Revealed type is 'Union[builtins.str, builtins.int]' [case testMetaclassOpAccessAny] from typing import Type @@ -1241,8 +1241,8 @@ class E(Enum): for e in E: reveal_type(e) [out] -_testEnumIterationAndPreciseElementType.py:5: error: Revealed type is '_testEnumIterationAndPreciseElementType.E*' -_testEnumIterationAndPreciseElementType.py:7: error: Revealed type is '_testEnumIterationAndPreciseElementType.E*' +_testEnumIterationAndPreciseElementType.py:5: note: Revealed type is '_testEnumIterationAndPreciseElementType.E*' +_testEnumIterationAndPreciseElementType.py:7: note: Revealed type is '_testEnumIterationAndPreciseElementType.E*' [case testEnumIterable] from enum import Enum @@ -1266,7 +1266,7 @@ f(N) g(N) reveal_type(list(N)) [out] -_testIntEnumIterable.py:11: error: Revealed type is 'builtins.list[_testIntEnumIterable.N*]' +_testIntEnumIterable.py:11: note: Revealed type is 'builtins.list[_testIntEnumIterable.N*]' [case testDerivedEnumIterable] from enum import Enum @@ -1326,7 +1326,7 @@ def print_custom_table() -> None: for row in simple_map(format_row, a, a, a, a, a, a, a, a): # 8 columns reveal_type(row) [out] -_testLoadsOfOverloads.py:24: error: Revealed type is 'builtins.str*' +_testLoadsOfOverloads.py:24: note: Revealed type is 'builtins.str*' [case testReduceWithAnyInstance] from typing import Iterable @@ -1358,7 +1358,7 @@ X = namedtuple('X', ['a', 'b']) x = X(a=1, b='s') [out] -_testNamedTupleNew.py:12: error: Revealed type is 'Tuple[builtins.int, fallback=_testNamedTupleNew.Child]' +_testNamedTupleNew.py:12: note: Revealed type is 'Tuple[builtins.int, fallback=_testNamedTupleNew.Child]' [case testNewAnalyzerBasicTypeshed_newsemanal] from typing import Dict, List, Tuple @@ -1366,4 +1366,4 @@ from typing import Dict, List, Tuple x: Dict[str, List[int]] reveal_type(x['test'][0]) [out] -_testNewAnalyzerBasicTypeshed_newsemanal.py:4: error: Revealed type is 'builtins.int*' +_testNewAnalyzerBasicTypeshed_newsemanal.py:4: note: Revealed type is 'builtins.int*'