From e458e17fda8235fc6313ddcfe8bab90c8624150e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 14 Oct 2026 15:21:35 -0700 Subject: [PATCH] conformance: remove questionable generic syntax test We noticed this test from a ty change that (correctly) disallows passing `Foo[T]` where `type[Foo[T]]` is expected: `Foo[T]` is a `GenericAlias`, not a type. But when I looked at the test, I noticed it doesn't really make sense to use a generic here at all. `__init_subclass__` is evaluated at the class level and can't possibly be generic. Probably TypeVars should be disallowed here for the same reason they're disallowed in ClassVars. But adding that to the spec or type checkers seems more trouble than it's worth; for now let's just remove the dubious test. --- .../results/mypy/generics_syntax_scoping.toml | 48 +++++++++---------- .../pycroscope/generics_syntax_scoping.toml | 12 ++--- .../pyrefly/generics_syntax_scoping.toml | 10 ++-- .../pyright/generics_syntax_scoping.toml | 12 ++--- .../results/ty/generics_syntax_scoping.toml | 10 ++-- .../zuban/generics_syntax_scoping.toml | 12 ++--- conformance/tests/generics_syntax_scoping.py | 9 ---- 7 files changed, 52 insertions(+), 61 deletions(-) diff --git a/conformance/results/mypy/generics_syntax_scoping.toml b/conformance/results/mypy/generics_syntax_scoping.toml index 34cc33a00..433b9c67b 100644 --- a/conformance/results/mypy/generics_syntax_scoping.toml +++ b/conformance/results/mypy/generics_syntax_scoping.toml @@ -6,31 +6,31 @@ output = """ generics_syntax_scoping.py:14: error: Name "S" is not defined [name-defined] generics_syntax_scoping.py:18: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type] generics_syntax_scoping.py:18: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases -generics_syntax_scoping.py:35: error: Cannot determine type of "T" [has-type] -generics_syntax_scoping.py:35: error: Name "T" is used before definition [used-before-def] -generics_syntax_scoping.py:44: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type] -generics_syntax_scoping.py:44: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases -generics_syntax_scoping.py:62: error: Expression is of type "Any", not "str" [assert-type] -generics_syntax_scoping.py:62: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:67: error: Expression is of type "Any", not "int" [assert-type] -generics_syntax_scoping.py:67: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:92: error: "T" already defined as a type parameter [misc] -generics_syntax_scoping.py:95: error: "T" already defined as a type parameter [misc] -generics_syntax_scoping.py:98: error: "T" already defined as a type parameter [misc] -generics_syntax_scoping.py:98: error: Variable "generics_syntax_scoping.ClassE.T" is not valid as a type [valid-type] -generics_syntax_scoping.py:98: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases -generics_syntax_scoping.py:117: error: Expression is of type "Any", not "TypeVar" [assert-type] -generics_syntax_scoping.py:117: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:122: error: Expression is of type "Any", not "complex" [assert-type] -generics_syntax_scoping.py:122: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:125: error: Expression is of type "Any", not "complex" [assert-type] -generics_syntax_scoping.py:125: note: "assert_type" expects everything to be "Any" in unchecked functions +generics_syntax_scoping.py:26: error: Cannot determine type of "T" [has-type] +generics_syntax_scoping.py:26: error: Name "T" is used before definition [used-before-def] +generics_syntax_scoping.py:35: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type] +generics_syntax_scoping.py:35: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases +generics_syntax_scoping.py:53: error: Expression is of type "Any", not "str" [assert-type] +generics_syntax_scoping.py:53: note: "assert_type" expects everything to be "Any" in unchecked functions +generics_syntax_scoping.py:58: error: Expression is of type "Any", not "int" [assert-type] +generics_syntax_scoping.py:58: note: "assert_type" expects everything to be "Any" in unchecked functions +generics_syntax_scoping.py:83: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:86: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:89: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:89: error: Variable "generics_syntax_scoping.ClassE.T" is not valid as a type [valid-type] +generics_syntax_scoping.py:89: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases +generics_syntax_scoping.py:108: error: Expression is of type "Any", not "TypeVar" [assert-type] +generics_syntax_scoping.py:108: note: "assert_type" expects everything to be "Any" in unchecked functions +generics_syntax_scoping.py:113: error: Expression is of type "Any", not "complex" [assert-type] +generics_syntax_scoping.py:113: note: "assert_type" expects everything to be "Any" in unchecked functions +generics_syntax_scoping.py:116: error: Expression is of type "Any", not "complex" [assert-type] +generics_syntax_scoping.py:116: note: "assert_type" expects everything to be "Any" in unchecked functions """ conformance_automated = "Fail" errors_diff = """ -Line 62: Unexpected errors ['generics_syntax_scoping.py:62: error: Expression is of type "Any", not "str" [assert-type]'] -Line 67: Unexpected errors ['generics_syntax_scoping.py:67: error: Expression is of type "Any", not "int" [assert-type]'] -Line 117: Unexpected errors ['generics_syntax_scoping.py:117: error: Expression is of type "Any", not "TypeVar" [assert-type]'] -Line 122: Unexpected errors ['generics_syntax_scoping.py:122: error: Expression is of type "Any", not "complex" [assert-type]'] -Line 125: Unexpected errors ['generics_syntax_scoping.py:125: error: Expression is of type "Any", not "complex" [assert-type]'] +Line 53: Unexpected errors ['generics_syntax_scoping.py:53: error: Expression is of type "Any", not "str" [assert-type]'] +Line 58: Unexpected errors ['generics_syntax_scoping.py:58: error: Expression is of type "Any", not "int" [assert-type]'] +Line 108: Unexpected errors ['generics_syntax_scoping.py:108: error: Expression is of type "Any", not "TypeVar" [assert-type]'] +Line 113: Unexpected errors ['generics_syntax_scoping.py:113: error: Expression is of type "Any", not "complex" [assert-type]'] +Line 116: Unexpected errors ['generics_syntax_scoping.py:116: error: Expression is of type "Any", not "complex" [assert-type]'] """ diff --git a/conformance/results/pycroscope/generics_syntax_scoping.toml b/conformance/results/pycroscope/generics_syntax_scoping.toml index 6aa30d4d5..4f2903c6f 100644 --- a/conformance/results/pycroscope/generics_syntax_scoping.toml +++ b/conformance/results/pycroscope/generics_syntax_scoping.toml @@ -4,10 +4,10 @@ errors_diff = """ output = """ ./generics_syntax_scoping.py:14:19: TypeVar bound cannot be parameterized by type variables [invalid_annotation] ./generics_syntax_scoping.py:18:13: Type parameter bound cannot reference a later type parameter [invalid_type_parameter] -./generics_syntax_scoping.py:35:6: Undefined name: T [undefined_name] -./generics_syntax_scoping.py:44:12: Incompatible argument type for x: expected type[./generics_syntax_scoping.py.Foo[~T@./generics_syntax_scoping.py.decorator1..decorator1]] but got types.GenericAlias (partial from [Any[error]]) [incompatible_argument] -./generics_syntax_scoping.py:44:16: Undefined name: T [undefined_name] -./generics_syntax_scoping.py:92:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] -./generics_syntax_scoping.py:95:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] -./generics_syntax_scoping.py:98:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] +./generics_syntax_scoping.py:26:6: Undefined name: T [undefined_name] +./generics_syntax_scoping.py:35:12: Incompatible argument type for x: expected type[./generics_syntax_scoping.py.Foo[~T@./generics_syntax_scoping.py.decorator1..decorator1]] but got types.GenericAlias (partial from [Any[error]]) [incompatible_argument] +./generics_syntax_scoping.py:35:16: Undefined name: T [undefined_name] +./generics_syntax_scoping.py:83:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] +./generics_syntax_scoping.py:86:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] +./generics_syntax_scoping.py:89:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter] """ diff --git a/conformance/results/pyrefly/generics_syntax_scoping.toml b/conformance/results/pyrefly/generics_syntax_scoping.toml index 6d7c35a63..2034cb3ed 100644 --- a/conformance/results/pyrefly/generics_syntax_scoping.toml +++ b/conformance/results/pyrefly/generics_syntax_scoping.toml @@ -5,9 +5,9 @@ errors_diff = """ output = """ ERROR generics_syntax_scoping.py:14:20-31: Type variable bounds and constraints must be concrete [invalid-annotation] ERROR generics_syntax_scoping.py:18:26-27: Expected a type form, got instance of `int` [not-a-type] -ERROR generics_syntax_scoping.py:35:7-8: `T` is uninitialized [unbound-name] -ERROR generics_syntax_scoping.py:44:17-18: Expected a type form, got instance of `int` [not-a-type] -ERROR generics_syntax_scoping.py:92:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] -ERROR generics_syntax_scoping.py:95:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] -ERROR generics_syntax_scoping.py:98:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] +ERROR generics_syntax_scoping.py:26:7-8: `T` is uninitialized [unbound-name] +ERROR generics_syntax_scoping.py:35:17-18: Expected a type form, got instance of `int` [not-a-type] +ERROR generics_syntax_scoping.py:83:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] +ERROR generics_syntax_scoping.py:86:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] +ERROR generics_syntax_scoping.py:89:17-18: Type parameter `T` shadows a type parameter of the same name from an enclosing scope [invalid-type-var] """ diff --git a/conformance/results/pyright/generics_syntax_scoping.toml b/conformance/results/pyright/generics_syntax_scoping.toml index 4a8f43c6a..5cc46a887 100644 --- a/conformance/results/pyright/generics_syntax_scoping.toml +++ b/conformance/results/pyright/generics_syntax_scoping.toml @@ -2,12 +2,12 @@ conformant = "Pass" output = """ generics_syntax_scoping.py:14:20 - error: TypeVar constraint type cannot be generic (reportGeneralTypeIssues) generics_syntax_scoping.py:18:17 - error: TypeVar constraint type cannot be generic (reportGeneralTypeIssues) -generics_syntax_scoping.py:35:7 - error: "T" is not defined (reportUndefinedVariable) -generics_syntax_scoping.py:44:17 - error: "T" is not defined (reportUndefinedVariable) -generics_syntax_scoping.py:92:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) -generics_syntax_scoping.py:95:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) -generics_syntax_scoping.py:98:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) -generics_syntax_scoping.py:98:29 - warning: TypeVar "T" appears only once in generic function signature +generics_syntax_scoping.py:26:7 - error: "T" is not defined (reportUndefinedVariable) +generics_syntax_scoping.py:35:17 - error: "T" is not defined (reportUndefinedVariable) +generics_syntax_scoping.py:83:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) +generics_syntax_scoping.py:86:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) +generics_syntax_scoping.py:89:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) +generics_syntax_scoping.py:89:29 - warning: TypeVar "T" appears only once in generic function signature   Use "object" instead (reportInvalidTypeVarUse) """ conformance_automated = "Pass" diff --git a/conformance/results/ty/generics_syntax_scoping.toml b/conformance/results/ty/generics_syntax_scoping.toml index 839a9eda0..b40a2f622 100644 --- a/conformance/results/ty/generics_syntax_scoping.toml +++ b/conformance/results/ty/generics_syntax_scoping.toml @@ -4,9 +4,9 @@ errors_diff = """ output = """ generics_syntax_scoping.py:14:20: error[invalid-type-variable-bound] TypeVar upper bound cannot be generic generics_syntax_scoping.py:18:17: error[invalid-type-variable-bound] TypeVar upper bound cannot be generic -generics_syntax_scoping.py:35:7: error[unresolved-reference] Name `T` used when not defined -generics_syntax_scoping.py:44:17: error[unresolved-reference] Name `T` used when not defined -generics_syntax_scoping.py:92:9: error[shadowed-type-variable] Generic function `method1` uses type variable `T` already bound by an enclosing scope -generics_syntax_scoping.py:95:9: error[shadowed-type-variable] Generic function `method2` uses type variable `T` already bound by an enclosing scope -generics_syntax_scoping.py:98:9: error[shadowed-type-variable] Generic function `method3` uses type variable `T` already bound by an enclosing scope +generics_syntax_scoping.py:26:7: error[unresolved-reference] Name `T` used when not defined +generics_syntax_scoping.py:35:17: error[unresolved-reference] Name `T` used when not defined +generics_syntax_scoping.py:83:9: error[shadowed-type-variable] Generic function `method1` uses type variable `T` already bound by an enclosing scope +generics_syntax_scoping.py:86:9: error[shadowed-type-variable] Generic function `method2` uses type variable `T` already bound by an enclosing scope +generics_syntax_scoping.py:89:9: error[shadowed-type-variable] Generic function `method3` uses type variable `T` already bound by an enclosing scope """ diff --git a/conformance/results/zuban/generics_syntax_scoping.toml b/conformance/results/zuban/generics_syntax_scoping.toml index a0444e813..c72eeb1b0 100644 --- a/conformance/results/zuban/generics_syntax_scoping.toml +++ b/conformance/results/zuban/generics_syntax_scoping.toml @@ -6,11 +6,11 @@ generics_syntax_scoping.py:14: error: Variable "tests.generics_syntax_scoping.S" generics_syntax_scoping.py:14: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases generics_syntax_scoping.py:18: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type] generics_syntax_scoping.py:18: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases +generics_syntax_scoping.py:26: error: Name "T" is used before definition [used-before-def] generics_syntax_scoping.py:35: error: Name "T" is used before definition [used-before-def] -generics_syntax_scoping.py:44: error: Name "T" is used before definition [used-before-def] -generics_syntax_scoping.py:44: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type] -generics_syntax_scoping.py:44: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases -generics_syntax_scoping.py:92: error: "T" already defined as a type parameter [misc] -generics_syntax_scoping.py:95: error: "T" already defined as a type parameter [misc] -generics_syntax_scoping.py:98: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:35: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type] +generics_syntax_scoping.py:35: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases +generics_syntax_scoping.py:83: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:86: error: "T" already defined as a type parameter [misc] +generics_syntax_scoping.py:89: error: "T" already defined as a type parameter [misc] """ diff --git a/conformance/tests/generics_syntax_scoping.py b/conformance/tests/generics_syntax_scoping.py index 768d8fda7..38c277db1 100644 --- a/conformance/tests/generics_syntax_scoping.py +++ b/conformance/tests/generics_syntax_scoping.py @@ -23,15 +23,6 @@ class Foo[T]: ... -class BaseClassC[T]: - def __init_subclass__(cls, param: type[Foo[T]]) -> None: - ... - - -class ClassC[T](BaseClassC[T], param=Foo[T]): # OK - ... - - print(T) # E: Runtime error: 'T' is not defined