diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 51a9dfbb8bc1..fac61bcc27ed 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -885,7 +885,10 @@ def g(x: int) -> int: ... # type variables of L, because generating and solving # constraints for the variables of L to make L a subtype of R # (below) treats type variables on the two sides as independent. - if left.variables: + if left.variables and not any( + isinstance(var, ParamSpecType) + for var in left.variables + ): # Apply generic type variables away in left via type inference. unified = unify_generic_callable(left, right, ignore_return=ignore_return) if unified is None: diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index f6123915aada..f5e2ce6ba033 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -406,3 +406,24 @@ with f() as x: pass [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] + +[case testFinalParamSpec] +# See https://github.com/python/mypy/issues/12033 +from typing import Generic, TypeVar +from typing_extensions import ParamSpec, final + +_P = ParamSpec("_P") +_T = TypeVar("_T") + +@final # Should be ok +class OnlyParamSpec(Generic[_P]): + pass + +@final # Should be ok +class MixedWithTypeVar1(Generic[_P, _T]): + pass + +@final # Should be ok +class MixedWithTypeVar2(Generic[_T, _P]): + pass +[builtins fixtures/dict.pyi]