Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Zac-HD opened this issue Mar 16, 2019 · 2 comments

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Mar 16, 2019

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.

@JelleZijlstra
Copy link
Member

This is a duplicate of #3737, which has a simpler example.

@ilevkivskyi
Copy link
Member

Note that supporting this would require lower bounds for type variables (currently mypy supports only upper bounds). For None it may sound silly, but technically it is still needed. Current workaround is to use overloads, see the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants