Skip to content

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

Description

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

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