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

Specific output type of default function argument incompatible with generic output #5273

Closed
Strilanc opened this issue Jun 25, 2018 · 2 comments

Comments

@Strilanc
Copy link

Strilanc commented Jun 25, 2018

mypy believes that a function with a specific output type can not be used as the default value for a method expecting a function with a generic output type. It interprets the difference as a problem instead of as a constraint.

Repro code

T = TypeVar('T')

def make_zero() -> int:
    return 0

def produce_many(amount: int,
                 producer: Callable[[], T] = make_zero) -> Tuple[T, ...]:
    return tuple(producer() for _ in range(amount))

Expected output

No type error. When the default value for producer is used, the type variable T is inferred to be int.

Actual output

Incompatible default for argument "producer" (default has type "Callable[[], int]", argument has type "Callable[[], T]")
@gvanrossum
Copy link
Member

gvanrossum commented Jun 25, 2018 via email

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Jun 25, 2018

This is a duplicate of #3737

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