From 74f73e5b5d314424d516297a24de590f28d12d62 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 1 Jun 2017 12:12:30 +0100 Subject: [PATCH 1/2] Clean up test fixtures --- test-data/unit/check-classes.test | 3 ++- test-data/unit/check-functions.test | 2 ++ test-data/unit/check-unions.test | 6 +++--- test-data/unit/lib-stub/builtins.pyi | 4 +--- test-data/unit/lib-stub/types.pyi | 8 ++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index e5abaccef89e..f2b83290cb60 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -1665,7 +1665,7 @@ main:4: error: Invalid signature "def (__main__.B, __main__.A) -> __main__.B" main:6: error: Invalid signature "def (__main__.C, builtins.str, builtins.str) -> __main__.C" [case testSetAttr] -from typing import Union +from typing import Union, Any class A: def __setattr__(self, name: str, value: Any) -> None: ... @@ -1729,6 +1729,7 @@ c = C() c.check = 13 [case testGetAttrAndSetattr] +from typing import Any class A: def __setattr__(self, name: str, value: Any) -> None: ... def __getattr__(self, name: str) -> Any: ... diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 343b4b79cf9f..fc049053f855 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -88,6 +88,7 @@ def r(x) -> None: ... r = l # E: Incompatible types in assignment (expression has type Callable[[Any, Any], None], variable has type Callable[[Any], None]) [case testSubtypingFunctionsImplicitNames] +from typing import Any def f(a, b): pass def g(c: Any, d: Any) -> Any: pass @@ -1825,6 +1826,7 @@ class A(Generic[t]): [case testRedefineFunction] +from typing import Any def f(x) -> Any: pass def g(x, y): pass def h(x): pass diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index 37a170e7367e..6ab2d0fed017 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -335,13 +335,13 @@ t_a = None # type: Type[Any] 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: Any) -> builtins.type' +reveal_type(u(type, type)) # E: 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: Any) -> builtins.type]' -reveal_type(u(1, type)) # E: Revealed type is 'Union[def (x: Any) -> builtins.type, 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]]' diff --git a/test-data/unit/lib-stub/builtins.pyi b/test-data/unit/lib-stub/builtins.pyi index 5010235a53ab..457bea0e9020 100644 --- a/test-data/unit/lib-stub/builtins.pyi +++ b/test-data/unit/lib-stub/builtins.pyi @@ -1,10 +1,8 @@ -Any = 0 - class object: def __init__(self) -> None: pass class type: - def __init__(self, x: Any) -> None: pass + def __init__(self, x: object) -> None: pass # These are provided here for convenience. class int: diff --git a/test-data/unit/lib-stub/types.pyi b/test-data/unit/lib-stub/types.pyi index b118000e688c..12a942493402 100644 --- a/test-data/unit/lib-stub/types.pyi +++ b/test-data/unit/lib-stub/types.pyi @@ -1,8 +1,8 @@ -from typing import TypeVar, Optional, List, Any, Generic, Sequence -T = TypeVar('T') +from typing import TypeVar -def coroutine(func: T) -> T: - return func +_T = TypeVar('_T') + +def coroutine(func: _T) -> _T: pass class bool: ... From e2e517bfeb2899c2d3ba20d6183b227616007fcf Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 1 Jun 2017 12:21:58 +0100 Subject: [PATCH 2/2] Fix test cases --- test-data/unit/semanal-classvar.test | 2 +- test-data/unit/semanal-types.test | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test-data/unit/semanal-classvar.test b/test-data/unit/semanal-classvar.test index 677e1bd8cadc..d2e474cd278f 100644 --- a/test-data/unit/semanal-classvar.test +++ b/test-data/unit/semanal-classvar.test @@ -95,7 +95,7 @@ def f(x: ClassVar, y: ClassVar) -> ClassVar: pass main:2: error: ClassVar can only be used for assignments in class body [case testClassVarInCallableArgs] -from typing import Callable, ClassVar +from typing import Callable, ClassVar, Any f = None # type: Callable[[int, ClassVar], Any] [out] main:2: error: Invalid type: ClassVar nested inside other type diff --git a/test-data/unit/semanal-types.test b/test-data/unit/semanal-types.test index 4c3033191dfc..c1ec57f205de 100644 --- a/test-data/unit/semanal-types.test +++ b/test-data/unit/semanal-types.test @@ -720,7 +720,7 @@ MypyFile:1( def ())) [case testOverloadedFunction] -from typing import overload +from typing import overload, Any @overload def f(a: object) -> int: a @overload @@ -730,7 +730,7 @@ def f(a: Any) -> Any: return a [out] MypyFile:1( - ImportFrom:1(typing, [overload]) + ImportFrom:1(typing, [overload, Any]) OverloadedFuncDef:2( FuncDef:7( f