Skip to content

Unpack generic tuple with no args not working #19140

Closed
@herobank110

Description

@herobank110

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

Activity

erictraut

erictraut commented on May 23, 2025

@erictraut

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

herobank110 commented on May 24, 2025

@herobank110
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

jorenham commented on May 26, 2025

@jorenham
Contributor

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

herobank110

herobank110 commented on Jun 8, 2025

@herobank110
Author

I made a fork and added a test case to investigate it but realized it seems to be working as expected on the latest mypy (1.16 vs 1.15 at time of issue report)

Thanks!
closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jorenham@erictraut@herobank110

        Issue actions

          Unpack generic tuple with no args not working · Issue #19140 · python/mypy