Skip to content

Incorrect "incompatible default for argument" when the hint is a generic type with a TypeVar #6556

Closed
@Zac-HD

Description

@Zac-HD

I would expect mypy to understand that (None,) is a valid default for Tuple[T, ...], but instead I get

error: Incompatible default for argument "a"
       (default has type "Tuple[None]", argument has type "Tuple[T, ...]")
from typing import List, Tuple, TypeVar
T = TypeVar("T")  # or covariant, or contravariant

def f(a: Tuple[T, ...] = (None,)) -> List[T]:  # Or Tuple[T], Set[T], etc.
    return list(a)

This was actually found while working on HypothesisWorks/hypothesis#167, where the signature eventually desugars to (Callable[..., T], SearchStrategy[T]) -> SearchStrategy[Callable[..., T]], but the tuple-to-list example here has the same problem and is much easier to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions