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

Bound TypeVar reported as incompatible with argument defaults #7927

Closed
ambv opened this issue Nov 11, 2019 · 2 comments
Closed

Bound TypeVar reported as incompatible with argument defaults #7927

ambv opened this issue Nov 11, 2019 · 2 comments

Comments

@ambv
Copy link
Contributor

ambv commented Nov 11, 2019

This is probably a herp derp on my part but I can't figure out what's wrong here.

Example:

from typing import *

class C:
    pass

C_T = TypeVar("C_T", bound=C)

def func(factory: Type[C_T] = C) -> C_T:
    return factory()

On the penultimate line Mypy reports:

error: Incompatible default for argument "type" (default has type "Type[C]",
argument has type "Type[C_T]")

I would expect it to be happy about the default.

@TH3CHARLie
Copy link
Collaborator

TH3CHARLie commented Nov 12, 2019

I'm not 100% sure but you may check #7864 on @ilevkivskyi 's clarification about default values.

@ilevkivskyi
Copy link
Member

This is actually a special case that we might want to special-case, see #3737. But yes, the general solution is to use overloads.

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