Skip to content

TypeVarTuple instantiation with the empty tuple in Generic not being recognized as such #19533

@gflima

Description

@gflima

Bug Report

Mypy does not recognize that a TypeVarTuple was instantiated with the empty tuple in a generic.

To Reproduce

from typing import Generic, reveal_type, TypeVarTuple

Ts = TypeVarTuple('Ts')

class A(Generic[*Ts]):

    def args(self) -> tuple[*Ts]:
        raise NotImplementedError

class B(A[int, *Ts]):
    pass

class C(B[*tuple[()]]):
    pass

reveal_type(A.args)
reveal_type(B.args)
reveal_type(C.args)

Expected Behavior

I'd expect that the return type of C.args be tuple[int]. And this, indeed, is what pyright infers:

test.py:18:13 - information: Type of "A.args" is "(self: A[Unknown]) -> tuple[Unknown]"
test.py:19:13 - information: Type of "B.args" is "(self: B[Unknown]) -> tuple[int, Unknown]"
test.py:20:13 - information: Type of "C.args" is "(self: C) -> tuple[int]"

Actual Behavior

Mypy however infers tuple[int, *tuple[Any, ...]]:

test.py:18: note: Revealed type is "def [Ts] (self: test8.A[Unpack[Ts`1]]) -> tuple[Unpack[Ts`1]]"
test.py:19: note: Revealed type is "def [Ts] (self: test8.A[builtins.int, Unpack[Ts`1]]) -> tuple[builtins.int, Unpack[Ts`1]]"
test.py:20: note: Revealed type is "def (self: test8.A[builtins.int, Unpack[builtins.tuple[Any, ...]]]) -> tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]"

Your Environment

  • Mypy version used: 1.17.0 (compiled: yes)
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy