Skip to content

Unpack generic tuple with no args not working #19140

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

Open
herobank110 opened this issue May 23, 2025 · 3 comments
Open

Unpack generic tuple with no args not working #19140

herobank110 opened this issue May 23, 2025 · 3 comments
Labels
bug mypy got something wrong

Comments

@herobank110
Copy link

herobank110 commented May 23, 2025

Bug Report

I would like a generic class with TypeVarTuple and connect a callback as parameter to a member function. This works for instances of the object created with one or more type arguments, but fails for no types.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.13&gist=9176cff57ec791ec0bd9d49e17b1e85e

Expected Behavior

Mypy should allow unpacking the TypeVarTuple to a Callable with no arguments.

Actual Behavior

error: Argument 1 to "foo" of "Class" has incompatible type "Callable[[], None]"; expected "Callable[[VarArg(Never)], None]" [arg-type]

Your Environment

mypy playground

  • Mypy version used: 1.15.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13
@herobank110 herobank110 added the bug mypy got something wrong label May 23, 2025
@erictraut
Copy link

erictraut commented May 23, 2025

Your code doesn't type check because you haven't specialized the generic Class in the last line of your code sample. In all previous cases, you've correctly supplied a specialization for the TypeVarTuple.

You can fix this by changing the last line to:

Class[()]().foo(x_no_args)

@herobank110
Copy link
Author

Ah, thanks didn't know that!

Now for a slight variation. Ideally I'd like to supply a default empty tuple and use the generic class without explicit specialization. This seems to work when an object is instantiated and has its type inferred but not for type annotated variables: mypy playground. The intended use case is for annotated class variables that are instantiated in a metaclass.
This appears to work as expected in pyright

Here's the error I got:

error: Invalid self argument "Class[*tuple[*tuple[()], ...]]" to attribute function "foo" with type "Callable[[Class[*Ts], Callable[[VarArg(*Ts)], None]], None]"  [misc]

@jorenham
Copy link
Contributor

This sounds like it could be related to #19110, and maybe also #19105 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants