Skip to content

mypy silent about incorrect metaclasses-based protocol  #4272

Open
@elazarg

Description

@elazarg
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).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions