From 11875d90443fce25d6b6d3b6142252ece7dcb367 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 00:35:27 +0000 Subject: [PATCH 1/6] Conformance suite: Minor tweaks to several assertions for better compatibility with ty --- conformance/tests/annotations_generators.py | 2 +- conformance/tests/generics_defaults.py | 13 +++++++-- .../tests/generics_defaults_referential.py | 8 ++++- conformance/tests/generics_scoping.py | 21 ++++++++++---- conformance/tests/generics_syntax_scoping.py | 29 ++++++++++--------- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/conformance/tests/annotations_generators.py b/conformance/tests/annotations_generators.py index 2ad75808..ba84a37e 100644 --- a/conformance/tests/annotations_generators.py +++ b/conformance/tests/annotations_generators.py @@ -190,4 +190,4 @@ async def generator30() -> AsyncIterator[int]: yield -assert_type(generator30, Callable[[], AsyncIterator[int]]) +assert_type(generator30(), AsyncIterator[int]) diff --git a/conformance/tests/generics_defaults.py b/conformance/tests/generics_defaults.py index 49fbd6cd..e4906c70 100644 --- a/conformance/tests/generics_defaults.py +++ b/conformance/tests/generics_defaults.py @@ -41,8 +41,12 @@ class OneDefault(Generic[T, DefaultBoolT]): ... class AllTheDefaults(Generic[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]): ... +def needs_allthedefaults_or_subclass(x: type[AllTheDefaults[Any, Any, str, int, bool]]) -> None: ... + +# do not use `assert_type` here: some type checkers infer a more precise type +# than `type[]` for class objects +needs_allthedefaults_or_subclass(AllTheDefaults) # OK -assert_type(AllTheDefaults, type[AllTheDefaults[Any, Any, str, int, bool]]) assert_type( AllTheDefaults[int, complex], type[AllTheDefaults[int, complex, str, int, bool]] ) @@ -91,7 +95,12 @@ class Class_ParamSpec(Generic[DefaultP]): ... class Class_TypeVarTuple(Generic[*DefaultTs]): ... -assert_type(Class_TypeVarTuple, type[Class_TypeVarTuple[*tuple[str, int]]]) +def needs_classtypevartuple_or_subclass(x: type[Class_TypeVarTuple[Any, Any]]) -> None: ... + +# do not use `assert_type` here: some type checkers infer a more precise type +# than `type[]` for class objects +needs_classtypevartuple_or_subclass(Class_TypeVarTuple) # OK + assert_type(Class_TypeVarTuple(), Class_TypeVarTuple[str, int]) assert_type(Class_TypeVarTuple[int, bool](), Class_TypeVarTuple[int, bool]) diff --git a/conformance/tests/generics_defaults_referential.py b/conformance/tests/generics_defaults_referential.py index a033d9c5..4db66a36 100644 --- a/conformance/tests/generics_defaults_referential.py +++ b/conformance/tests/generics_defaults_referential.py @@ -91,7 +91,13 @@ class Bar(Generic[Z1, ListDefaultT]): # OK def __init__(self, x: Z1, y: ListDefaultT): ... -assert_type(Bar, type[Bar[Any, list[Any]]]) +def requires_bar_or_subclass(x: type[Bar[Any, list[Any]]]) -> None: ... + +# Don't use `assert_type(Bar, type[Bar[Any, list[Any]]])` here, +# since some type checkers infer a more precise type than `type[]` for +# class objects +requires_bar_or_subclass(Bar) # OK + assert_type(Bar[int], type[Bar[int, list[int]]]) assert_type(Bar[int](0, []), Bar[int, list[int]]) assert_type(Bar[int, list[str]](0, []), Bar[int, list[str]]) diff --git a/conformance/tests/generics_scoping.py b/conformance/tests/generics_scoping.py index 442e1a8d..7003db34 100644 --- a/conformance/tests/generics_scoping.py +++ b/conformance/tests/generics_scoping.py @@ -1,6 +1,6 @@ # Specification: https://typing.readthedocs.io/en/latest/spec/generics.html#scoping-rules-for-type-variables -from typing import TypeVar, Generic, Iterable, TypeAlias, assert_type +from typing import TypeVar, Generic, Iterable, TypeAlias, assert_type, Literal # > A type variable used in a generic function could be inferred to represent # > different types in the same code block. @@ -11,8 +11,13 @@ def fun_1(x: T) -> T: # T here def fun_2(x: T) -> T: # and here could be different return x -assert_type(fun_1(1), int) -assert_type(fun_2('a'), str) +# One of these two should pass; either is acceptable: +assert_type(fun_1(1), int) # E[fun1-int] +assert_type(fun_1(1), Literal[1]) # E[fun1-int] + +# One of these two should pass; either is acceptable: +assert_type(fun_1("a"), str) # E[fun1-str] +assert_type(fun_1("a"), Literal["a"]) # E[fun1-str] # > A type variable used in a method of a generic class that coincides # > with one of the variables that parameterize this class is always bound @@ -39,8 +44,14 @@ def method(self, x: T, y: S) -> S: return y x: Foo[int] = Foo() -assert_type(x.method(0, "abc"), str) -assert_type(x.method(0, b"abc"), bytes) + +# Either of these is acceptable; one of the two should pass: +assert_type(x.method(0, "abc"), str) # E[method-str] +assert_type(x.method(0, "abc"), Literal["abc"]) # E[method-str] + +# Either of these is acceptable; one of the two should pass: +assert_type(x.method(0, b"abc"), bytes) # E[method-bytes] +assert_type(x.method(0, b"abc"), Literal[b"abc"]) # E[method-bytes] # > Unbound type variables should not appear in the bodies of generic functions, # > or in the class bodies apart from method definitions. diff --git a/conformance/tests/generics_syntax_scoping.py b/conformance/tests/generics_syntax_scoping.py index 2d3f5639..3306d397 100644 --- a/conformance/tests/generics_syntax_scoping.py +++ b/conformance/tests/generics_syntax_scoping.py @@ -4,7 +4,7 @@ # Specification: https://peps.python.org/pep-0695/#type-parameter-scopes -from typing import Callable, Mapping, Sequence, TypeVar, assert_type +from typing import Callable, Mapping, Literal, Sequence, TypeVar, assert_type # > A compiler error or runtime exception is generated if the definition # > of an earlier type parameter references a later type parameter even @@ -102,23 +102,24 @@ def method3[T](self, x: T): # E T = int(0) -class Outer2[T]: - T = int(1) - - assert_type(T, int) +def f(a: int, b: str, c: complex): + class Outer2[T]: + T = a - class Inner1: - T = str("") + assert_type(T, int) - assert_type(T, str) + class Inner1: + T = b - def inner_method(self): - assert_type(T, TypeVar) + assert_type(T, str) - def outer_method(self): - T = 3j + def inner_method(self): + assert_type(T, TypeVar) - assert_type(T, complex) + def outer_method(self): + T = c - def inner_func(): assert_type(T, complex) + + def inner_func(): + assert_type(T, complex) From 652dde5fff12991f57520d021af3bad55afdff5a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 01:01:08 +0000 Subject: [PATCH 2/6] update results for other type checkers --- .../results/mypy/generics_defaults.toml | 46 ++++++++---------- .../mypy/generics_defaults_referential.toml | 10 ++-- .../results/mypy/generics_scoping.toml | 48 ++++++++++--------- .../results/mypy/generics_syntax_scoping.toml | 18 +++---- .../results/pyrefly/generics_defaults.toml | 10 ++-- .../results/pyrefly/generics_scoping.toml | 24 ++++++---- .../results/pyright/generics_defaults.toml | 10 ++-- .../results/pyright/generics_scoping.toml | 24 ++++++---- conformance/results/results.html | 2 +- .../results/zuban/generics_defaults.toml | 10 ++-- .../results/zuban/generics_scoping.toml | 48 ++++++++++--------- conformance/tests/annotations_generators.py | 4 +- 12 files changed, 133 insertions(+), 121 deletions(-) diff --git a/conformance/results/mypy/generics_defaults.toml b/conformance/results/mypy/generics_defaults.toml index c12fd160..f7036eea 100644 --- a/conformance/results/mypy/generics_defaults.toml +++ b/conformance/results/mypy/generics_defaults.toml @@ -4,35 +4,31 @@ generics_defaults.py:24: error: "T" cannot appear after "DefaultStrT" in type pa generics_defaults.py:30: error: Expression is of type "type[NoNonDefaults[DefaultStrT, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type] generics_defaults.py:31: error: Expression is of type "type[NoNonDefaults[str, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type] generics_defaults.py:38: error: Expression is of type "type[OneDefault[float, DefaultBoolT]]", not "type[OneDefault[float, bool]]" [assert-type] -generics_defaults.py:45: error: Expression is of type "type[AllTheDefaults[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[Any, Any, str, int, bool]]" [assert-type] -generics_defaults.py:46: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:50: error: Type application has too few types (expected between 2 and 5) [misc] -generics_defaults.py:52: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:55: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:79: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type] -generics_defaults.py:94: error: Expression is of type "type[Class_TypeVarTuple[*DefaultTs]]", not "type[Class_TypeVarTuple[str, int]]" [assert-type] -generics_defaults.py:107: error: TypeVar default must be a subtype of the bound type [misc] -generics_defaults.py:114: error: TypeVar default must be one of the constraint types [misc] -generics_defaults.py:132: error: Expression is of type "int", not "Any" [assert-type] -generics_defaults.py:156: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type] -generics_defaults.py:156: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] -generics_defaults.py:157: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type] -generics_defaults.py:157: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] +generics_defaults.py:50: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:54: error: Type application has too few types (expected between 2 and 5) [misc] +generics_defaults.py:56: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:63: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:83: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type] +generics_defaults.py:116: error: TypeVar default must be a subtype of the bound type [misc] +generics_defaults.py:123: error: TypeVar default must be one of the constraint types [misc] +generics_defaults.py:141: error: Expression is of type "int", not "Any" [assert-type] +generics_defaults.py:165: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type] +generics_defaults.py:165: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] +generics_defaults.py:166: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type] +generics_defaults.py:166: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] """ conformance_automated = "Fail" errors_diff = """ -Line 143: Expected 1 errors +Line 152: Expected 1 errors Line 30: Unexpected errors ['generics_defaults.py:30: error: Expression is of type "type[NoNonDefaults[DefaultStrT, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type]'] Line 31: Unexpected errors ['generics_defaults.py:31: error: Expression is of type "type[NoNonDefaults[str, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type]'] Line 38: Unexpected errors ['generics_defaults.py:38: error: Expression is of type "type[OneDefault[float, DefaultBoolT]]", not "type[OneDefault[float, bool]]" [assert-type]'] -Line 45: Unexpected errors ['generics_defaults.py:45: error: Expression is of type "type[AllTheDefaults[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[Any, Any, str, int, bool]]" [assert-type]'] -Line 46: Unexpected errors ['generics_defaults.py:46: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 52: Unexpected errors ['generics_defaults.py:52: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 55: Unexpected errors ['generics_defaults.py:55: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 59: Unexpected errors ['generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 79: Unexpected errors ['generics_defaults.py:79: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type]'] -Line 94: Unexpected errors ['generics_defaults.py:94: error: Expression is of type "type[Class_TypeVarTuple[*DefaultTs]]", not "type[Class_TypeVarTuple[str, int]]" [assert-type]'] -Line 156: Unexpected errors ['generics_defaults.py:156: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type]', 'generics_defaults.py:156: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] -Line 157: Unexpected errors ['generics_defaults.py:157: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type]', 'generics_defaults.py:157: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] +Line 50: Unexpected errors ['generics_defaults.py:50: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 56: Unexpected errors ['generics_defaults.py:56: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 59: Unexpected errors ['generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 63: Unexpected errors ['generics_defaults.py:63: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 83: Unexpected errors ['generics_defaults.py:83: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type]'] +Line 165: Unexpected errors ['generics_defaults.py:165: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type]', 'generics_defaults.py:165: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] +Line 166: Unexpected errors ['generics_defaults.py:166: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type]', 'generics_defaults.py:166: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] """ diff --git a/conformance/results/mypy/generics_defaults_referential.toml b/conformance/results/mypy/generics_defaults_referential.toml index 588048dd..838c0deb 100644 --- a/conformance/results/mypy/generics_defaults_referential.toml +++ b/conformance/results/mypy/generics_defaults_referential.toml @@ -6,9 +6,8 @@ generics_defaults_referential.py:53: error: Type parameter "Start2T" has a defau generics_defaults_referential.py:74: error: TypeVar default must be one of the constraint types [misc] generics_defaults_referential.py:77: error: TypeVar default must be one of the constraint types [misc] generics_defaults_referential.py:78: error: TypeVar default must be one of the constraint types [misc] -generics_defaults_referential.py:94: error: Expression is of type "type[Bar[Z1, ListDefaultT]]", not "type[Bar[Any, list[Any]]]" [assert-type] -generics_defaults_referential.py:95: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type] -generics_defaults_referential.py:96: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type] +generics_defaults_referential.py:101: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type] +generics_defaults_referential.py:102: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type] """ conformance_automated = "Fail" errors_diff = """ @@ -17,7 +16,6 @@ Line 60: Expected 1 errors Line 68: Expected 1 errors Line 23: Unexpected errors ['generics_defaults_referential.py:23: error: Expression is of type "type[slice[StartT, StopT, StepT]]", not "type[slice[int, int, int | None]]" [assert-type]'] Line 77: Unexpected errors ['generics_defaults_referential.py:77: error: TypeVar default must be one of the constraint types [misc]'] -Line 94: Unexpected errors ['generics_defaults_referential.py:94: error: Expression is of type "type[Bar[Z1, ListDefaultT]]", not "type[Bar[Any, list[Any]]]" [assert-type]'] -Line 95: Unexpected errors ['generics_defaults_referential.py:95: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type]'] -Line 96: Unexpected errors ['generics_defaults_referential.py:96: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type]'] +Line 101: Unexpected errors ['generics_defaults_referential.py:101: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type]'] +Line 102: Unexpected errors ['generics_defaults_referential.py:102: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type]'] """ diff --git a/conformance/results/mypy/generics_scoping.toml b/conformance/results/mypy/generics_scoping.toml index 3c3e0054..013baaa7 100644 --- a/conformance/results/mypy/generics_scoping.toml +++ b/conformance/results/mypy/generics_scoping.toml @@ -1,26 +1,30 @@ output = """ -generics_scoping.py:29: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] -generics_scoping.py:50: error: Type variable "generics_scoping.S" is unbound [valid-type] -generics_scoping.py:50: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) -generics_scoping.py:50: note: (Hint: Use "S" in function signature to bind "S" inside a function) -generics_scoping.py:54: error: Type variable "generics_scoping.S" is unbound [valid-type] -generics_scoping.py:54: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) -generics_scoping.py:54: note: (Hint: Use "S" in function signature to bind "S" inside a function) -generics_scoping.py:65: error: Free type variable expected in Generic[...] [misc] -generics_scoping.py:75: error: Type variable "T" is bound by an outer class [valid-type] -generics_scoping.py:78: error: Type variable "generics_scoping.T" is unbound [valid-type] -generics_scoping.py:78: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:78: note: (Hint: Use "T" in function signature to bind "T" inside a function) -generics_scoping.py:87: error: Can't use bound type variable "T" to define generic alias [valid-type] -generics_scoping.py:94: error: Type variable "generics_scoping.T" is unbound [valid-type] -generics_scoping.py:94: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:94: note: (Hint: Use "T" in function signature to bind "T" inside a function) -generics_scoping.py:95: error: Type variable "generics_scoping.T" is unbound [valid-type] -generics_scoping.py:95: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:95: note: (Hint: Use "T" in function signature to bind "T" inside a function) -generics_scoping.py:96: error: Type variable "generics_scoping.T" is unbound [valid-type] -generics_scoping.py:96: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:96: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:16: error: Expression is of type "int", not "Literal[1]" [assert-type] +generics_scoping.py:20: error: Expression is of type "str", not "Literal['a']" [assert-type] +generics_scoping.py:34: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] +generics_scoping.py:50: error: Expression is of type "str", not "Literal['abc']" [assert-type] +generics_scoping.py:54: error: Expression is of type "bytes", not "Literal[b'abc']" [assert-type] +generics_scoping.py:61: error: Type variable "generics_scoping.S" is unbound [valid-type] +generics_scoping.py:61: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) +generics_scoping.py:61: note: (Hint: Use "S" in function signature to bind "S" inside a function) +generics_scoping.py:65: error: Type variable "generics_scoping.S" is unbound [valid-type] +generics_scoping.py:65: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) +generics_scoping.py:65: note: (Hint: Use "S" in function signature to bind "S" inside a function) +generics_scoping.py:76: error: Free type variable expected in Generic[...] [misc] +generics_scoping.py:86: error: Type variable "T" is bound by an outer class [valid-type] +generics_scoping.py:89: error: Type variable "generics_scoping.T" is unbound [valid-type] +generics_scoping.py:89: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:89: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:98: error: Can't use bound type variable "T" to define generic alias [valid-type] +generics_scoping.py:105: error: Type variable "generics_scoping.T" is unbound [valid-type] +generics_scoping.py:105: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:105: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:106: error: Type variable "generics_scoping.T" is unbound [valid-type] +generics_scoping.py:106: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:106: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:107: error: Type variable "generics_scoping.T" is unbound [valid-type] +generics_scoping.py:107: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:107: note: (Hint: Use "T" in function signature to bind "T" inside a function) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/mypy/generics_syntax_scoping.toml b/conformance/results/mypy/generics_syntax_scoping.toml index 2e249720..34cc33a0 100644 --- a/conformance/results/mypy/generics_syntax_scoping.toml +++ b/conformance/results/mypy/generics_syntax_scoping.toml @@ -19,18 +19,18 @@ generics_syntax_scoping.py:95: error: "T" already defined as a type parameter [ 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:116: error: Expression is of type "Any", not "TypeVar" [assert-type] -generics_syntax_scoping.py:116: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:121: error: Expression is of type "Any", not "complex" [assert-type] -generics_syntax_scoping.py:121: note: "assert_type" expects everything to be "Any" in unchecked functions -generics_syntax_scoping.py:124: error: Expression is of type "Any", not "complex" [assert-type] -generics_syntax_scoping.py:124: note: "assert_type" expects everything to be "Any" in unchecked functions +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 """ 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 116: Unexpected errors ['generics_syntax_scoping.py:116: error: Expression is of type "Any", not "TypeVar" [assert-type]'] -Line 121: Unexpected errors ['generics_syntax_scoping.py:121: error: Expression is of type "Any", not "complex" [assert-type]'] -Line 124: Unexpected errors ['generics_syntax_scoping.py:124: error: Expression is of type "Any", not "complex" [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]'] """ diff --git a/conformance/results/pyrefly/generics_defaults.toml b/conformance/results/pyrefly/generics_defaults.toml index efe58237..fa9dae6f 100644 --- a/conformance/results/pyrefly/generics_defaults.toml +++ b/conformance/results/pyrefly/generics_defaults.toml @@ -3,9 +3,9 @@ errors_diff = """ """ output = """ ERROR generics_defaults.py:24:7-31: Type parameter `T` without a default cannot follow type parameter `DefaultStrT` with a default [invalid-type-var] -ERROR generics_defaults.py:50:1-20: Expected 5 type arguments for `AllTheDefaults`, got 1 [bad-specialization] -ERROR generics_defaults.py:107:51-54: Expected default `int` of `Invalid1` to be assignable to the upper bound of `str` [invalid-type-var] -ERROR generics_defaults.py:114:52-55: Expected default `int` of `Invalid2` to be one of the following constraints: `float`, `str` [invalid-type-var] -ERROR generics_defaults.py:132:12-27: assert_type(int, Any) failed [assert-type] -ERROR generics_defaults.py:143:7-11: TypeVar `T5` with a default cannot follow TypeVarTuple `Ts` [invalid-type-var] +ERROR generics_defaults.py:54:1-20: Expected 5 type arguments for `AllTheDefaults`, got 1 [bad-specialization] +ERROR generics_defaults.py:116:51-54: Expected default `int` of `Invalid1` to be assignable to the upper bound of `str` [invalid-type-var] +ERROR generics_defaults.py:123:52-55: Expected default `int` of `Invalid2` to be one of the following constraints: `float`, `str` [invalid-type-var] +ERROR generics_defaults.py:141:12-27: assert_type(int, Any) failed [assert-type] +ERROR generics_defaults.py:152:7-11: TypeVar `T5` with a default cannot follow TypeVarTuple `Ts` [invalid-type-var] """ diff --git a/conformance/results/pyrefly/generics_scoping.toml b/conformance/results/pyrefly/generics_scoping.toml index f73633f3..a4d46cbf 100644 --- a/conformance/results/pyrefly/generics_scoping.toml +++ b/conformance/results/pyrefly/generics_scoping.toml @@ -4,16 +4,20 @@ Does not implement several scoping checks/restrictions for generics """ conformance_automated = "Fail" errors_diff = """ -Line 50: Expected 1 errors -Line 54: Expected 1 errors -Line 75: Expected 1 errors -Line 78: Expected 1 errors -Line 87: Expected 1 errors -Line 94: Expected 1 errors -Line 95: Expected 1 errors -Line 96: Expected 1 errors +Line 61: Expected 1 errors +Line 65: Expected 1 errors +Line 86: Expected 1 errors +Line 89: Expected 1 errors +Line 98: Expected 1 errors +Line 105: Expected 1 errors +Line 106: Expected 1 errors +Line 107: Expected 1 errors """ output = """ -ERROR generics_scoping.py:29:10-13: Argument `Literal['a']` is not assignable to parameter `x` with type `int` in function `MyClass.meth_2` [bad-argument-type] -ERROR generics_scoping.py:65:11-20: Redundant type parameter declaration [invalid-type-var] +ERROR generics_scoping.py:16:12-34: assert_type(int, Literal[1]) failed [assert-type] +ERROR generics_scoping.py:20:12-38: assert_type(str, Literal['a']) failed [assert-type] +ERROR generics_scoping.py:34:10-13: Argument `Literal['a']` is not assignable to parameter `x` with type `int` in function `MyClass.meth_2` [bad-argument-type] +ERROR generics_scoping.py:50:12-48: assert_type(str, Literal['abc']) failed [assert-type] +ERROR generics_scoping.py:54:12-50: assert_type(bytes, Literal[b'abc']) failed [assert-type] +ERROR generics_scoping.py:76:11-20: Redundant type parameter declaration [invalid-type-var] """ diff --git a/conformance/results/pyright/generics_defaults.toml b/conformance/results/pyright/generics_defaults.toml index 35fdac0c..006455b1 100644 --- a/conformance/results/pyright/generics_defaults.toml +++ b/conformance/results/pyright/generics_defaults.toml @@ -1,11 +1,11 @@ conformant = "Pass" output = """ generics_defaults.py:24:7 - error: "T" cannot appear after "DefaultStrT" in type parameter list because it has no default type (reportGeneralTypeIssues) -generics_defaults.py:50:16 - error: Too few type arguments provided for "AllTheDefaults"; expected 2 but received 1 (reportInvalidTypeArguments) -generics_defaults.py:107:51 - error: TypeVar default type must be a subtype of the bound type (reportGeneralTypeIssues) -generics_defaults.py:114:52 - error: TypeVar default type must be one of the constrained types (reportGeneralTypeIssues) -generics_defaults.py:132:13 - error: "assert_type" mismatch: expected "Any" but received "int" (reportAssertTypeFailure) -generics_defaults.py:143:7 - error: TypeVar "T5" has a default value and cannot follow TypeVarTuple "Ts" (reportGeneralTypeIssues) +generics_defaults.py:54:16 - error: Too few type arguments provided for "AllTheDefaults"; expected 2 but received 1 (reportInvalidTypeArguments) +generics_defaults.py:116:51 - error: TypeVar default type must be a subtype of the bound type (reportGeneralTypeIssues) +generics_defaults.py:123:52 - error: TypeVar default type must be one of the constrained types (reportGeneralTypeIssues) +generics_defaults.py:141:13 - error: "assert_type" mismatch: expected "Any" but received "int" (reportAssertTypeFailure) +generics_defaults.py:152:7 - error: TypeVar "T5" has a default value and cannot follow TypeVarTuple "Ts" (reportGeneralTypeIssues) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/pyright/generics_scoping.toml b/conformance/results/pyright/generics_scoping.toml index 2e352ca7..9e73f07d 100644 --- a/conformance/results/pyright/generics_scoping.toml +++ b/conformance/results/pyright/generics_scoping.toml @@ -1,16 +1,20 @@ conformant = "Pass" output = """ -generics_scoping.py:29:10 - error: Argument of type "Literal['a']" cannot be assigned to parameter "x" of type "int" in function "meth_2" +generics_scoping.py:16:13 - error: "assert_type" mismatch: expected "Literal[1]" but received "int" (reportAssertTypeFailure) +generics_scoping.py:20:13 - error: "assert_type" mismatch: expected "Literal['a']" but received "str" (reportAssertTypeFailure) +generics_scoping.py:34:10 - error: Argument of type "Literal['a']" cannot be assigned to parameter "x" of type "int" in function "meth_2"   "Literal['a']" is not assignable to "int" (reportArgumentType) -generics_scoping.py:50:13 - error: Type variable "S" has no meaning in this context (reportGeneralTypeIssues) -generics_scoping.py:54:19 - error: Type variable "S" has no meaning in this context (reportGeneralTypeIssues) -generics_scoping.py:65:29 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) -generics_scoping.py:75:24 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) -generics_scoping.py:78:17 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) -generics_scoping.py:87:5 - error: Generic type alias within class cannot use bound type variables T (reportInvalidTypeForm) -generics_scoping.py:94:14 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) -generics_scoping.py:95:19 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) -generics_scoping.py:96:6 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:50:13 - error: "assert_type" mismatch: expected "Literal['abc']" but received "str" (reportAssertTypeFailure) +generics_scoping.py:54:13 - error: "assert_type" mismatch: expected "Literal[b"abc"]" but received "bytes" (reportAssertTypeFailure) +generics_scoping.py:61:13 - error: Type variable "S" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:65:19 - error: Type variable "S" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:76:29 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) +generics_scoping.py:86:24 - error: TypeVar "T" is already in use by an outer scope (reportGeneralTypeIssues) +generics_scoping.py:89:17 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:98:5 - error: Generic type alias within class cannot use bound type variables T (reportInvalidTypeForm) +generics_scoping.py:105:14 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:106:19 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) +generics_scoping.py:107:6 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 72964529..05d8cbd1 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -307,7 +307,7 @@

Python Type System Conformance Test Results

     generics_scoping Pass Pass -Pass +Unknown
Partial

Does not implement several scoping checks/restrictions for generics

     generics_self_advanced diff --git a/conformance/results/zuban/generics_defaults.toml b/conformance/results/zuban/generics_defaults.toml index 1eb17cae..9a166994 100644 --- a/conformance/results/zuban/generics_defaults.toml +++ b/conformance/results/zuban/generics_defaults.toml @@ -3,9 +3,9 @@ errors_diff = """ """ output = """ generics_defaults.py:24: error: "T" cannot appear after "DefaultStrT" in type parameter list because it has no default type [misc] -generics_defaults.py:50: error: "AllTheDefaults" expects between 2 and 5 type arguments, but 1 given [type-arg] -generics_defaults.py:107: error: TypeVar default must be a subtype of the bound type [misc] -generics_defaults.py:114: error: TypeVar default must be one of the constraint types [misc] -generics_defaults.py:132: error: Expression is of type "int", not "Any" [misc] -generics_defaults.py:143: error: TypeVar defaults are ambiguous after a TypeVarTuple [misc] +generics_defaults.py:54: error: "AllTheDefaults" expects between 2 and 5 type arguments, but 1 given [type-arg] +generics_defaults.py:116: error: TypeVar default must be a subtype of the bound type [misc] +generics_defaults.py:123: error: TypeVar default must be one of the constraint types [misc] +generics_defaults.py:141: error: Expression is of type "int", not "Any" [misc] +generics_defaults.py:152: error: TypeVar defaults are ambiguous after a TypeVarTuple [misc] """ diff --git a/conformance/results/zuban/generics_scoping.toml b/conformance/results/zuban/generics_scoping.toml index 92f6073d..9db5b66f 100644 --- a/conformance/results/zuban/generics_scoping.toml +++ b/conformance/results/zuban/generics_scoping.toml @@ -1,26 +1,30 @@ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Lines 15, 16: Expected error (tag 'fun1-int') +Lines 19, 20: Expected error (tag 'fun1-str') +Lines 49, 50: Expected error (tag 'method-str') +Lines 53, 54: Expected error (tag 'method-bytes') """ output = """ -generics_scoping.py:29: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] -generics_scoping.py:50: error: Type variable "generics_scoping.S" is unbound [misc] -generics_scoping.py:50: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) -generics_scoping.py:50: note: (Hint: Use "S" in function signature to bind "S" inside a function) -generics_scoping.py:54: error: Type variable "generics_scoping.S" is unbound [misc] -generics_scoping.py:54: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) -generics_scoping.py:54: note: (Hint: Use "S" in function signature to bind "S" inside a function) -generics_scoping.py:65: error: Free type variable expected in Generic[...] [misc] -generics_scoping.py:75: error: Type variable "T" is bound by an outer class [misc] -generics_scoping.py:78: error: Type variable "T" is bound by an outer class [misc] -generics_scoping.py:80: error: Type variable "T" is bound by an outer class [misc] -generics_scoping.py:87: error: Can't use bound type variable "T" to define generic alias [misc] -generics_scoping.py:94: error: Type variable "generics_scoping.T" is unbound [misc] -generics_scoping.py:94: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:94: note: (Hint: Use "T" in function signature to bind "T" inside a function) -generics_scoping.py:95: error: Type variable "generics_scoping.T" is unbound [misc] -generics_scoping.py:95: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:95: note: (Hint: Use "T" in function signature to bind "T" inside a function) -generics_scoping.py:96: error: Type variable "generics_scoping.T" is unbound [misc] -generics_scoping.py:96: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) -generics_scoping.py:96: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:34: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] +generics_scoping.py:61: error: Type variable "generics_scoping.S" is unbound [misc] +generics_scoping.py:61: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) +generics_scoping.py:61: note: (Hint: Use "S" in function signature to bind "S" inside a function) +generics_scoping.py:65: error: Type variable "generics_scoping.S" is unbound [misc] +generics_scoping.py:65: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) +generics_scoping.py:65: note: (Hint: Use "S" in function signature to bind "S" inside a function) +generics_scoping.py:76: error: Free type variable expected in Generic[...] [misc] +generics_scoping.py:86: error: Type variable "T" is bound by an outer class [misc] +generics_scoping.py:89: error: Type variable "T" is bound by an outer class [misc] +generics_scoping.py:91: error: Type variable "T" is bound by an outer class [misc] +generics_scoping.py:98: error: Can't use bound type variable "T" to define generic alias [misc] +generics_scoping.py:105: error: Type variable "generics_scoping.T" is unbound [misc] +generics_scoping.py:105: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:105: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:106: error: Type variable "generics_scoping.T" is unbound [misc] +generics_scoping.py:106: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:106: note: (Hint: Use "T" in function signature to bind "T" inside a function) +generics_scoping.py:107: error: Type variable "generics_scoping.T" is unbound [misc] +generics_scoping.py:107: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) +generics_scoping.py:107: note: (Hint: Use "T" in function signature to bind "T" inside a function) """ diff --git a/conformance/tests/annotations_generators.py b/conformance/tests/annotations_generators.py index ba84a37e..b69e070c 100644 --- a/conformance/tests/annotations_generators.py +++ b/conformance/tests/annotations_generators.py @@ -190,4 +190,6 @@ async def generator30() -> AsyncIterator[int]: yield -assert_type(generator30(), AsyncIterator[int]) +async def uses_generator30() -> None: + async for x in generator30(): + assert_type(x, int) From 7b6a5d2d6c068f5643b82be36db00a77cf5fd8ca Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 01:26:01 +0000 Subject: [PATCH 3/6] revert some questionable changes to tests around type-parameter defaults --- .../results/mypy/generics_defaults.toml | 46 ++++++++++--------- .../mypy/generics_defaults_referential.toml | 10 ++-- .../results/pyrefly/generics_defaults.toml | 10 ++-- .../results/pyright/generics_defaults.toml | 10 ++-- .../results/zuban/generics_defaults.toml | 10 ++-- conformance/tests/generics_defaults.py | 13 +----- .../tests/generics_defaults_referential.py | 8 +--- conformance/tests/generics_syntax_scoping.py | 2 +- 8 files changed, 50 insertions(+), 59 deletions(-) diff --git a/conformance/results/mypy/generics_defaults.toml b/conformance/results/mypy/generics_defaults.toml index f7036eea..c12fd160 100644 --- a/conformance/results/mypy/generics_defaults.toml +++ b/conformance/results/mypy/generics_defaults.toml @@ -4,31 +4,35 @@ generics_defaults.py:24: error: "T" cannot appear after "DefaultStrT" in type pa generics_defaults.py:30: error: Expression is of type "type[NoNonDefaults[DefaultStrT, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type] generics_defaults.py:31: error: Expression is of type "type[NoNonDefaults[str, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type] generics_defaults.py:38: error: Expression is of type "type[OneDefault[float, DefaultBoolT]]", not "type[OneDefault[float, bool]]" [assert-type] -generics_defaults.py:50: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:54: error: Type application has too few types (expected between 2 and 5) [misc] -generics_defaults.py:56: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:63: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] -generics_defaults.py:83: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type] -generics_defaults.py:116: error: TypeVar default must be a subtype of the bound type [misc] -generics_defaults.py:123: error: TypeVar default must be one of the constraint types [misc] -generics_defaults.py:141: error: Expression is of type "int", not "Any" [assert-type] -generics_defaults.py:165: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type] -generics_defaults.py:165: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] -generics_defaults.py:166: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type] -generics_defaults.py:166: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] +generics_defaults.py:45: error: Expression is of type "type[AllTheDefaults[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[Any, Any, str, int, bool]]" [assert-type] +generics_defaults.py:46: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:50: error: Type application has too few types (expected between 2 and 5) [misc] +generics_defaults.py:52: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:55: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type] +generics_defaults.py:79: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type] +generics_defaults.py:94: error: Expression is of type "type[Class_TypeVarTuple[*DefaultTs]]", not "type[Class_TypeVarTuple[str, int]]" [assert-type] +generics_defaults.py:107: error: TypeVar default must be a subtype of the bound type [misc] +generics_defaults.py:114: error: TypeVar default must be one of the constraint types [misc] +generics_defaults.py:132: error: Expression is of type "int", not "Any" [assert-type] +generics_defaults.py:156: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type] +generics_defaults.py:156: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] +generics_defaults.py:157: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type] +generics_defaults.py:157: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc] """ conformance_automated = "Fail" errors_diff = """ -Line 152: Expected 1 errors +Line 143: Expected 1 errors Line 30: Unexpected errors ['generics_defaults.py:30: error: Expression is of type "type[NoNonDefaults[DefaultStrT, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type]'] Line 31: Unexpected errors ['generics_defaults.py:31: error: Expression is of type "type[NoNonDefaults[str, DefaultIntT]]", not "type[NoNonDefaults[str, int]]" [assert-type]'] Line 38: Unexpected errors ['generics_defaults.py:38: error: Expression is of type "type[OneDefault[float, DefaultBoolT]]", not "type[OneDefault[float, bool]]" [assert-type]'] -Line 50: Unexpected errors ['generics_defaults.py:50: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 56: Unexpected errors ['generics_defaults.py:56: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 59: Unexpected errors ['generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 63: Unexpected errors ['generics_defaults.py:63: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] -Line 83: Unexpected errors ['generics_defaults.py:83: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type]'] -Line 165: Unexpected errors ['generics_defaults.py:165: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type]', 'generics_defaults.py:165: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] -Line 166: Unexpected errors ['generics_defaults.py:166: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type]', 'generics_defaults.py:166: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] +Line 45: Unexpected errors ['generics_defaults.py:45: error: Expression is of type "type[AllTheDefaults[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[Any, Any, str, int, bool]]" [assert-type]'] +Line 46: Unexpected errors ['generics_defaults.py:46: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 52: Unexpected errors ['generics_defaults.py:52: error: Expression is of type "type[AllTheDefaults[int, complex, DefaultStrT, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 55: Unexpected errors ['generics_defaults.py:55: error: Expression is of type "type[AllTheDefaults[int, complex, str, DefaultIntT, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 59: Unexpected errors ['generics_defaults.py:59: error: Expression is of type "type[AllTheDefaults[int, complex, str, int, DefaultBoolT]]", not "type[AllTheDefaults[int, complex, str, int, bool]]" [assert-type]'] +Line 79: Unexpected errors ['generics_defaults.py:79: error: Expression is of type "type[Class_ParamSpec[DefaultP]]", not "type[Class_ParamSpec[[str, int]]]" [assert-type]'] +Line 94: Unexpected errors ['generics_defaults.py:94: error: Expression is of type "type[Class_TypeVarTuple[*DefaultTs]]", not "type[Class_TypeVarTuple[str, int]]" [assert-type]'] +Line 156: Unexpected errors ['generics_defaults.py:156: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [float, bool]]]" [assert-type]', 'generics_defaults.py:156: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] +Line 157: Unexpected errors ['generics_defaults.py:157: error: Expression is of type "type[Foo6[*tuple[Any, ...], Any]]", not "type[Foo6[int, str, [bytes]]]" [assert-type]', 'generics_defaults.py:157: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [misc]'] """ diff --git a/conformance/results/mypy/generics_defaults_referential.toml b/conformance/results/mypy/generics_defaults_referential.toml index 838c0deb..588048dd 100644 --- a/conformance/results/mypy/generics_defaults_referential.toml +++ b/conformance/results/mypy/generics_defaults_referential.toml @@ -6,8 +6,9 @@ generics_defaults_referential.py:53: error: Type parameter "Start2T" has a defau generics_defaults_referential.py:74: error: TypeVar default must be one of the constraint types [misc] generics_defaults_referential.py:77: error: TypeVar default must be one of the constraint types [misc] generics_defaults_referential.py:78: error: TypeVar default must be one of the constraint types [misc] -generics_defaults_referential.py:101: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type] -generics_defaults_referential.py:102: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type] +generics_defaults_referential.py:94: error: Expression is of type "type[Bar[Z1, ListDefaultT]]", not "type[Bar[Any, list[Any]]]" [assert-type] +generics_defaults_referential.py:95: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type] +generics_defaults_referential.py:96: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type] """ conformance_automated = "Fail" errors_diff = """ @@ -16,6 +17,7 @@ Line 60: Expected 1 errors Line 68: Expected 1 errors Line 23: Unexpected errors ['generics_defaults_referential.py:23: error: Expression is of type "type[slice[StartT, StopT, StepT]]", not "type[slice[int, int, int | None]]" [assert-type]'] Line 77: Unexpected errors ['generics_defaults_referential.py:77: error: TypeVar default must be one of the constraint types [misc]'] -Line 101: Unexpected errors ['generics_defaults_referential.py:101: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type]'] -Line 102: Unexpected errors ['generics_defaults_referential.py:102: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type]'] +Line 94: Unexpected errors ['generics_defaults_referential.py:94: error: Expression is of type "type[Bar[Z1, ListDefaultT]]", not "type[Bar[Any, list[Any]]]" [assert-type]'] +Line 95: Unexpected errors ['generics_defaults_referential.py:95: error: Expression is of type "type[Bar[int, ListDefaultT]]", not "type[Bar[int, list[int]]]" [assert-type]'] +Line 96: Unexpected errors ['generics_defaults_referential.py:96: error: Expression is of type "Bar[int, list[Never]]", not "Bar[int, list[int]]" [assert-type]'] """ diff --git a/conformance/results/pyrefly/generics_defaults.toml b/conformance/results/pyrefly/generics_defaults.toml index fa9dae6f..efe58237 100644 --- a/conformance/results/pyrefly/generics_defaults.toml +++ b/conformance/results/pyrefly/generics_defaults.toml @@ -3,9 +3,9 @@ errors_diff = """ """ output = """ ERROR generics_defaults.py:24:7-31: Type parameter `T` without a default cannot follow type parameter `DefaultStrT` with a default [invalid-type-var] -ERROR generics_defaults.py:54:1-20: Expected 5 type arguments for `AllTheDefaults`, got 1 [bad-specialization] -ERROR generics_defaults.py:116:51-54: Expected default `int` of `Invalid1` to be assignable to the upper bound of `str` [invalid-type-var] -ERROR generics_defaults.py:123:52-55: Expected default `int` of `Invalid2` to be one of the following constraints: `float`, `str` [invalid-type-var] -ERROR generics_defaults.py:141:12-27: assert_type(int, Any) failed [assert-type] -ERROR generics_defaults.py:152:7-11: TypeVar `T5` with a default cannot follow TypeVarTuple `Ts` [invalid-type-var] +ERROR generics_defaults.py:50:1-20: Expected 5 type arguments for `AllTheDefaults`, got 1 [bad-specialization] +ERROR generics_defaults.py:107:51-54: Expected default `int` of `Invalid1` to be assignable to the upper bound of `str` [invalid-type-var] +ERROR generics_defaults.py:114:52-55: Expected default `int` of `Invalid2` to be one of the following constraints: `float`, `str` [invalid-type-var] +ERROR generics_defaults.py:132:12-27: assert_type(int, Any) failed [assert-type] +ERROR generics_defaults.py:143:7-11: TypeVar `T5` with a default cannot follow TypeVarTuple `Ts` [invalid-type-var] """ diff --git a/conformance/results/pyright/generics_defaults.toml b/conformance/results/pyright/generics_defaults.toml index 006455b1..35fdac0c 100644 --- a/conformance/results/pyright/generics_defaults.toml +++ b/conformance/results/pyright/generics_defaults.toml @@ -1,11 +1,11 @@ conformant = "Pass" output = """ generics_defaults.py:24:7 - error: "T" cannot appear after "DefaultStrT" in type parameter list because it has no default type (reportGeneralTypeIssues) -generics_defaults.py:54:16 - error: Too few type arguments provided for "AllTheDefaults"; expected 2 but received 1 (reportInvalidTypeArguments) -generics_defaults.py:116:51 - error: TypeVar default type must be a subtype of the bound type (reportGeneralTypeIssues) -generics_defaults.py:123:52 - error: TypeVar default type must be one of the constrained types (reportGeneralTypeIssues) -generics_defaults.py:141:13 - error: "assert_type" mismatch: expected "Any" but received "int" (reportAssertTypeFailure) -generics_defaults.py:152:7 - error: TypeVar "T5" has a default value and cannot follow TypeVarTuple "Ts" (reportGeneralTypeIssues) +generics_defaults.py:50:16 - error: Too few type arguments provided for "AllTheDefaults"; expected 2 but received 1 (reportInvalidTypeArguments) +generics_defaults.py:107:51 - error: TypeVar default type must be a subtype of the bound type (reportGeneralTypeIssues) +generics_defaults.py:114:52 - error: TypeVar default type must be one of the constrained types (reportGeneralTypeIssues) +generics_defaults.py:132:13 - error: "assert_type" mismatch: expected "Any" but received "int" (reportAssertTypeFailure) +generics_defaults.py:143:7 - error: TypeVar "T5" has a default value and cannot follow TypeVarTuple "Ts" (reportGeneralTypeIssues) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/zuban/generics_defaults.toml b/conformance/results/zuban/generics_defaults.toml index 9a166994..1eb17cae 100644 --- a/conformance/results/zuban/generics_defaults.toml +++ b/conformance/results/zuban/generics_defaults.toml @@ -3,9 +3,9 @@ errors_diff = """ """ output = """ generics_defaults.py:24: error: "T" cannot appear after "DefaultStrT" in type parameter list because it has no default type [misc] -generics_defaults.py:54: error: "AllTheDefaults" expects between 2 and 5 type arguments, but 1 given [type-arg] -generics_defaults.py:116: error: TypeVar default must be a subtype of the bound type [misc] -generics_defaults.py:123: error: TypeVar default must be one of the constraint types [misc] -generics_defaults.py:141: error: Expression is of type "int", not "Any" [misc] -generics_defaults.py:152: error: TypeVar defaults are ambiguous after a TypeVarTuple [misc] +generics_defaults.py:50: error: "AllTheDefaults" expects between 2 and 5 type arguments, but 1 given [type-arg] +generics_defaults.py:107: error: TypeVar default must be a subtype of the bound type [misc] +generics_defaults.py:114: error: TypeVar default must be one of the constraint types [misc] +generics_defaults.py:132: error: Expression is of type "int", not "Any" [misc] +generics_defaults.py:143: error: TypeVar defaults are ambiguous after a TypeVarTuple [misc] """ diff --git a/conformance/tests/generics_defaults.py b/conformance/tests/generics_defaults.py index e4906c70..49fbd6cd 100644 --- a/conformance/tests/generics_defaults.py +++ b/conformance/tests/generics_defaults.py @@ -41,12 +41,8 @@ class OneDefault(Generic[T, DefaultBoolT]): ... class AllTheDefaults(Generic[T1, T2, DefaultStrT, DefaultIntT, DefaultBoolT]): ... -def needs_allthedefaults_or_subclass(x: type[AllTheDefaults[Any, Any, str, int, bool]]) -> None: ... - -# do not use `assert_type` here: some type checkers infer a more precise type -# than `type[]` for class objects -needs_allthedefaults_or_subclass(AllTheDefaults) # OK +assert_type(AllTheDefaults, type[AllTheDefaults[Any, Any, str, int, bool]]) assert_type( AllTheDefaults[int, complex], type[AllTheDefaults[int, complex, str, int, bool]] ) @@ -95,12 +91,7 @@ class Class_ParamSpec(Generic[DefaultP]): ... class Class_TypeVarTuple(Generic[*DefaultTs]): ... -def needs_classtypevartuple_or_subclass(x: type[Class_TypeVarTuple[Any, Any]]) -> None: ... - -# do not use `assert_type` here: some type checkers infer a more precise type -# than `type[]` for class objects -needs_classtypevartuple_or_subclass(Class_TypeVarTuple) # OK - +assert_type(Class_TypeVarTuple, type[Class_TypeVarTuple[*tuple[str, int]]]) assert_type(Class_TypeVarTuple(), Class_TypeVarTuple[str, int]) assert_type(Class_TypeVarTuple[int, bool](), Class_TypeVarTuple[int, bool]) diff --git a/conformance/tests/generics_defaults_referential.py b/conformance/tests/generics_defaults_referential.py index 4db66a36..a033d9c5 100644 --- a/conformance/tests/generics_defaults_referential.py +++ b/conformance/tests/generics_defaults_referential.py @@ -91,13 +91,7 @@ class Bar(Generic[Z1, ListDefaultT]): # OK def __init__(self, x: Z1, y: ListDefaultT): ... -def requires_bar_or_subclass(x: type[Bar[Any, list[Any]]]) -> None: ... - -# Don't use `assert_type(Bar, type[Bar[Any, list[Any]]])` here, -# since some type checkers infer a more precise type than `type[]` for -# class objects -requires_bar_or_subclass(Bar) # OK - +assert_type(Bar, type[Bar[Any, list[Any]]]) assert_type(Bar[int], type[Bar[int, list[int]]]) assert_type(Bar[int](0, []), Bar[int, list[int]]) assert_type(Bar[int, list[str]](0, []), Bar[int, list[str]]) diff --git a/conformance/tests/generics_syntax_scoping.py b/conformance/tests/generics_syntax_scoping.py index 3306d397..768d8fda 100644 --- a/conformance/tests/generics_syntax_scoping.py +++ b/conformance/tests/generics_syntax_scoping.py @@ -4,7 +4,7 @@ # Specification: https://peps.python.org/pep-0695/#type-parameter-scopes -from typing import Callable, Mapping, Literal, Sequence, TypeVar, assert_type +from typing import Callable, Mapping, Sequence, TypeVar, assert_type # > A compiler error or runtime exception is generated if the definition # > of an earlier type parameter references a later type parameter even From 88bf117f81f55cfd48c7354f950b27fb9c8e0b89 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 21:16:34 +0000 Subject: [PATCH 4/6] Apply suggestion from @rchen152 Co-authored-by: Rebecca Chen --- conformance/tests/generics_scoping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conformance/tests/generics_scoping.py b/conformance/tests/generics_scoping.py index 7003db34..06770ddd 100644 --- a/conformance/tests/generics_scoping.py +++ b/conformance/tests/generics_scoping.py @@ -16,8 +16,8 @@ def fun_2(x: T) -> T: # and here could be different assert_type(fun_1(1), Literal[1]) # E[fun1-int] # One of these two should pass; either is acceptable: -assert_type(fun_1("a"), str) # E[fun1-str] -assert_type(fun_1("a"), Literal["a"]) # E[fun1-str] +assert_type(fun_2("a"), str) # E[fun1-str] +assert_type(fun_2("a"), Literal["a"]) # E[fun1-str] # > A type variable used in a method of a generic class that coincides # > with one of the variables that parameterize this class is always bound From 9955ae1263a13bdba2eb0aa0ba0cb35ea229d77e Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 21:20:59 +0000 Subject: [PATCH 5/6] Mark Zuban as partially conformant with `generics_scoping.toml` --- conformance/results/results.html | 2 +- conformance/results/zuban/generics_scoping.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conformance/results/results.html b/conformance/results/results.html index 05d8cbd1..f5006fbc 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -307,7 +307,7 @@

Python Type System Conformance Test Results

     generics_scoping Pass Pass -Unknown +Partial
Partial

Does not implement several scoping checks/restrictions for generics

     generics_self_advanced diff --git a/conformance/results/zuban/generics_scoping.toml b/conformance/results/zuban/generics_scoping.toml index 9db5b66f..28fbbb40 100644 --- a/conformance/results/zuban/generics_scoping.toml +++ b/conformance/results/zuban/generics_scoping.toml @@ -1,4 +1,5 @@ conformance_automated = "Fail" +conformant = "Partial" errors_diff = """ Lines 15, 16: Expected error (tag 'fun1-int') Lines 19, 20: Expected error (tag 'fun1-str') From d59f13235bb7297b02da130b1e4cd2e0d7a7f9df Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 16 Feb 2026 21:25:50 +0000 Subject: [PATCH 6/6] rename tag --- conformance/results/zuban/generics_scoping.toml | 4 ++-- conformance/tests/generics_scoping.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conformance/results/zuban/generics_scoping.toml b/conformance/results/zuban/generics_scoping.toml index 28fbbb40..7c937b14 100644 --- a/conformance/results/zuban/generics_scoping.toml +++ b/conformance/results/zuban/generics_scoping.toml @@ -1,8 +1,8 @@ conformance_automated = "Fail" conformant = "Partial" errors_diff = """ -Lines 15, 16: Expected error (tag 'fun1-int') -Lines 19, 20: Expected error (tag 'fun1-str') +Lines 15, 16: Expected error (tag 'fun1') +Lines 19, 20: Expected error (tag 'fun2') Lines 49, 50: Expected error (tag 'method-str') Lines 53, 54: Expected error (tag 'method-bytes') """ diff --git a/conformance/tests/generics_scoping.py b/conformance/tests/generics_scoping.py index 06770ddd..56a8795a 100644 --- a/conformance/tests/generics_scoping.py +++ b/conformance/tests/generics_scoping.py @@ -12,12 +12,12 @@ def fun_2(x: T) -> T: # and here could be different return x # One of these two should pass; either is acceptable: -assert_type(fun_1(1), int) # E[fun1-int] -assert_type(fun_1(1), Literal[1]) # E[fun1-int] +assert_type(fun_1(1), int) # E[fun1] +assert_type(fun_1(1), Literal[1]) # E[fun1] # One of these two should pass; either is acceptable: -assert_type(fun_2("a"), str) # E[fun1-str] -assert_type(fun_2("a"), Literal["a"]) # E[fun1-str] +assert_type(fun_2("a"), str) # E[fun2] +assert_type(fun_2("a"), Literal["a"]) # E[fun2] # > A type variable used in a method of a generic class that coincides # > with one of the variables that parameterize this class is always bound