Skip to content

[BUG] Union should expand TypeVarTuple. #1442

Closed

Description

@randolf-scholz
from typing import TypeVarTuple, Union
import random

Ts = TypeVarTuple("Ts")

def random_item(*items: *Ts) -> Union[*Ts]:
    """Chooses a random input"""
    return random.choice(items)

reveal_type(random_item(1, "apple", None))  # should be int | str | None

However, Union[*Ts] simplifies to *Ts which is a typing._UnpackGenericAlias.

Activity

  1. AlexWaygood commented on Aug 5, 2023

    @AlexWaygood
    Member

    Please clarify whether you believe there is a "bug in the specification", a bug in a specific type checker, or a bug in the behaviour at runtime

  2. randolf-scholz commented on Aug 5, 2023

    @randolf-scholz
    ContributorAuthor

    Nevermind, pyright seems to check this with proper configuration. I would suggest appending something like this as example to the TypeVarTuple-PEP.

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

    topic: otherOther topics not covered

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions