Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes @final and ParamSpec integration #12034

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]