Skip to content
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
27 changes: 11 additions & 16 deletions conformance/results/mypy/aliases_type_statement.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
conformant = "Partial"
notes = """
Does not reject type alias defined in function scope.
"""
conformant = "Pass"
output = """
aliases_type_statement.py:17: error: "TypeAliasType" has no attribute "bit_count" [attr-defined]
aliases_type_statement.py:19: error: "TypeAliasType" not callable [operator]
Expand All @@ -24,18 +21,16 @@ aliases_type_statement.py:46: error: Invalid type: try using Literal[True] inste
aliases_type_statement.py:47: error: Invalid type: try using Literal[1] instead? [valid-type]
aliases_type_statement.py:48: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_type_statement.py:49: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_type_statement.py:52: error: Name "BadTypeAlias14" already defined on line 51 [no-redef]
aliases_type_statement.py:62: error: All type parameters should be declared ("V" not declared) [valid-type]
aliases_type_statement.py:67: error: All type parameters should be declared ("T1" not declared) [valid-type]
aliases_type_statement.py:77: error: Type argument "str" of "RecursiveTypeAlias2" must be a subtype of "int" [type-var]
aliases_type_statement.py:79: error: Type argument "int" of "RecursiveTypeAlias2" must be a subtype of "str" [type-var]
aliases_type_statement.py:82: error: Cannot resolve name "RecursiveTypeAlias3" (possible cyclic definition) [misc]
aliases_type_statement.py:84: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:88: error: Cannot resolve name "RecursiveTypeAlias6" (possible cyclic definition) [misc]
aliases_type_statement.py:88: error: Cannot resolve name "RecursiveTypeAlias7" (possible cyclic definition) [misc]
aliases_type_statement.py:89: error: Cannot resolve name "RecursiveTypeAlias7" (possible cyclic definition) [misc]
aliases_type_statement.py:53: error: All type parameters should be declared ("V" not declared) [valid-type]
aliases_type_statement.py:58: error: All type parameters should be declared ("T1" not declared) [valid-type]
aliases_type_statement.py:68: error: Type argument "str" of "RecursiveTypeAlias2" must be a subtype of "int" [type-var]
aliases_type_statement.py:70: error: Type argument "int" of "RecursiveTypeAlias2" must be a subtype of "str" [type-var]
aliases_type_statement.py:73: error: Cannot resolve name "RecursiveTypeAlias3" (possible cyclic definition) [misc]
aliases_type_statement.py:75: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:79: error: Cannot resolve name "RecursiveTypeAlias6" (possible cyclic definition) [misc]
aliases_type_statement.py:79: error: Cannot resolve name "RecursiveTypeAlias7" (possible cyclic definition) [misc]
aliases_type_statement.py:80: error: Cannot resolve name "RecursiveTypeAlias7" (possible cyclic definition) [misc]
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
Line 56: Expected 1 errors
"""
18 changes: 8 additions & 10 deletions conformance/results/pyrefly/aliases_type_statement.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ ERROR aliases_type_statement.py:46:23-27: Bool literal cannot be used in annotat
ERROR aliases_type_statement.py:47:23-24: Number literal cannot be used in annotations [invalid-annotation]
ERROR aliases_type_statement.py:48:23-34: Boolean operation cannot be used in annotations [invalid-annotation]
ERROR aliases_type_statement.py:49:23-33: F-string cannot be used in annotations [invalid-annotation]
ERROR aliases_type_statement.py:52:6-20: Cannot redefine existing type alias `BadTypeAlias14` [redefinition]
ERROR aliases_type_statement.py:56:5-30: `type` statement is not allowed in this context [invalid-syntax]
ERROR aliases_type_statement.py:62:15-25: Type parameters used in `TA1` but not declared [invalid-type-var]
ERROR aliases_type_statement.py:67:12-20: Type parameters used in `TA2` but not declared [invalid-type-var]
ERROR aliases_type_statement.py:77:7-41: `str` is not assignable to upper bound `int` of type variable `S` [bad-specialization]
ERROR aliases_type_statement.py:79:7-41: `int` is not assignable to upper bound `str` of type variable `T` [bad-specialization]
ERROR aliases_type_statement.py:82:28-47: Found cyclic self-reference in `RecursiveTypeAlias3` [invalid-type-alias]
ERROR aliases_type_statement.py:84:31-59: Found cyclic self-reference in `RecursiveTypeAlias4` [invalid-type-alias]
ERROR aliases_type_statement.py:88:28-47: Found cyclic self-reference in `RecursiveTypeAlias6` [invalid-type-alias]
ERROR aliases_type_statement.py:89:28-47: Found cyclic self-reference in `RecursiveTypeAlias7` [invalid-type-alias]
ERROR aliases_type_statement.py:53:15-25: Type parameters used in `TA1` but not declared [invalid-type-var]
ERROR aliases_type_statement.py:58:12-20: Type parameters used in `TA2` but not declared [invalid-type-var]
ERROR aliases_type_statement.py:68:7-41: `str` is not assignable to upper bound `int` of type variable `S` [bad-specialization]
ERROR aliases_type_statement.py:70:7-41: `int` is not assignable to upper bound `str` of type variable `T` [bad-specialization]
ERROR aliases_type_statement.py:73:28-47: Found cyclic self-reference in `RecursiveTypeAlias3` [invalid-type-alias]
ERROR aliases_type_statement.py:75:31-59: Found cyclic self-reference in `RecursiveTypeAlias4` [invalid-type-alias]
ERROR aliases_type_statement.py:79:28-47: Found cyclic self-reference in `RecursiveTypeAlias6` [invalid-type-alias]
ERROR aliases_type_statement.py:80:28-47: Found cyclic self-reference in `RecursiveTypeAlias7` [invalid-type-alias]
"""
16 changes: 7 additions & 9 deletions conformance/results/pyright/aliases_type_statement.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ aliases_type_statement.py:46:23 - error: Expected class but received "Literal[Tr
aliases_type_statement.py:47:23 - error: Expected class but received "Literal[1]" (reportGeneralTypeIssues)
aliases_type_statement.py:48:23 - error: Binary operator not allowed in type expression (reportInvalidTypeForm)
aliases_type_statement.py:49:23 - error: Type expressions cannot use format string literals (f-strings) (reportGeneralTypeIssues)
aliases_type_statement.py:51:6 - error: Type alias declaration "BadTypeAlias14" is obscured by a declaration of the same name (reportRedeclaration)
aliases_type_statement.py:56:10 - error: A type statement can be used only within a module or class scope (reportGeneralTypeIssues)
aliases_type_statement.py:62:23 - error: Type parameter "V" is not included in the type parameter list for "TA1" (reportGeneralTypeIssues)
aliases_type_statement.py:67:17 - error: Type parameter "T1" is not included in the type parameter list for "TA2" (reportGeneralTypeIssues)
aliases_type_statement.py:77:7 - error: Could not specialize type "RecursiveTypeAlias2[S@RecursiveTypeAlias2, T@RecursiveTypeAlias2, P@RecursiveTypeAlias2]"
aliases_type_statement.py:53:23 - error: Type parameter "V" is not included in the type parameter list for "TA1" (reportGeneralTypeIssues)
aliases_type_statement.py:58:17 - error: Type parameter "T1" is not included in the type parameter list for "TA2" (reportGeneralTypeIssues)
aliases_type_statement.py:68:7 - error: Could not specialize type "RecursiveTypeAlias2[S@RecursiveTypeAlias2, T@RecursiveTypeAlias2, P@RecursiveTypeAlias2]"
  Type "str" is not assignable to type "int"
    "str" is not assignable to "int" (reportInvalidTypeForm)
aliases_type_statement.py:79:7 - error: Could not specialize type "RecursiveTypeAlias2[S@RecursiveTypeAlias2, T@RecursiveTypeAlias2, P@RecursiveTypeAlias2]"
aliases_type_statement.py:70:7 - error: Could not specialize type "RecursiveTypeAlias2[S@RecursiveTypeAlias2, T@RecursiveTypeAlias2, P@RecursiveTypeAlias2]"
  Type "int" is not assignable to type "str"
    "int" is not assignable to "str" (reportInvalidTypeForm)
aliases_type_statement.py:82:28 - error: Type alias "RecursiveTypeAlias3" cannot use itself in its definition (reportGeneralTypeIssues)
aliases_type_statement.py:84:31 - error: Type alias "RecursiveTypeAlias4" cannot use itself in its definition (reportGeneralTypeIssues)
aliases_type_statement.py:88:28 - error: Type alias "RecursiveTypeAlias6" cannot use itself in its definition (reportGeneralTypeIssues)
aliases_type_statement.py:73:28 - error: Type alias "RecursiveTypeAlias3" cannot use itself in its definition (reportGeneralTypeIssues)
aliases_type_statement.py:75:31 - error: Type alias "RecursiveTypeAlias4" cannot use itself in its definition (reportGeneralTypeIssues)
aliases_type_statement.py:79:28 - error: Type alias "RecursiveTypeAlias6" cannot use itself in its definition (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
4 changes: 2 additions & 2 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,11 @@ <h3>Python Type System Conformance Test Results</h3>
<th class="column col2 not-conformant">Unsupported</th>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_type_statement</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject type alias defined in function scope.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject use of the `type` statement inside functions.</p><p>Does not reject circular definitions of type aliases.</p><p>Does not reject redeclarations of type aliases.</p><p>Does not support `type` statements generic over `TypeVarTuple`s.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject circular definitions of type aliases.</p><p>Does not support `type` statements generic over `TypeVarTuple`s.</p></span></div></th>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_typealiastype</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly rejects some recursive type aliases using TypeAliasType.</p><p>Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.</p></span></div></th>
Expand Down
20 changes: 8 additions & 12 deletions conformance/results/ty/aliases_type_statement.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
conformance_automated = "Fail"
conformant = "Partial"
notes = """
Does not reject use of the `type` statement inside functions.
Does not reject circular definitions of type aliases.
Does not reject redeclarations of type aliases.
Does not support `type` statements generic over `TypeVarTuple`s.
"""
errors_diff = """
Line 56: Expected 1 errors
Line 84: Expected 1 errors
Lines 51, 52: Expected error (tag 'TA14')
Line 75: Expected 1 errors
Line 10: Unexpected errors ['aliases_type_statement.py:10:52: error[invalid-type-arguments] Too many type arguments: expected 2, got 3', 'aliases_type_statement.py:10:52: error[invalid-type-form] `...` is not allowed in this context in a type alias value']
"""
output = """
Expand All @@ -33,11 +29,11 @@ aliases_type_statement.py:46:23: error[invalid-type-form] Boolean literals are n
aliases_type_statement.py:47:23: error[invalid-type-form] Int literals are not allowed in this context in a type alias value: Did you mean `typing.Literal[1]`?
aliases_type_statement.py:48:23: error[invalid-type-form] Boolean operations are not allowed in type alias values
aliases_type_statement.py:49:23: error[invalid-type-form] F-strings are not allowed in type alias values
aliases_type_statement.py:62:23: error[unbound-type-variable] Type variable `V` is not bound to any outer generic context
aliases_type_statement.py:67:17: error[unbound-type-variable] Type variable `T1` is not bound to any outer generic context
aliases_type_statement.py:77:27: error[invalid-type-arguments] Type `str` is not assignable to upper bound `int` of type variable `S@RecursiveTypeAlias2`
aliases_type_statement.py:79:32: error[invalid-type-arguments] Type `int` is not assignable to upper bound `str` of type variable `T@RecursiveTypeAlias2`
aliases_type_statement.py:82:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias3`
aliases_type_statement.py:88:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias6`
aliases_type_statement.py:89:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias7`
aliases_type_statement.py:53:23: error[unbound-type-variable] Type variable `V` is not bound to any outer generic context
aliases_type_statement.py:58:17: error[unbound-type-variable] Type variable `T1` is not bound to any outer generic context
aliases_type_statement.py:68:27: error[invalid-type-arguments] Type `str` is not assignable to upper bound `int` of type variable `S@RecursiveTypeAlias2`
aliases_type_statement.py:70:32: error[invalid-type-arguments] Type `int` is not assignable to upper bound `str` of type variable `T@RecursiveTypeAlias2`
aliases_type_statement.py:73:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias3`
aliases_type_statement.py:79:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias6`
aliases_type_statement.py:80:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias7`
"""
16 changes: 7 additions & 9 deletions conformance/results/zuban/aliases_type_statement.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ aliases_type_statement.py:46: error: Invalid type alias: expression is not a val
aliases_type_statement.py:47: error: Invalid type: try using Literal[1] instead? [valid-type]
aliases_type_statement.py:48: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_type_statement.py:49: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_type_statement.py:52: error: Name "BadTypeAlias14" already defined on line 51 [no-redef]
aliases_type_statement.py:56: error: Type alias not allowed in function [misc]
aliases_type_statement.py:62: error: All type parameters should be declared ("V" not declared) [misc]
aliases_type_statement.py:67: error: All type parameters should be declared ("T1" not declared) [misc]
aliases_type_statement.py:77: error: Type argument "str" of "RecursiveTypeAlias2" must be a subtype of "int" [type-var]
aliases_type_statement.py:79: error: Type argument "int" of "RecursiveTypeAlias2" must be a subtype of "str" [type-var]
aliases_type_statement.py:82: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:84: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:88: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:53: error: All type parameters should be declared ("V" not declared) [misc]
aliases_type_statement.py:58: error: All type parameters should be declared ("T1" not declared) [misc]
aliases_type_statement.py:68: error: Type argument "str" of "RecursiveTypeAlias2" must be a subtype of "int" [type-var]
aliases_type_statement.py:70: error: Type argument "int" of "RecursiveTypeAlias2" must be a subtype of "str" [type-var]
aliases_type_statement.py:73: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:75: error: Invalid recursive alias: a union item of itself [misc]
aliases_type_statement.py:79: error: Invalid recursive alias: a union item of itself [misc]
"""
9 changes: 0 additions & 9 deletions conformance/tests/aliases_type_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ def func2(x: object):
type BadTypeAlias12 = list or set # E
type BadTypeAlias13 = f"{'int'}" # E

type BadTypeAlias14 = int # E[TA14]: redeclared
type BadTypeAlias14 = int # E[TA14]: redeclared


def func3():
type BadTypeAlias15 = int # E: alias not allowed in function
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is allowed, should we not retain these and mark them as OK?

Copy link
Copy Markdown
Member Author

@carljm carljm Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a more controversial change, since it would render every other type checker non-compliant. It would require adding language to the spec requiring this support.

The intent of this PR is not to require that type checkers support these cases, but to leave it up to individual type checkers (since the spec has nothing to say about it) pending a possible future effort to add clarifying language one way or another in the spec.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Makes sense. I don't disagree that these should be allowed, but it seems like it's decreasing "conformity", so just wondering if resolving this either way should be tracked in an issue.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, though there's an infinite universe of things not specified in the typing spec or tested in the conformance suite, and we should prioritize standardizing the things that most impact users; I don't think this is very high on that list.




V = TypeVar("V")

type TA1[K] = dict[K, V] # E: combines old and new TypeVars
Expand Down