Skip to content

expand unions of fixed-length tuples in unpacking *args #2734

@carljm

Description

@carljm
from typing import Literal

def f(x: int | None = None, y: str = ""): ...

def _(flag: bool):
    args = () if flag else (1,)
    f(*args)

We error on f(*args) because args is a union of two fixed-length tuple types, so we give up and just treat it as a variable-length homogeneous iterable. (Pyright and pyrefly do the same.) But mypy allows this call. It would require expanding the union and checking the call twice, similar to how we do in overload matching.

Metadata

Metadata

Assignees

Labels

callsIssues relating to call-signature checking and diagnostics

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions