Skip to content

mypy silent about incorrect metaclasses-based protocol #4272

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

Open
elazarg opened this issue Nov 21, 2017 · 2 comments
Open

mypy silent about incorrect metaclasses-based protocol #4272

elazarg opened this issue Nov 21, 2017 · 2 comments

Comments

@elazarg
Copy link
Contributor

elazarg commented Nov 21, 2017

from typing import TypeVar, Type, Iterable, Iterator
T = TypeVar('T')
class M(type):
    def __iter__(self: Type[T]) -> Iterator[T]: raise Exception
class A(metaclass=M): pass
x: Iterable[A] = A  # fine
y: Iterable[str] = A  # should be rejected, but it is not

This pattern is important for enums, and came up in python/typeshed#1755. @ilevkivskyi noted that this is likely due to a bug in bind_self (see there).

@ilevkivskyi
Copy link
Member

Thanks for opening the issue! It looks like the fix is more complex, since it requires carrying over original_type from subtypes.py.

@elazarg
Copy link
Contributor Author

elazarg commented Nov 21, 2017

In general bind_self is buggy and ad-hoc. But when I tried to do it "right" it feels like it means making a class MemberChecker with all the context carried around by ExpressionChecker and TypeChecker.

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

No branches or pull requests

3 participants