GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Empty variadic `tuple` subtype not assignable to `tuple[int, ...]` · Issue #19110 · python/mypy

Empty variadic tuple subtype not assignable to tuple[int, ...] #19110

New issue
Copy link
New issue
Copy link
Closed
#21518
Closed
Empty variadic tuple subtype not assignable to tuple[int, ...]#19110
#21518
Copy link
Labels
bugmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

Description

@jorenham
jorenham
opened on May 18, 2025
Issue body actions
class Shape[*Ts](tuple[*Ts]): ...
class Shape0(Shape[()]): ...
class Shape1(Shape[int]): ...

def rank(shape: tuple[int, ...]) -> int:
    return len(shape)

_ = rank(Shape())       # ✅
_ = rank(())            # ✅
_ = rank(Shape0())      # ❌  Argument 1 to "rank" has incompatible type "Shape0"; expected "tuple[int, ...]"
_ = rank(Shape1([1]))   # ✅

playground

Perhaps this is related to #19105, which also involves empty tuple subtypes.

Activity

  1. jorenham
    added
    bugmypy got something wrong
    on May 18, 2025
  2. jorenham commented on May 18, 2025

    @jorenham
    jorenham
    on May 18, 2025
    ContributorAuthor
    More actions

    I confirmed that #19100 does not solve this

  3. jorenham commented on May 19, 2025

    @jorenham
    jorenham
    on May 19, 2025
    ContributorAuthor
    More actions

    I'm guessing that it's a consequence of this issue, but it might be worth noting that these variadic tuple subtypes ignore the constraints of typevars:

    class Shape[*Ts](tuple[*Ts]): ...
    
    class Shape0(Shape[()]): ...
    class Shape1(Shape[int]): ...
    class ShapeN(Shape[*tuple[int, ...]]): ...
    
    
    def upcast[T: (tuple[()], tuple[int], tuple[int, ...])](shape: T) -> T:
        return shape
    
    reveal_type(upcast(Shape0()))  # ❌ Shape0
    reveal_type(upcast(Shape1()))  # ✅ tuple[builtins.int]
    reveal_type(upcast(ShapeN()))  # ❌ ShapeN

    full output:

    main.py:11: error: Value of type variable "T" of "upcast" cannot be "Shape0"  [type-var]
    main.py:11: note: Revealed type is "__main__.Shape0"
    main.py:12: note: Revealed type is "tuple[builtins.int]"
    main.py:13: error: Value of type variable "T" of "upcast" cannot be "ShapeN"  [type-var]
    main.py:13: note: Revealed type is "__main__.ShapeN"
    Found 2 errors in 1 file (checked 1 source file)
    

    playground

    For reference, pyright reveals these as tuple[()], tuple[int], tuple[int, ...] (playground).

    Let me know in case I should raise this separately.

  4. sterliakov commented on May 19, 2025

    @sterliakov
    sterliakov
    on May 19, 2025
    Collaborator
    More actions

    Wow, you opened a can of worms with your typevartuple experiments! This is definitely a bug.

    Reacted by Joren Hammudoglu
  5. sterliakov
    added
    topic-pep-646PEP 646 (TypeVarTuple, Unpack)
    on May 19, 2025
  6. ilevkivskyi
    added a commit that references this issue on May 20, 2026

    Fix edge cases in variadic tuple subclasses (#21518)

    9b96cbe
  7. ilevkivskyi
    closed this as completedin #21518on May 20, 2026
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 wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.