Skip to content

conformance: aliases_typealiastype: quote recursive aliases, and add … #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions conformance/results/mypy/aliases_typealiastype.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Incorrectly rejects some recursive type aliases using TypeAliasType.
Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.
"""
output = """
aliases_typealiastype.py:19: error: Cannot resolve name "GoodAlias4" (possible cyclic definition) [misc]
aliases_typealiastype.py:20: error: Cannot resolve name "GoodAlias5" (possible cyclic definition) [misc]
aliases_typealiastype.py:22: error: Cannot resolve name "GoodAlias5" (possible cyclic definition) [misc]
aliases_typealiastype.py:27: error: Type variable "T" is not included in type_params [valid-type]
Expand All @@ -17,7 +16,6 @@ aliases_typealiastype.py:46: error: Cannot resolve name "BadAlias4" (possible cy
aliases_typealiastype.py:47: error: Invalid recursive alias: a union item of itself [misc]
aliases_typealiastype.py:48: error: Cannot resolve name "BadAlias6" (possible cyclic definition) [misc]
aliases_typealiastype.py:48: error: Cannot resolve name "BadAlias7" (possible cyclic definition) [misc]
aliases_typealiastype.py:48: error: Name "BadAlias7" is used before definition [used-before-def]
aliases_typealiastype.py:49: error: Cannot resolve name "BadAlias7" (possible cyclic definition) [misc]
aliases_typealiastype.py:52: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_typealiastype.py:53: error: Bracketed expression "[...]" is not valid as a type [valid-type]
Expand All @@ -35,10 +33,10 @@ aliases_typealiastype.py:62: error: Invalid type: try using Literal[1] instead?
aliases_typealiastype.py:63: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_typealiastype.py:63: error: Function "list" could always be true in boolean context [truthy-function]
aliases_typealiastype.py:64: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_typealiastype.py:66: error: Cannot resolve name "BadAlias21" (possible cyclic definition) [misc]
"""
conformance_automated = "Fail"
errors_diff = """
Line 19: Unexpected errors ['aliases_typealiastype.py:19: error: Cannot resolve name "GoodAlias4" (possible cyclic definition) [misc]']
Line 20: Unexpected errors ['aliases_typealiastype.py:20: error: Cannot resolve name "GoodAlias5" (possible cyclic definition) [misc]']
Line 22: Unexpected errors ['aliases_typealiastype.py:22: error: Cannot resolve name "GoodAlias5" (possible cyclic definition) [misc]']
Line 27: Unexpected errors ['aliases_typealiastype.py:27: error: Type variable "T" is not included in type_params [valid-type]']
Expand Down
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.15.0"
test_duration = 1.8
test_duration = 2.0
8 changes: 6 additions & 2 deletions conformance/results/pyright/aliases_typealiastype.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
conformant = "Pass"
conformant = "Partial"
notes = """
incorrectly allows undefined self reference
"""
output = """
aliases_typealiastype.py:32:18 - error: Cannot access attribute "other_attrib" for class "TypeAliasType"
  Attribute "other_attrib" is unknown (reportAttributeAccessIssue)
Expand Down Expand Up @@ -29,6 +32,7 @@ aliases_typealiastype.py:62:42 - error: Expected class but received "Literal[1]"
aliases_typealiastype.py:63:42 - error: Binary operator not allowed in type expression (reportInvalidTypeForm)
aliases_typealiastype.py:64:42 - error: Type expressions cannot use format string literals (f-strings) (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 66: Expected 1 errors
"""
9 changes: 6 additions & 3 deletions conformance/results/pyright/generics_type_erasure.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
conformant = "Pass"
conformant = "Partial"
notes = """
no error for `type(n1).label`
"""
output = """
generics_type_erasure.py:38:16 - error: Argument of type "Literal['']" cannot be assigned to parameter "label" of type "int | None" in function "__init__"
  Type "Literal['']" is not assignable to type "int | None"
Expand All @@ -12,8 +15,8 @@ generics_type_erasure.py:42:11 - error: Access to generic instance variable thro
generics_type_erasure.py:43:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:44:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:45:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:46:10 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 46: Expected 1 errors
"""
4 changes: 2 additions & 2 deletions conformance/results/pyright/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyright 1.1.399"
test_duration = 1.1
version = "pyright 1.1.400"
test_duration = 0.9
462 changes: 21 additions & 441 deletions conformance/results/results.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion conformance/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def update_type_checker_info(
def main():
# Some tests cover features that are available only in the
# latest version of Python (3.12), so we need this version.
assert sys.version_info >= (3, 12)
# assert sys.version_info >= (3, 12)

options = parse_options(sys.argv[1:])

Expand Down
12 changes: 7 additions & 5 deletions conformance/tests/aliases_typealiastype.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
GoodAlias1 = TypeAliasType("GoodAlias1", int)
GoodAlias2 = TypeAliasType("GoodAlias2", list[T], type_params=(T,))
GoodAlias3 = TypeAliasType("GoodAlias3", list[T] | list[S], type_params=(S, T))
GoodAlias4 = TypeAliasType("GoodAlias4", T | list[GoodAlias4[T]], type_params=(T,))
GoodAlias4 = TypeAliasType("GoodAlias4", T | "list[GoodAlias4[T]]", type_params=(T,))
GoodAlias5 = TypeAliasType(
"GoodAlias5",
Callable[P, TStr] | list[S] | list[GoodAlias5[S, TStr, P]] | tuple[*Ts],
Callable[P, TStr] | list[S] | list["GoodAlias5[S, TStr, P]"] | tuple[*Ts],
type_params=(S, TStr, P, Ts),
)

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

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

BadAlias21 = TypeAliasType("BadAlias21", list[BadAlias21]) # E