From 36a1637812cb93a3388f6bf11a6337a4055fae9f Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sun, 7 Jan 2018 21:07:38 +0200 Subject: [PATCH 1/3] annotate functions in tests --- test-data/unit/check-classes.test | 2 +- test-data/unit/check-inference.test | 8 ++++---- test-data/unit/check-modules.test | 2 +- test-data/unit/check-statements.test | 2 +- test-data/unit/fixtures/list.pyi | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index ba623eedc036..a58976b67e6d 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -122,7 +122,7 @@ A().f = None # E: Cannot assign to a method [case testReferToInvalidAttribute] class A: - def __init__(self): + def __init__(self) -> None: self.x = object() a = None # type: A a.y diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index a904cacd57ad..b921e9318275 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -1403,7 +1403,7 @@ b[{}] = 1 [case testInferDictInitializedToEmptyAndUpdatedFromMethod] map = {} -def add(): +def add() -> None: map[1] = 2 [builtins fixtures/dict.pyi] [out] @@ -1959,7 +1959,7 @@ class C: if bool(): f() - 1 + '' # E: Unsupported left operand type for + ("int") + 1 + '' # E: Unsupported operand types for + ("int" and "str") [builtins fixtures/list.pyi] [out] @@ -1976,7 +1976,7 @@ class C: if bool(): f() - 1 + '' # E: Unsupported left operand type for + ("int") + 1 + '' # E: Unsupported operand types for + ("int" and "str") [builtins fixtures/list.pyi] [out] @@ -1992,6 +1992,6 @@ class C: if bool(): f([]) - 1 + '' # E: Unsupported left operand type for + ("int") + 1 + '' # E: Unsupported operand types for + ("int" and "str") [builtins fixtures/list.pyi] [out] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index f3104c6f2715..5d9d55875dfa 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -1312,7 +1312,7 @@ class A: def f(self) -> str: return 'foo' class B(A): def f(self) -> str: return self.x - def initialize(self): self.x = 'bar' + def initialize(self) -> None: self.x = 'bar' [out] diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index cd38fc02f3fb..4c25e02ad6fa 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -353,7 +353,7 @@ a @= 1 # E: Argument 1 to "__imatmul__" of "A" has incompatible type "int"; exp [case testInplaceSetitem] class A(object): - def __init__(self): + def __init__(self) -> None: self.a = 0 def __iadd__(self, a): diff --git a/test-data/unit/fixtures/list.pyi b/test-data/unit/fixtures/list.pyi index b97be43fda1a..c022304ca578 100644 --- a/test-data/unit/fixtures/list.pyi +++ b/test-data/unit/fixtures/list.pyi @@ -26,7 +26,8 @@ class list(Generic[T]): class tuple(Generic[T]): pass class function: pass -class int: pass +class int: + def __add__(self, other: 'int') -> 'int': pass class float: pass class str: pass class bool(int): pass From 8c5be18030b52aeb0072d352cd8c2ae166f1199b Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Tue, 9 Jan 2018 01:02:54 +0200 Subject: [PATCH 2/3] fix and duplicate tests as required --- test-data/unit/check-classes.test | 15 ++++++++++----- test-data/unit/check-inference.test | 13 +++++++++---- test-data/unit/check-modules.test | 7 ++++++- test-data/unit/fixtures/list.pyi | 3 +-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index a58976b67e6d..ea55b40e916d 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -125,13 +125,18 @@ class A: def __init__(self) -> None: self.x = object() a = None # type: A -a.y -a.y = object() +a.y # E: "A" has no attribute "y" +a.y = object() # E: "A" has no attribute "y" +a.x +a.x = object() + +[case testInferAttributeUnannotatedInit] +class A: + def __init__(self): + self.x = object() + a.x a.x = object() -[out] -main:6: error: "A" has no attribute "y" -main:7: error: "A" has no attribute "y" [case testArgumentTypeInference] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index b921e9318275..c9bb0fdb05c9 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -1406,7 +1406,12 @@ map = {} def add() -> None: map[1] = 2 [builtins fixtures/dict.pyi] -[out] + +[case testInferDictInitializedToEmptyAndUpdatedFromMethodUnannotated] +map = {} +def add(): + map[1] = 2 +[builtins fixtures/dict.pyi] [case testSpecialCaseEmptyListInitialization] def f(blocks: Any): # E: Name 'Any' is not defined @@ -1959,7 +1964,7 @@ class C: if bool(): f() - 1 + '' # E: Unsupported operand types for + ("int" and "str") + 1() # E: "int" not callable [builtins fixtures/list.pyi] [out] @@ -1976,7 +1981,7 @@ class C: if bool(): f() - 1 + '' # E: Unsupported operand types for + ("int" and "str") + 1() # E: "int" not callable [builtins fixtures/list.pyi] [out] @@ -1992,6 +1997,6 @@ class C: if bool(): f([]) - 1 + '' # E: Unsupported operand types for + ("int" and "str") + 1() # E: "int" not callable [builtins fixtures/list.pyi] [out] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 5d9d55875dfa..d8492dad0436 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -1313,8 +1313,13 @@ class A: class B(A): def f(self) -> str: return self.x def initialize(self) -> None: self.x = 'bar' -[out] +[case testDeferredClassContextUnannotated] +class A: + def f(self) -> str: return 'foo' +class B(A): + def f(self) -> str: return self.x + def initialize(self): self.x = 'bar' -- Scripts and __main__ diff --git a/test-data/unit/fixtures/list.pyi b/test-data/unit/fixtures/list.pyi index c022304ca578..b97be43fda1a 100644 --- a/test-data/unit/fixtures/list.pyi +++ b/test-data/unit/fixtures/list.pyi @@ -26,8 +26,7 @@ class list(Generic[T]): class tuple(Generic[T]): pass class function: pass -class int: - def __add__(self, other: 'int') -> 'int': pass +class int: pass class float: pass class str: pass class bool(int): pass From 815a3f5762fd028fcd09b977fb1bfbe6ff1ace18 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Tue, 9 Jan 2018 21:44:13 +0200 Subject: [PATCH 3/3] inplace addition for list; fix InvalidAttribute --- test-data/unit/check-classes.test | 7 +++++-- test-data/unit/check-statements.test | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index ea55b40e916d..e543c22a15e2 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -124,17 +124,20 @@ A().f = None # E: Cannot assign to a method class A: def __init__(self) -> None: self.x = object() -a = None # type: A +a: A a.y # E: "A" has no attribute "y" a.y = object() # E: "A" has no attribute "y" a.x a.x = object() -[case testInferAttributeUnannotatedInit] +[case testReferToInvalidAttributeUnannotatedInit] class A: def __init__(self): self.x = object() +a: A +a.y # E: "A" has no attribute "y" +a.y = object() # E: "A" has no attribute "y" a.x a.x = object() diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 4c25e02ad6fa..41d31e687793 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -354,11 +354,11 @@ a @= 1 # E: Argument 1 to "__imatmul__" of "A" has incompatible type "int"; exp [case testInplaceSetitem] class A(object): def __init__(self) -> None: - self.a = 0 + self.a = [1] def __iadd__(self, a): # type: (int) -> A - self.a += 1 + self.a += [2] return self a = A()