Skip to content

Overload resolution fails for Type[T] and metaclass #3452

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

Closed
LiraNuna opened this issue May 26, 2017 · 3 comments
Closed

Overload resolution fails for Type[T] and metaclass #3452

LiraNuna opened this issue May 26, 2017 · 3 comments
Labels
bug mypy got something wrong priority-1-normal

Comments

@LiraNuna
Copy link

LiraNuna commented May 26, 2017

Given this code:

from typing import Iterable, Iterator, List, Type

class EM(type, Iterable[int]):
    def __iter__(self) -> Iterator[int]:
        return iter(range(5))

class E(metaclass=EM):
    pass

def passes_typecheck(e: EM) -> List[int]:
    return list(e)

def fails_typecheck(e: Type[E]) -> List[int]:
    return list(e)

print(passes_typecheck(E))
print(fails_typecheck(E))

mypy fails type checking for the fails_typecheck call with the following error:

bug.py:14: error: No overload variant of "list" matches argument types [Type[bug.E]]

Given that metaclasses are sometimes an implementation detail, I think this should be supported, however this could just be ignorance on my part.

@JukkaL
Copy link
Collaborator

JukkaL commented May 26, 2017

This looks like a bug.

#3326 is related but probably a separate issue.

@JukkaL JukkaL added bug mypy got something wrong priority-1-normal labels May 26, 2017
@elazarg
Copy link
Contributor

elazarg commented Jun 4, 2017

This is a problem in the treatment of overload resolution.

@elazarg
Copy link
Contributor

elazarg commented Jun 8, 2017

I suggest changing the title of the bug to something like Overload resolution fails for Type[T] and metaclass.

@LiraNuna LiraNuna changed the title Type[T] does not seem to support metaclasses Overload resolution fails for Type[T] and metaclass Jun 8, 2017
JukkaL pushed a commit that referenced this issue Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

No branches or pull requests

3 participants