Closed
Description
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
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
erictraut commentedon 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:
herobank110 commentedon May 24, 2025
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:
jorenham commentedon May 26, 2025
This sounds like it could be related to #19110, and maybe also #19105 🤔
herobank110 commentedon Jun 8, 2025
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