Skip to content

Function rejects tuple argument when argument type context is a union involving a tuple-bound typevar #21520

@bzoracler

Description

@bzoracler

Bug Report, To Reproduce, and Actual Behaviour

Mypy rejects this example (see the line containing reveal_type(f(b)))

# mypy: disable-error-code=empty-body

type VarTuple[T] = tuple[T, ...]

class MyTuple(tuple[int, str]): ...

def f[T: str | MyTuple](arg: T | VarTuple[T], /) -> T: ...
def f2[T: MyTuple](arg: T | VarTuple[T], /) -> T: ...

b = MyTuple((1, ""))
reveal_type(f(b))  # E: Argument 1 to "f" has incompatible type "MyTuple"; expected "tuple[Never, ...]"  [arg-type] \
                   # N: Revealed type is "Never"
reveal_type(f2(b))  # N: Revealed type is "tuple[int, str, fallback=__main__.MyTuple]"

Expected Behavior

No errors and revealed type for f(b) should be same as for f2(b).

Your Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions