Closed
Description
Consider this .pyi
code snippet:
from typing import Any, Generic, Self, TypeVar, TypeVarTuple, type_check_only
T = TypeVar("T")
Ts = TypeVarTuple("Ts")
@type_check_only
class S(tuple[*Ts], Generic[T, *Ts]):
def f(self, x: T, /) -> T: ...
When ran through mypy
(checked with 1.15.0
and the master branch), the following error is reported
Argument 1 to "type_check_only" has incompatible type "type[S[T, *Ts]]"; expected "type[S[T, *Ts]]" [arg-type]
Without the additional T
type parameter, the false positive error disappears. It also disappears if I remove the tuple
baseclass.
And as far as I could tell, it doesn't seem to be associated with a particular config option or cli flag.
Activity
[-]Argument 1 to "type_check_only" has incompatible type "type[S[T, *Ts]]"; expected "type[S[T, *Ts]]"[/-][+]Argument 1 to `type_check_only` has incompatible type `type[S[T, *Ts]]`; expected `type[S[T, *Ts]]`[/+]sterliakov commentedon May 17, 2025
Amazing.
mypy
does not supporttype_check_only
at all, but this bug is rather surprising - we must be doing something deeply wrong.Here's a pdb session following quick debugging:
Hm, so the type is not a subtype of itself. I suspect fixing this
is_subtype
behaviour may incidentally close a couple more typevartuple issues.Merge branch 'master' into bugfix/pythongh-19093-infer-constraints-in…
Include tuple fallback in constraints built from tuple types (#19100)