Skip to content

Commit d06c5dd

Browse files
conformance: remove questionable generic syntax test (#2368)
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.
1 parent 835b70f commit d06c5dd

7 files changed

Lines changed: 52 additions & 61 deletions

File tree

‎conformance/results/mypy/generics_syntax_scoping.toml‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ output = """
66
generics_syntax_scoping.py:14: error: Name "S" is not defined [name-defined]
77
generics_syntax_scoping.py:18: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type]
88
generics_syntax_scoping.py:18: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
9-
generics_syntax_scoping.py:35: error: Cannot determine type of "T" [has-type]
10-
generics_syntax_scoping.py:35: error: Name "T" is used before definition [used-before-def]
11-
generics_syntax_scoping.py:44: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type]
12-
generics_syntax_scoping.py:44: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
13-
generics_syntax_scoping.py:62: error: Expression is of type "Any", not "str" [assert-type]
14-
generics_syntax_scoping.py:62: note: "assert_type" expects everything to be "Any" in unchecked functions
15-
generics_syntax_scoping.py:67: error: Expression is of type "Any", not "int" [assert-type]
16-
generics_syntax_scoping.py:67: note: "assert_type" expects everything to be "Any" in unchecked functions
17-
generics_syntax_scoping.py:92: error: "T" already defined as a type parameter [misc]
18-
generics_syntax_scoping.py:95: error: "T" already defined as a type parameter [misc]
19-
generics_syntax_scoping.py:98: error: "T" already defined as a type parameter [misc]
20-
generics_syntax_scoping.py:98: error: Variable "generics_syntax_scoping.ClassE.T" is not valid as a type [valid-type]
21-
generics_syntax_scoping.py:98: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
22-
generics_syntax_scoping.py:117: error: Expression is of type "Any", not "TypeVar" [assert-type]
23-
generics_syntax_scoping.py:117: note: "assert_type" expects everything to be "Any" in unchecked functions
24-
generics_syntax_scoping.py:122: error: Expression is of type "Any", not "complex" [assert-type]
25-
generics_syntax_scoping.py:122: note: "assert_type" expects everything to be "Any" in unchecked functions
26-
generics_syntax_scoping.py:125: error: Expression is of type "Any", not "complex" [assert-type]
27-
generics_syntax_scoping.py:125: note: "assert_type" expects everything to be "Any" in unchecked functions
9+
generics_syntax_scoping.py:26: error: Cannot determine type of "T" [has-type]
10+
generics_syntax_scoping.py:26: error: Name "T" is used before definition [used-before-def]
11+
generics_syntax_scoping.py:35: error: Variable "generics_syntax_scoping.T" is not valid as a type [valid-type]
12+
generics_syntax_scoping.py:35: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
13+
generics_syntax_scoping.py:53: error: Expression is of type "Any", not "str" [assert-type]
14+
generics_syntax_scoping.py:53: note: "assert_type" expects everything to be "Any" in unchecked functions
15+
generics_syntax_scoping.py:58: error: Expression is of type "Any", not "int" [assert-type]
16+
generics_syntax_scoping.py:58: note: "assert_type" expects everything to be "Any" in unchecked functions
17+
generics_syntax_scoping.py:83: error: "T" already defined as a type parameter [misc]
18+
generics_syntax_scoping.py:86: error: "T" already defined as a type parameter [misc]
19+
generics_syntax_scoping.py:89: error: "T" already defined as a type parameter [misc]
20+
generics_syntax_scoping.py:89: error: Variable "generics_syntax_scoping.ClassE.T" is not valid as a type [valid-type]
21+
generics_syntax_scoping.py:89: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
22+
generics_syntax_scoping.py:108: error: Expression is of type "Any", not "TypeVar" [assert-type]
23+
generics_syntax_scoping.py:108: note: "assert_type" expects everything to be "Any" in unchecked functions
24+
generics_syntax_scoping.py:113: error: Expression is of type "Any", not "complex" [assert-type]
25+
generics_syntax_scoping.py:113: note: "assert_type" expects everything to be "Any" in unchecked functions
26+
generics_syntax_scoping.py:116: error: Expression is of type "Any", not "complex" [assert-type]
27+
generics_syntax_scoping.py:116: note: "assert_type" expects everything to be "Any" in unchecked functions
2828
"""
2929
conformance_automated = "Fail"
3030
errors_diff = """
31-
Line 62: Unexpected errors ['generics_syntax_scoping.py:62: error: Expression is of type "Any", not "str" [assert-type]']
32-
Line 67: Unexpected errors ['generics_syntax_scoping.py:67: error: Expression is of type "Any", not "int" [assert-type]']
33-
Line 117: Unexpected errors ['generics_syntax_scoping.py:117: error: Expression is of type "Any", not "TypeVar" [assert-type]']
34-
Line 122: Unexpected errors ['generics_syntax_scoping.py:122: error: Expression is of type "Any", not "complex" [assert-type]']
35-
Line 125: Unexpected errors ['generics_syntax_scoping.py:125: error: Expression is of type "Any", not "complex" [assert-type]']
31+
Line 53: Unexpected errors ['generics_syntax_scoping.py:53: error: Expression is of type "Any", not "str" [assert-type]']
32+
Line 58: Unexpected errors ['generics_syntax_scoping.py:58: error: Expression is of type "Any", not "int" [assert-type]']
33+
Line 108: Unexpected errors ['generics_syntax_scoping.py:108: error: Expression is of type "Any", not "TypeVar" [assert-type]']
34+
Line 113: Unexpected errors ['generics_syntax_scoping.py:113: error: Expression is of type "Any", not "complex" [assert-type]']
35+
Line 116: Unexpected errors ['generics_syntax_scoping.py:116: error: Expression is of type "Any", not "complex" [assert-type]']
3636
"""

‎conformance/results/pycroscope/generics_syntax_scoping.toml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ errors_diff = """
44
output = """
55
./generics_syntax_scoping.py:14:19: TypeVar bound cannot be parameterized by type variables [invalid_annotation]
66
./generics_syntax_scoping.py:18:13: Type parameter bound cannot reference a later type parameter [invalid_type_parameter]
7-
./generics_syntax_scoping.py:35:6: Undefined name: T [undefined_name]
8-
./generics_syntax_scoping.py:44:12: Incompatible argument type for x: expected type[./generics_syntax_scoping.py.Foo[~T@./generics_syntax_scoping.py.decorator1.<locals>.decorator1]] but got types.GenericAlias (partial from <class 'Foo'>[Any[error]]) [incompatible_argument]
9-
./generics_syntax_scoping.py:44:16: Undefined name: T [undefined_name]
10-
./generics_syntax_scoping.py:92:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
11-
./generics_syntax_scoping.py:95:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
12-
./generics_syntax_scoping.py:98:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
7+
./generics_syntax_scoping.py:26:6: Undefined name: T [undefined_name]
8+
./generics_syntax_scoping.py:35:12: Incompatible argument type for x: expected type[./generics_syntax_scoping.py.Foo[~T@./generics_syntax_scoping.py.decorator1.<locals>.decorator1]] but got types.GenericAlias (partial from <class 'Foo'>[Any[error]]) [incompatible_argument]
9+
./generics_syntax_scoping.py:35:16: Undefined name: T [undefined_name]
10+
./generics_syntax_scoping.py:83:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
11+
./generics_syntax_scoping.py:86:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
12+
./generics_syntax_scoping.py:89:16: Type parameter 'T' is already in use by an outer scope [invalid_type_parameter]
1313
"""

‎conformance/results/pyrefly/generics_syntax_scoping.toml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ errors_diff = """
55
output = """
66
ERROR generics_syntax_scoping.py:14:20-31: Type variable bounds and constraints must be concrete [invalid-annotation]
77
ERROR generics_syntax_scoping.py:18:26-27: Expected a type form, got instance of `int` [not-a-type]
8-
ERROR generics_syntax_scoping.py:35:7-8: `T` is uninitialized [unbound-name]
9-
ERROR generics_syntax_scoping.py:44:17-18: Expected a type form, got instance of `int` [not-a-type]
10-
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]
11-
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]
12-
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]
8+
ERROR generics_syntax_scoping.py:26:7-8: `T` is uninitialized [unbound-name]
9+
ERROR generics_syntax_scoping.py:35:17-18: Expected a type form, got instance of `int` [not-a-type]
10+
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]
11+
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]
12+
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]
1313
"""

‎conformance/results/pyright/generics_syntax_scoping.toml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ conformant = "Pass"
22
output = """
33
generics_syntax_scoping.py:14:20 - error: TypeVar constraint type cannot be generic (reportGeneralTypeIssues)
44
generics_syntax_scoping.py:18:17 - error: TypeVar constraint type cannot be generic (reportGeneralTypeIssues)
5-
generics_syntax_scoping.py:35:7 - error: "T" is not defined (reportUndefinedVariable)
6-
generics_syntax_scoping.py:44:17 - error: "T" is not defined (reportUndefinedVariable)
7-
generics_syntax_scoping.py:92:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
8-
generics_syntax_scoping.py:95:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
9-
generics_syntax_scoping.py:98:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
10-
generics_syntax_scoping.py:98:29 - warning: TypeVar "T" appears only once in generic function signature
5+
generics_syntax_scoping.py:26:7 - error: "T" is not defined (reportUndefinedVariable)
6+
generics_syntax_scoping.py:35:17 - error: "T" is not defined (reportUndefinedVariable)
7+
generics_syntax_scoping.py:83:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
8+
generics_syntax_scoping.py:86:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
9+
generics_syntax_scoping.py:89:17 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues)
10+
generics_syntax_scoping.py:89:29 - warning: TypeVar "T" appears only once in generic function signature
1111
  Use "object" instead (reportInvalidTypeVarUse)
1212
"""
1313
conformance_automated = "Pass"

‎conformance/results/ty/generics_syntax_scoping.toml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ errors_diff = """
44
output = """
55
generics_syntax_scoping.py:14:20: error[invalid-type-variable-bound] TypeVar upper bound cannot be generic
66
generics_syntax_scoping.py:18:17: error[invalid-type-variable-bound] TypeVar upper bound cannot be generic
7-
generics_syntax_scoping.py:35:7: error[unresolved-reference] Name `T` used when not defined
8-
generics_syntax_scoping.py:44:17: error[unresolved-reference] Name `T` used when not defined
9-
generics_syntax_scoping.py:92:9: error[shadowed-type-variable] Generic function `method1` uses type variable `T` already bound by an enclosing scope
10-
generics_syntax_scoping.py:95:9: error[shadowed-type-variable] Generic function `method2` uses type variable `T` already bound by an enclosing scope
11-
generics_syntax_scoping.py:98:9: error[shadowed-type-variable] Generic function `method3` uses type variable `T` already bound by an enclosing scope
7+
generics_syntax_scoping.py:26:7: error[unresolved-reference] Name `T` used when not defined
8+
generics_syntax_scoping.py:35:17: error[unresolved-reference] Name `T` used when not defined
9+
generics_syntax_scoping.py:83:9: error[shadowed-type-variable] Generic function `method1` uses type variable `T` already bound by an enclosing scope
10+
generics_syntax_scoping.py:86:9: error[shadowed-type-variable] Generic function `method2` uses type variable `T` already bound by an enclosing scope
11+
generics_syntax_scoping.py:89:9: error[shadowed-type-variable] Generic function `method3` uses type variable `T` already bound by an enclosing scope
1212
"""

‎conformance/results/zuban/generics_syntax_scoping.toml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ generics_syntax_scoping.py:14: error: Variable "tests.generics_syntax_scoping.S"
66
generics_syntax_scoping.py:14: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
77
generics_syntax_scoping.py:18: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type]
88
generics_syntax_scoping.py:18: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
9+
generics_syntax_scoping.py:26: error: Name "T" is used before definition [used-before-def]
910
generics_syntax_scoping.py:35: error: Name "T" is used before definition [used-before-def]
10-
generics_syntax_scoping.py:44: error: Name "T" is used before definition [used-before-def]
11-
generics_syntax_scoping.py:44: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type]
12-
generics_syntax_scoping.py:44: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
13-
generics_syntax_scoping.py:92: error: "T" already defined as a type parameter [misc]
14-
generics_syntax_scoping.py:95: error: "T" already defined as a type parameter [misc]
15-
generics_syntax_scoping.py:98: error: "T" already defined as a type parameter [misc]
11+
generics_syntax_scoping.py:35: error: Variable "tests.generics_syntax_scoping.T" is not valid as a type [valid-type]
12+
generics_syntax_scoping.py:35: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
13+
generics_syntax_scoping.py:83: error: "T" already defined as a type parameter [misc]
14+
generics_syntax_scoping.py:86: error: "T" already defined as a type parameter [misc]
15+
generics_syntax_scoping.py:89: error: "T" already defined as a type parameter [misc]
1616
"""

‎conformance/tests/generics_syntax_scoping.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ class Foo[T]:
2323
...
2424

2525

26-
class BaseClassC[T]:
27-
def __init_subclass__(cls, param: type[Foo[T]]) -> None:
28-
...
29-
30-
31-
class ClassC[T](BaseClassC[T], param=Foo[T]): # OK
32-
...
33-
34-
3526
print(T) # E: Runtime error: 'T' is not defined
3627

3728

0 commit comments

Comments
 (0)