diff --git a/conformance/results/mypy/generics_paramspec_semantics.toml b/conformance/results/mypy/generics_paramspec_semantics.toml index 7dc429c7..009dbbf1 100644 --- a/conformance/results/mypy/generics_paramspec_semantics.toml +++ b/conformance/results/mypy/generics_paramspec_semantics.toml @@ -1,4 +1,5 @@ -conformant = "Pass" +conformant = "Partial" +notes = "parameter specification variance not supported" output = """ generics_paramspec_semantics.py:26: error: Unexpected keyword argument "a" [call-arg] generics_paramspec_semantics.py:26: error: Unexpected keyword argument "b" [call-arg] @@ -11,7 +12,25 @@ generics_paramspec_semantics.py:127: error: Argument 1 to "expects_int_first" ha generics_paramspec_semantics.py:127: note: This is likely because "one" has named arguments: "x". Consider marking them positional-only generics_paramspec_semantics.py:132: error: Argument 1 to "expects_int_first" has incompatible type "def two(*, x: int) -> int"; expected "def (int, /, *, x: int) -> int" [arg-type] generics_paramspec_semantics.py:137: error: Argument 1 to "expects_int_first" has incompatible type "def three(**kwargs: int) -> int"; expected "def (int, /, **kwargs: int) -> int" [arg-type] +generics_paramspec_semantics.py:151: error: Incompatible types in assignment (expression has type "ContravariantParamSpec[[int]]", variable has type "ContravariantParamSpec[[object]]") [assignment] +generics_paramspec_semantics.py:155: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment] +generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc] +generics_paramspec_semantics.py:165: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:169: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment] +generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc] +generics_paramspec_semantics.py:175: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment] """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 159: Expected 1 errors +Line 174: Expected 1 errors +Line 179: Expected 1 errors +Line 155: Unexpected errors ['generics_paramspec_semantics.py:155: error: Missing return statement [empty-body]'] +Line 158: Unexpected errors ['generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]'] +Line 161: Unexpected errors ['generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]'] +Line 171: Unexpected errors ['generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]'] +Line 175: Unexpected errors ['generics_paramspec_semantics.py:175: error: Missing return statement [empty-body]'] +Line 178: Unexpected errors ['generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]'] """ diff --git a/conformance/results/pyrefly/generics_paramspec_semantics.toml b/conformance/results/pyrefly/generics_paramspec_semantics.toml index a62bb475..9ed0bac3 100644 --- a/conformance/results/pyrefly/generics_paramspec_semantics.toml +++ b/conformance/results/pyrefly/generics_paramspec_semantics.toml @@ -1,6 +1,15 @@ -conformant = "Pass" -conformance_automated = "Pass" +conformant = "Partial" +notes = "parameter specification variance not supported" +conformance_automated = "Fail" errors_diff = """ +Line 151: Expected 1 errors +Line 165: Expected 1 errors +Line 174: Expected 1 errors +Line 150: Unexpected errors ['`ContravariantParamSpec[[object]]` is not assignable to `ContravariantParamSpec[[int]]` [bad-assignment]'] +Line 161: Unexpected errors ['Unexpected keyword argument `contravariant` to ParamSpec [invalid-param-spec]'] +Line 168: Unexpected errors ['`ContravariantParamSpecOld[[object]]` is not assignable to `ContravariantParamSpecOld[[int]]` [bad-assignment]'] +Line 171: Unexpected errors ['Unexpected keyword argument `covariant` to ParamSpec [invalid-param-spec]'] +Line 178: Unexpected errors ['`ContravariantParamSpecOld[[int]]` is not assignable to `ContravariantParamSpecOld[[object]]` [bad-assignment]'] """ output = """ ERROR generics_paramspec_semantics.py:26:4-5: Expected argument `a` to be positional [unexpected-keyword] @@ -14,4 +23,12 @@ ERROR generics_paramspec_semantics.py:120:4-5: Argument `Literal[1]` is not assi ERROR generics_paramspec_semantics.py:127:1-19: Argument `(x: str) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type] ERROR generics_paramspec_semantics.py:132:1-19: Argument `(*, x: int) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type] ERROR generics_paramspec_semantics.py:137:1-19: Argument `(**kwargs: int) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type] +ERROR generics_paramspec_semantics.py:150:39-45: `ContravariantParamSpec[[object]]` is not assignable to `ContravariantParamSpec[[int]]` [bad-assignment] +ERROR generics_paramspec_semantics.py:159:11-18: `CovariantParamSpec[[object]]` is not assignable to variable `out_int` with type `CovariantParamSpec[[int]]` [bad-assignment] +ERROR generics_paramspec_semantics.py:161:24-42: Unexpected keyword argument `contravariant` to ParamSpec [invalid-param-spec] +ERROR generics_paramspec_semantics.py:168:46-56: `ContravariantParamSpecOld[[object]]` is not assignable to `ContravariantParamSpecOld[[int]]` [bad-assignment] +ERROR generics_paramspec_semantics.py:169:14-24: `ContravariantParamSpecOld[[int]]` is not assignable to variable `in_obj_old` with type `ContravariantParamSpecOld[[object]]` [bad-assignment] +ERROR generics_paramspec_semantics.py:171:26-40: Unexpected keyword argument `covariant` to ParamSpec [invalid-param-spec] +ERROR generics_paramspec_semantics.py:178:50-61: `ContravariantParamSpecOld[[int]]` is not assignable to `ContravariantParamSpecOld[[object]]` [bad-assignment] +ERROR generics_paramspec_semantics.py:179:15-26: `ContravariantParamSpecOld[[object]]` is not assignable to variable `out_int_old` with type `ContravariantParamSpecOld[[int]]` [bad-assignment] """ diff --git a/conformance/results/pyright/generics_paramspec_semantics.toml b/conformance/results/pyright/generics_paramspec_semantics.toml index e24a0a9c..c04baa0b 100644 --- a/conformance/results/pyright/generics_paramspec_semantics.toml +++ b/conformance/results/pyright/generics_paramspec_semantics.toml @@ -1,6 +1,7 @@ -conformant = "Pass" +conformant = "Partial" notes = """ Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed). +parameter specification variance not supported """ output = """ generics_paramspec_semantics.py:26:6 - error: Expected 2 more positional arguments (reportCallIssue) @@ -30,7 +31,41 @@ generics_paramspec_semantics.py:132:2 - error: Argument of type "(*, x: int) -> generics_paramspec_semantics.py:137:2 - error: Argument of type "(**kwargs: int) -> int" cannot be assigned to parameter "x" of type "(int, **P@expects_int_first) -> int" in function "expects_int_first"   Type "(**kwargs: int) -> int" is not assignable to type "(int, **P@expects_int_first) -> int"     Function accepts too many positional parameters; expected 0 but received 1 (reportArgumentType) +generics_paramspec_semantics.py:150:39 - error: Type "ContravariantParamSpec[(object)]" is not assignable to declared type "ContravariantParamSpec[(int)]" +  "ContravariantParamSpec[(object)]" is not assignable to "ContravariantParamSpec[(int)]" +    Type parameter "InP@ContravariantParamSpec" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType) +generics_paramspec_semantics.py:151:10 - error: Type "ContravariantParamSpec[(int)]" is not assignable to declared type "ContravariantParamSpec[(object)]" +  "ContravariantParamSpec[(int)]" is not assignable to "ContravariantParamSpec[(object)]" +    Type parameter "InP@ContravariantParamSpec" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType) +generics_paramspec_semantics.py:158:39 - error: Type "CovariantParamSpec[(int)]" is not assignable to declared type "CovariantParamSpec[(object)]" +  "CovariantParamSpec[(int)]" is not assignable to "CovariantParamSpec[(object)]" +    Type parameter "OutP@CovariantParamSpec" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType) +generics_paramspec_semantics.py:159:11 - error: Type "CovariantParamSpec[(object)]" is not assignable to declared type "CovariantParamSpec[(int)]" +  "CovariantParamSpec[(object)]" is not assignable to "CovariantParamSpec[(int)]" +    Type parameter "OutP@CovariantParamSpec" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType) +generics_paramspec_semantics.py:161:24 - error: "contravariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues) +generics_paramspec_semantics.py:168:46 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]" +  "ContravariantParamSpecOld[(object)]" is not assignable to "ContravariantParamSpecOld[(int)]" +    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType) +generics_paramspec_semantics.py:169:14 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]" +  "ContravariantParamSpecOld[(int)]" is not assignable to "ContravariantParamSpecOld[(object)]" +    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType) +generics_paramspec_semantics.py:171:26 - error: "covariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues) +generics_paramspec_semantics.py:178:50 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]" +  "ContravariantParamSpecOld[(int)]" is not assignable to "ContravariantParamSpecOld[(object)]" +    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType) +generics_paramspec_semantics.py:179:15 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]" +  "ContravariantParamSpecOld[(object)]" is not assignable to "ContravariantParamSpecOld[(int)]" +    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType) """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 165: Expected 1 errors +Line 174: Expected 1 errors +Line 150: Unexpected errors ['generics_paramspec_semantics.py:150:39 - error: Type "ContravariantParamSpec[(object)]" is not assignable to declared type "ContravariantParamSpec[(int)]"'] +Line 158: Unexpected errors ['generics_paramspec_semantics.py:158:39 - error: Type "CovariantParamSpec[(int)]" is not assignable to declared type "CovariantParamSpec[(object)]"'] +Line 161: Unexpected errors ['generics_paramspec_semantics.py:161:24 - error: "contravariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)'] +Line 168: Unexpected errors ['generics_paramspec_semantics.py:168:46 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]"'] +Line 171: Unexpected errors ['generics_paramspec_semantics.py:171:26 - error: "covariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)'] +Line 178: Unexpected errors ['generics_paramspec_semantics.py:178:50 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]"'] """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 925a525c..2d55aeda 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -322,11 +322,11 @@

Python Type System Conformance Test Results

Partial

Incorrectly allows using `*args: P.args` and `**kwargs: P.kwargs` when `P` has not been put into scope by any other parameter annotation or enclosing scope.

     generics_paramspec_semantics -Pass -
Pass*

Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed).

-Pass -Pass -Pass +
Partial

parameter specification variance not supported

+
Partial

Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed).

parameter specification variance not supported

+
Partial

parameter specification variance not supported

+
Partial

parameter specification variance not supported

+
Partial

parameter specification variance not supported

     generics_paramspec_specialization Pass diff --git a/conformance/results/ty/generics_paramspec_semantics.toml b/conformance/results/ty/generics_paramspec_semantics.toml index 2a84cbc3..a6821ca2 100644 --- a/conformance/results/ty/generics_paramspec_semantics.toml +++ b/conformance/results/ty/generics_paramspec_semantics.toml @@ -1,5 +1,18 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = "parameter specification variance not supported" +conformance_automated = "Fail" errors_diff = """ +Line 151: Expected 1 errors +Line 159: Expected 1 errors +Line 169: Expected 1 errors +Line 179: Expected 1 errors +Line 155: Unexpected errors ['generics_paramspec_semantics.py:155:20: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(**OutP@CovariantParamSpec) -> None`'] +Line 161: Unexpected errors ['generics_paramspec_semantics.py:161:7: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet'] +Line 163: Unexpected errors ['generics_paramspec_semantics.py:163:33: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`'] +Line 164: Unexpected errors ['generics_paramspec_semantics.py:164:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression', 'generics_paramspec_semantics.py:164:47: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression'] +Line 171: Unexpected errors ['generics_paramspec_semantics.py:171:8: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet'] +Line 173: Unexpected errors ['generics_paramspec_semantics.py:173:29: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`'] +Line 175: Unexpected errors ['generics_paramspec_semantics.py:175:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown`', 'generics_paramspec_semantics.py:175:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression', 'generics_paramspec_semantics.py:175:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`'] """ output = """ generics_paramspec_semantics.py:26:4: error[positional-only-parameter-as-kwarg] Positional-only parameter 1 (`a`) passed as keyword argument @@ -13,4 +26,19 @@ generics_paramspec_semantics.py:120:4: error[invalid-argument-type] Argument is generics_paramspec_semantics.py:127:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def one(x: str) -> int` generics_paramspec_semantics.py:132:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def two(*, x: int) -> int` generics_paramspec_semantics.py:137:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def three(**kwargs: int) -> int` +generics_paramspec_semantics.py:155:20: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(**OutP@CovariantParamSpec) -> None` +generics_paramspec_semantics.py:161:7: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet +generics_paramspec_semantics.py:163:33: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic` +generics_paramspec_semantics.py:164:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression +generics_paramspec_semantics.py:164:47: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression +generics_paramspec_semantics.py:165:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown` +generics_paramspec_semantics.py:165:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression +generics_paramspec_semantics.py:165:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...` +generics_paramspec_semantics.py:171:8: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet +generics_paramspec_semantics.py:173:29: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic` +generics_paramspec_semantics.py:174:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression +generics_paramspec_semantics.py:174:48: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression +generics_paramspec_semantics.py:175:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown` +generics_paramspec_semantics.py:175:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression +generics_paramspec_semantics.py:175:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...` """ diff --git a/conformance/results/zuban/generics_paramspec_semantics.toml b/conformance/results/zuban/generics_paramspec_semantics.toml index f6fe67e4..0a37c4c0 100644 --- a/conformance/results/zuban/generics_paramspec_semantics.toml +++ b/conformance/results/zuban/generics_paramspec_semantics.toml @@ -1,5 +1,16 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = "parameter specification variance not supported" +conformance_automated = "Fail" errors_diff = """ +Line 159: Expected 1 errors +Line 174: Expected 1 errors +Line 179: Expected 1 errors +Line 155: Unexpected errors ['generics_paramspec_semantics.py:155: error: Missing return statement [empty-body]'] +Line 158: Unexpected errors ['generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]'] +Line 161: Unexpected errors ['generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]'] +Line 171: Unexpected errors ['generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]'] +Line 175: Unexpected errors ['generics_paramspec_semantics.py:175: error: Missing return statement [empty-body]'] +Line 178: Unexpected errors ['generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]'] """ output = """ generics_paramspec_semantics.py:26: error: Unexpected keyword argument "a" [call-arg] @@ -12,4 +23,13 @@ generics_paramspec_semantics.py:120: error: Argument 1 has incompatible type "in generics_paramspec_semantics.py:127: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" [arg-type] generics_paramspec_semantics.py:132: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, Never], int]" [arg-type] generics_paramspec_semantics.py:137: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[KwArg(int)], int]"; expected "Callable[[int, Never], int]" [arg-type] +generics_paramspec_semantics.py:151: error: Incompatible types in assignment (expression has type "ContravariantParamSpec[[int]]", variable has type "ContravariantParamSpec[[object]]") [assignment] +generics_paramspec_semantics.py:155: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment] +generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc] +generics_paramspec_semantics.py:165: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:169: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment] +generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc] +generics_paramspec_semantics.py:175: error: Missing return statement [empty-body] +generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment] """ diff --git a/conformance/tests/generics_paramspec_semantics.py b/conformance/tests/generics_paramspec_semantics.py index 836d461d..4f0bba51 100644 --- a/conformance/tests/generics_paramspec_semantics.py +++ b/conformance/tests/generics_paramspec_semantics.py @@ -142,3 +142,38 @@ def three(**kwargs: int) -> int: @expects_int_first # OK def four(*args: int) -> int: raise NotImplementedError + +class ContravariantParamSpec[**InP]: + def f(self, *args: InP.args, **kwargs: InP.kwargs): ... + +in_obj: ContravariantParamSpec[object] = ContravariantParamSpec() +in_int: ContravariantParamSpec[int] = in_obj # OK +in_obj = in_int # E + + +class CovariantParamSpec[**OutP]: + def f(self) -> Callable[OutP, None]: ... + +out_int: CovariantParamSpec[int] = CovariantParamSpec() +out_obj: CovariantParamSpec[object] = out_int # OK +out_int = out_obj # E + +InP = ParamSpec("InP", contravariant=True) + +class ContravariantParamSpecOld(Generic[InP]): + def in_f(self, *args: InP.args, **kwargs: InP.kwargs): ... # OK + def out_f(self) -> Callable[InP, None]: ... # E + +in_obj_old: ContravariantParamSpecOld[object] = ContravariantParamSpecOld() +in_int_old: ContravariantParamSpecOld[int] = in_obj_old # OK +in_obj_old = in_int_old # E + +OutP = ParamSpec("OutP", covariant=True) + +class CovariantParamSpecOld(Generic[OutP]): + def in_f(self, *args: OutP.args, **kwargs: OutP.kwargs): ... # E + def out_f(self) -> Callable[OutP, None]: ... # OK + +out_int_old: ContravariantParamSpecOld[int] = ContravariantParamSpecOld() +out_obj_old: ContravariantParamSpecOld[object] = out_int_old # OK +out_int_old = out_obj_old # E diff --git a/docs/spec/generics.rst b/docs/spec/generics.rst index ff1396a2..e52a281e 100644 --- a/docs/spec/generics.rst +++ b/docs/spec/generics.rst @@ -2729,13 +2729,12 @@ The algorithm for computing the variance of a type parameter is as follows. For each type parameter in a generic class: -1. If the type parameter is variadic (``TypeVarTuple``) or a parameter -specification (``ParamSpec``), it is always considered invariant. No further -inference is needed. +1. If the type parameter is variadic (``TypeVarTuple``) it is always +considered invariant. No further inference is needed. -2. If the type parameter comes from a traditional ``TypeVar`` declaration and -is not specified as ``infer_variance`` (see below), its variance is specified -by the ``TypeVar`` constructor call. No further inference is needed. +2. If the type parameter comes from a traditional ``TypeVar``/``ParamSpec`` +declaration and is not specified as ``infer_variance`` (see below), its +variance is specified by the constructor call. No further inference is needed. 3. Create two specialized versions of the class. We'll refer to these as ``upper`` and ``lower`` specializations. In both of these specializations,