Skip to content

Commit 12e6943

Browse files
committed
conformance: Fix questionable assert_type() with known class
The previous test asserted that type checkers should consider a direct reference to the class to be equivalent to a type[] usage. But it is entirely reasonable for type checkers to recognize the direct class reference as an instance of a more precise singleton type, as ty does. (Pycroscope also kind of does this but I'm still working on adjusting its behavior.) I replaced this test with assertions about the assignability of the direct class reference to a few type[] variants.
1 parent ea6a8cb commit 12e6943

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

conformance/results/mypy/generics_defaults_specialization.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Does not correctly resolve defaults when classes are used directly.
44
"""
55
output = """
66
generics_defaults_specialization.py:30: error: Bad number of arguments for type alias, expected between 0 and 1, given 2 [type-arg]
7-
generics_defaults_specialization.py:45: error: Expression is of type "type[Bar[DefaultStrT]]", not "type[Bar[str]]" [assert-type]
8-
generics_defaults_specialization.py:55: error: The type "type[Foo]" is not generic and not indexable [misc]
7+
generics_defaults_specialization.py:56: error: The type "type[Foo]" is not generic and not indexable [misc]
98
"""
109
conformance_automated = "Fail"
1110
errors_diff = """
12-
Line 45: Unexpected errors ['generics_defaults_specialization.py:45: error: Expression is of type "type[Bar[DefaultStrT]]", not "type[Bar[str]]" [assert-type]']
11+
Line 46: Expected 1 errors
1312
"""

conformance/results/pyrefly/generics_defaults_specialization.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ errors_diff = """
44
"""
55
output = """
66
ERROR generics_defaults_specialization.py:30:1-19: Expected 1 type argument for `MyAlias`, got 2 [bad-specialization]
7-
ERROR generics_defaults_specialization.py:55:1-9: Expected 0 type arguments for `Foo`, got 1 [bad-specialization]
7+
ERROR generics_defaults_specialization.py:46:22-25: `type[Bar]` is not assignable to `type[Bar[int]]` [bad-assignment]
8+
ERROR generics_defaults_specialization.py:56:1-9: Expected 0 type arguments for `Foo`, got 1 [bad-specialization]
89
"""
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Allows incorrect assignment to type[].
4+
"""
25
output = """
36
generics_defaults_specialization.py:30:15 - error: Too many type arguments provided for "MyAlias[DefaultStrT@MyAlias]"; expected 1 but received 2 (reportInvalidTypeForm)
4-
generics_defaults_specialization.py:55:5 - error: Expected no type arguments for class "Foo" (reportInvalidTypeArguments)
7+
generics_defaults_specialization.py:56:5 - error: Expected no type arguments for class "Foo" (reportInvalidTypeArguments)
58
"""
6-
conformance_automated = "Pass"
9+
conformance_automated = "Fail"
710
errors_diff = """
11+
Line 46: Expected 1 errors
812
"""

conformance/results/ty/generics_defaults_specialization.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ notes = """
44
Does not reject subscription of an already-specialized generic class.
55
"""
66
errors_diff = """
7-
Line 55: Expected 1 errors
7+
Line 56: Expected 1 errors
88
"""
99
output = """
1010
generics_defaults_specialization.py:30:15: error[invalid-type-arguments] Too many type arguments: expected between 0 and 1, got 2
11+
generics_defaults_specialization.py:46:22: error[invalid-assignment] Object of type `<class 'Bar'>` is not assignable to `type[Bar[int]]`
1112
"""

conformance/results/zuban/generics_defaults_specialization.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ errors_diff = """
33
"""
44
output = """
55
generics_defaults_specialization.py:30: error: Bad number of arguments for type alias, expected between 0 and 1, given 2 [misc]
6-
generics_defaults_specialization.py:55: error: "Foo" expects no type arguments, but 1 given [type-arg]
6+
generics_defaults_specialization.py:46: error: Incompatible types in assignment (expression has type "type[Bar]", variable has type "type[Bar[int]]") [assignment]
7+
generics_defaults_specialization.py:56: error: "Foo" expects no type arguments, but 1 given [type-arg]
78
"""

conformance/tests/generics_defaults_specialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class SubclassMe(Generic[T1, DefaultStrT]):
4242
class Bar(SubclassMe[int, DefaultStrT]): ...
4343

4444

45-
assert_type(Bar, type[Bar[str]])
45+
x1: type[Bar[str]] = Bar # ok
46+
x2: type[Bar[int]] = Bar # E
4647
assert_type(Bar(), Bar[str])
4748
assert_type(Bar[bool](), Bar[bool])
4849

0 commit comments

Comments
 (0)