Skip to content

Commit 5373b08

Browse files
yangdanny97facebook-github-bot
authored andcommitted
update conformance test sources
Summary: I made a fix to the conformance tests, so I'm pulling in the latest changes and regenerating the outputs. python/typing#1959 This also pulled in the new overload conformance tests. Reviewed By: ndmitchell Differential Revision: D72514863 fbshipit-source-id: 5a06f65d3738a2152ae864122c9c9b5691570b16
1 parent 623b445 commit 5373b08

25 files changed

+1558
-238
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Used as part of the test for the typing.Final special form.
3+
"""
4+
5+
from typing import Final
6+
7+
TEN: Final[int] = 10
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Used as part of the test for the typing.Final special form.
3+
"""
4+
5+
from typing import Final
6+
7+
PI: Final = 3.14

conformance/third_party/aliases_type_statement.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ def func2(x: object):
4848
type BadTypeAlias12 = list or set # E
4949
type BadTypeAlias13 = f"{'int'}" # E
5050

51-
if 1 < 2:
52-
type BadTypeAlias14 = int # E: redeclared
53-
else:
54-
type BadTypeAlias14 = int
51+
type BadTypeAlias14 = int # E[TA14]: redeclared
52+
type BadTypeAlias14 = int # E[TA14]: redeclared
5553

5654

5755
def func3():
@@ -87,5 +85,5 @@ def func3():
8785

8886
type RecursiveTypeAlias5[T] = T | list[RecursiveTypeAlias5[T]]
8987

90-
type RecursiveTypeAlias6 = RecursiveTypeAlias7 # E: circular definition
91-
type RecursiveTypeAlias7 = RecursiveTypeAlias6
88+
type RecursiveTypeAlias6 = RecursiveTypeAlias7 # E[RTA6]: circular definition
89+
type RecursiveTypeAlias7 = RecursiveTypeAlias6 # E[RTA6]: circular definition

conformance/third_party/annotations_coroutines.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ async def func1(ignored: int, /) -> str:
1616
return "spam"
1717

1818

19-
assert_type(func1, Callable[[int], Coroutine[Any, Any, str]])
19+
# Don't use assert_type here because some type checkers infer
20+
# the narrower type types.CoroutineType rather than typing.Coroutine
21+
# in this case.
22+
v1: Callable[[int], Coroutine[Any, Any, str]] = func1
2023

2124

2225
async def func2() -> None:

conformance/third_party/annotations_generators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ async def generator29() -> AsyncIterator[int]:
179179
raise NotImplementedError
180180

181181

182-
assert_type(generator29, Callable[[], Coroutine[Any, Any, AsyncIterator[int]]])
182+
# Don't use assert_type here because some type checkers infer
183+
# the narrower type types.CoroutineType rather than typing.Coroutine
184+
# in this case.
185+
v1: Callable[[], Coroutine[Any, Any, AsyncIterator[int]]] = generator29
183186

184187

185188
async def generator30() -> AsyncIterator[int]:

conformance/third_party/callables_kwargs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ def func5(v1: int, **kwargs: Unpack[TD2]) -> None: # E: parameter v1 overlaps w
121121

122122
def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict, not a TypeVar bound to TypedDict.
123123
...
124+
125+
# > The situation where the destination callable contains **kwargs: Unpack[TypedDict] and
126+
# > the source callable doesn’t contain **kwargs should be disallowed. This is because,
127+
# > we cannot be sure that additional keyword arguments are not being passed in when an instance of a subclass
128+
# > had been assigned to a variable with a base class type and then unpacked in the destination callable invocation
129+
130+
def func7(*, v1: int, v3: str, v2: str = "") -> None:
131+
...
132+
133+
134+
v7: TDProtocol6 = func7 # E: source does not have kwargs

conformance/third_party/classes_override.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def method2(self, x: str) -> str:
4949
def method2(self, x: int | str) -> int | str: # OK
5050
return 0
5151

52-
@override
53-
def method3(self) -> int: # E: no matching signature in ancestor
52+
@override # E[method3]
53+
def method3(self) -> int: # E[method3]: no matching signature in ancestor
5454
return 1
5555

5656
@overload # E[method4]
@@ -61,7 +61,7 @@ def method4(self, x: int) -> int:
6161
def method4(self, x: str) -> str:
6262
...
6363

64-
@override
64+
@override # E[method4]
6565
def method4(self, x: int | str) -> int | str: # E[method4]: no matching signature in ancestor
6666
return 0
6767

@@ -75,18 +75,18 @@ def method5(self): # OK
7575
# > only normal methods but also @property, @staticmethod, and @classmethod.
7676

7777
@staticmethod
78-
@override
79-
def static_method1() -> int: # E: no matching signature in ancestor
78+
@override # E[static_method1]
79+
def static_method1() -> int: # E[static_method1]: no matching signature in ancestor
8080
return 1
8181

8282
@classmethod
83-
@override
84-
def class_method1(cls) -> int: # E: no matching signature in ancestor
83+
@override # E[class_method1]
84+
def class_method1(cls) -> int: # E[class_method1]: no matching signature in ancestor
8585
return 1
8686

8787
@property
88-
@override
89-
def property1(self) -> int: # E: no matching signature in ancestor
88+
@override # E[property1]
89+
def property1(self) -> int: # E[property1]: no matching signature in ancestor
9090
return 1
9191

9292

0 commit comments

Comments
 (0)