From 12e6943142c2ddfef010bbaddcc9871b3f0d5fb1 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Mar 2026 21:40:44 -0700 Subject: [PATCH 1/2] 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. --- .../results/mypy/generics_defaults_specialization.toml | 5 ++--- .../pyrefly/generics_defaults_specialization.toml | 3 ++- .../pyright/generics_defaults_specialization.toml | 10 +++++++--- .../results/ty/generics_defaults_specialization.toml | 3 ++- .../zuban/generics_defaults_specialization.toml | 3 ++- conformance/tests/generics_defaults_specialization.py | 3 ++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/conformance/results/mypy/generics_defaults_specialization.toml b/conformance/results/mypy/generics_defaults_specialization.toml index a40e0dc91..1aab9fb8d 100644 --- a/conformance/results/mypy/generics_defaults_specialization.toml +++ b/conformance/results/mypy/generics_defaults_specialization.toml @@ -4,10 +4,9 @@ Does not correctly resolve defaults when classes are used directly. """ output = """ generics_defaults_specialization.py:30: error: Bad number of arguments for type alias, expected between 0 and 1, given 2 [type-arg] -generics_defaults_specialization.py:45: error: Expression is of type "type[Bar[DefaultStrT]]", not "type[Bar[str]]" [assert-type] -generics_defaults_specialization.py:55: error: The type "type[Foo]" is not generic and not indexable [misc] +generics_defaults_specialization.py:56: error: The type "type[Foo]" is not generic and not indexable [misc] """ conformance_automated = "Fail" errors_diff = """ -Line 45: Unexpected errors ['generics_defaults_specialization.py:45: error: Expression is of type "type[Bar[DefaultStrT]]", not "type[Bar[str]]" [assert-type]'] +Line 46: Expected 1 errors """ diff --git a/conformance/results/pyrefly/generics_defaults_specialization.toml b/conformance/results/pyrefly/generics_defaults_specialization.toml index 009497adb..4b087764e 100644 --- a/conformance/results/pyrefly/generics_defaults_specialization.toml +++ b/conformance/results/pyrefly/generics_defaults_specialization.toml @@ -4,5 +4,6 @@ errors_diff = """ """ output = """ ERROR generics_defaults_specialization.py:30:1-19: Expected 1 type argument for `MyAlias`, got 2 [bad-specialization] -ERROR generics_defaults_specialization.py:55:1-9: Expected 0 type arguments for `Foo`, got 1 [bad-specialization] +ERROR generics_defaults_specialization.py:46:22-25: `type[Bar]` is not assignable to `type[Bar[int]]` [bad-assignment] +ERROR generics_defaults_specialization.py:56:1-9: Expected 0 type arguments for `Foo`, got 1 [bad-specialization] """ diff --git a/conformance/results/pyright/generics_defaults_specialization.toml b/conformance/results/pyright/generics_defaults_specialization.toml index c7ba75826..28c6cdced 100644 --- a/conformance/results/pyright/generics_defaults_specialization.toml +++ b/conformance/results/pyright/generics_defaults_specialization.toml @@ -1,8 +1,12 @@ -conformant = "Pass" +conformant = "Partial" +notes = """ +Allows incorrect assignment to type[]. +""" output = """ generics_defaults_specialization.py:30:15 - error: Too many type arguments provided for "MyAlias[DefaultStrT@MyAlias]"; expected 1 but received 2 (reportInvalidTypeForm) -generics_defaults_specialization.py:55:5 - error: Expected no type arguments for class "Foo" (reportInvalidTypeArguments) +generics_defaults_specialization.py:56:5 - error: Expected no type arguments for class "Foo" (reportInvalidTypeArguments) """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 46: Expected 1 errors """ diff --git a/conformance/results/ty/generics_defaults_specialization.toml b/conformance/results/ty/generics_defaults_specialization.toml index 3f8748258..062e89daa 100644 --- a/conformance/results/ty/generics_defaults_specialization.toml +++ b/conformance/results/ty/generics_defaults_specialization.toml @@ -4,8 +4,9 @@ notes = """ Does not reject subscription of an already-specialized generic class. """ errors_diff = """ -Line 55: Expected 1 errors +Line 56: Expected 1 errors """ output = """ generics_defaults_specialization.py:30:15: error[invalid-type-arguments] Too many type arguments: expected between 0 and 1, got 2 +generics_defaults_specialization.py:46:22: error[invalid-assignment] Object of type `` is not assignable to `type[Bar[int]]` """ diff --git a/conformance/results/zuban/generics_defaults_specialization.toml b/conformance/results/zuban/generics_defaults_specialization.toml index 5b68604f1..7592bf2be 100644 --- a/conformance/results/zuban/generics_defaults_specialization.toml +++ b/conformance/results/zuban/generics_defaults_specialization.toml @@ -3,5 +3,6 @@ errors_diff = """ """ output = """ generics_defaults_specialization.py:30: error: Bad number of arguments for type alias, expected between 0 and 1, given 2 [misc] -generics_defaults_specialization.py:55: error: "Foo" expects no type arguments, but 1 given [type-arg] +generics_defaults_specialization.py:46: error: Incompatible types in assignment (expression has type "type[Bar]", variable has type "type[Bar[int]]") [assignment] +generics_defaults_specialization.py:56: error: "Foo" expects no type arguments, but 1 given [type-arg] """ diff --git a/conformance/tests/generics_defaults_specialization.py b/conformance/tests/generics_defaults_specialization.py index a663d3bdf..91db2579b 100644 --- a/conformance/tests/generics_defaults_specialization.py +++ b/conformance/tests/generics_defaults_specialization.py @@ -42,7 +42,8 @@ class SubclassMe(Generic[T1, DefaultStrT]): class Bar(SubclassMe[int, DefaultStrT]): ... -assert_type(Bar, type[Bar[str]]) +x1: type[Bar[str]] = Bar # ok +x2: type[Bar[int]] = Bar # E assert_type(Bar(), Bar[str]) assert_type(Bar[bool](), Bar[bool]) From 2f43808b2d0ed2116efefefba7c999c3d8873445 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Mar 2026 21:51:21 -0700 Subject: [PATCH 2/2] update --- conformance/results/results.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conformance/results/results.html b/conformance/results/results.html index 110fc977e..44628376a 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -302,7 +302,7 @@

Python Type System Conformance Test Results

     generics_defaults_specialization
Partial

Does not correctly resolve defaults when classes are used directly.

-Pass +
Partial

Allows incorrect assignment to type[].

Pass Pass
Partial

Does not reject subscription of an already-specialized generic class.