-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Methods of a variadic generic class become uncallable when specified with TypeVarTuple and a suffix #10845
Description
When a variadic generic class is indexed with an unpacked TypeVarTuple followed by some suffix, any methods of that class which unpack the variadic generic fail to typecheck regardless of what arguments you pass in. It seems that the variadic args somehow swallow up all following arguments, making it impossible to pass in arguments corresponding to the suffix types.
In the following example, the call to foo.foo is expected to typecheck. However, it instead throws a cryptic error which is unable to be resolved with any set of arguments.
class Foo[*Ts]:
def foo(self, *args: *Ts):
...
def bar[*Ts, X](foo: Foo[*Ts, X], x: X, *args: *Ts):
foo.foo(*args, x) # error: Argument missing for parameter "__p2" (reportCallIssue)Here are some similar constructs which do not trigger this error:
class Foo[*Ts]:
def foo(self, *args: *Ts):
...
# swapping order of generic parameters to Foo
def bar[*Ts, X](foo: Foo[X, *Ts], x: X, *args: *Ts):
foo.foo(x, *args) # okfrom typing import Callable
# using a callable directly
def bar[*Ts, X](foo: Callable[[*Ts, X], None], x: X, *args: *Ts):
foo(*args, x) # okfrom typing import Callable
# using an attribute which returns a function instead of a method definition
class Foo[*Ts]:
def __init__(self, foo: Callable[[*Ts], None]):
self.foo = foo
def bar[*Ts, X](foo: Foo[*Ts, X], x: X, *args: *Ts):
foo.foo(*args, x) # okDespite the last non-example, it seems the mere presence of a method declaraton causes the error to reappear, even though the revealed type of foo.foo doesn't change.
from typing import Callable
class Foo[*Ts]:
def __init__(self, foo: Callable[[*Ts], None]):
self.foo = foo # ok
def foo(self, *args: *Ts):
...
def bar[*Ts, X](foo: Foo[*Ts, X], x: X, *args: *Ts):
reveal_type(foo.foo) # Type of "foo.foo" is "(*Ts@bar, X@bar) -> None"
foo.foo(*args, x) # Argument missing for parameter "__p2"This issue occurs with:
- Command-line version 1.1.404
- VS Code Pylance extension release version 2025.7.1
- VS Code Pylance extension pre-release version 2025.7.102
- This Pyright Playground