Skip to content

Commit 3de8ac3

Browse files
rchen152facebook-github-bot
authored andcommitted
Import latest copy of conformance tests
Summary: I noticed that Danny submitted a couple PRs to make the conformance tests more flexible on what lines they expect certain errors on. This diff pulls in those changes, which give us a nice conformance boost. We do have a new conformance failure due to python/typing#2015. Reviewed By: yangdanny97 Differential Revision: D78778303 fbshipit-source-id: 256563b1f8e983263d2425708861d91dc00a4330
1 parent e804d01 commit 3de8ac3

17 files changed

Lines changed: 306 additions & 252 deletions

conformance/third_party/aliases_newtype.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
assert_type(UserId(5) + 1, int)
1616

17+
# > NewType('Derived', Base) returns a dummy function
18+
_: type = UserId # E: functions are not instances of `type`
19+
1720
# > Both isinstance and issubclass, as well as subclassing will fail for
1821
# > NewType('Derived', Base) since function objects don’t support these
1922
# > operations.

conformance/third_party/aliases_type_statement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ def func3():
8585

8686
type RecursiveTypeAlias5[T] = T | list[RecursiveTypeAlias5[T]]
8787

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

conformance/third_party/aliases_typealiastype.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
GoodAlias1 = TypeAliasType("GoodAlias1", int)
1717
GoodAlias2 = TypeAliasType("GoodAlias2", list[T], type_params=(T,))
1818
GoodAlias3 = TypeAliasType("GoodAlias3", list[T] | list[S], type_params=(S, T))
19-
GoodAlias4 = TypeAliasType("GoodAlias4", T | list[GoodAlias4[T]], type_params=(T,))
19+
GoodAlias4 = TypeAliasType("GoodAlias4", T | "list[GoodAlias4[T]]", type_params=(T,))
2020
GoodAlias5 = TypeAliasType(
2121
"GoodAlias5",
22-
Callable[P, TStr] | list[S] | list[GoodAlias5[S, TStr, P]] | tuple[*Ts],
22+
Callable[P, TStr] | list[S] | list["GoodAlias5[S, TStr, P]"] | tuple[*Ts],
2323
type_params=(S, TStr, P, Ts),
2424
)
2525

@@ -43,9 +43,9 @@ class ClassA(Generic[T]):
4343
BadAlias1 = TypeAliasType("BadAlias1", list[S], type_params=(T,)) # E: S not in scope
4444
BadAlias2 = TypeAliasType("BadAlias2", list[S]) # E: S not in scope
4545
BadAlias3 = TypeAliasType("BadAlias3", int, type_params=my_tuple) # E: not literal tuple
46-
BadAlias4 = TypeAliasType("BadAlias4", BadAlias4) # E: circular dependency
47-
BadAlias5 = TypeAliasType("BadAlias5", T | BadAlias5[str], type_params=(T,)) # E: circular dependency
48-
BadAlias6 = TypeAliasType("BadAlias6", BadAlias7) # E: circular dependency
46+
BadAlias4 = TypeAliasType("BadAlias4", "BadAlias4") # E: circular dependency
47+
BadAlias5 = TypeAliasType("BadAlias5", T | "BadAlias5[str]", type_params=(T,)) # E: circular dependency
48+
BadAlias6 = TypeAliasType("BadAlias6", "BadAlias7") # E: circular dependency
4949
BadAlias7 = TypeAliasType("BadAlias7", BadAlias6) # E?: circular dependency
5050

5151
# The following are invalid type expressions for a type alias.
@@ -62,3 +62,5 @@ class ClassA(Generic[T]):
6262
BadAlias18 = TypeAliasType("BadAlias18", 1) # E
6363
BadAlias19 = TypeAliasType("BadAlias19", list or set) # E
6464
BadAlias20 = TypeAliasType("BadAlias20", f"{'int'}") # E
65+
66+
BadAlias21 = TypeAliasType("BadAlias21", list[BadAlias21]) # E

conformance/third_party/classes_classvar.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ class ClassA(Generic[T, P]):
5757
good1: CV[int] = 1
5858
good2: ClassVar[list[str]] = []
5959
good3: ClassVar[Any] = 1
60+
# > If an assigned value is available, the type should be inferred as some type
61+
# > to which this value is assignable.
62+
# Here, type checkers could infer good4 as `float` or `Any`, for example.
6063
good4: ClassVar = 3.1
61-
good5: Annotated[ClassVar[list[int]], ""] = []
64+
# > If the `ClassVar` qualifier is used without any assigned value, the type
65+
# > should be inferred as `Any`:
66+
good5: ClassVar #E? Type checkers may error on uninitialized ClassVar
67+
good6: Annotated[ClassVar[list[int]], ""] = []
6268

6369
def method1(self, a: ClassVar[int]): # E: ClassVar not allowed here
6470
x: ClassVar[str] = "" # E: ClassVar not allowed here
@@ -75,7 +81,7 @@ def method2(self) -> ClassVar[int]: # E: ClassVar not allowed here
7581
assert_type(ClassA.good1, int)
7682
assert_type(ClassA.good2, list[str])
7783
assert_type(ClassA.good3, Any)
78-
assert_type(ClassA.good4, float)
84+
assert_type(ClassA.good5, Any)
7985

8086

8187
class BasicStarship:

0 commit comments

Comments
 (0)