Skip to content

Instantly share code, notes, and snippets.

@Spindel
Created May 6, 2020 18:54
Show Gist options
  • Save Spindel/9d5791f0f053f52009e0b50d68c752eb to your computer and use it in GitHub Desktop.
Save Spindel/9d5791f0f053f52009e0b50d68c752eb to your computer and use it in GitHub Desktop.
Mypy complains
import abc
import typing
import dataclasses
from functools import singledispatchmethod
@dataclasses.dataclass
class Root:
pass
@dataclasses.dataclass
class Child(Root):
name: str
@dataclasses.dataclass
class Parent(Child):
family: int
class Interface(metaclass=abc.ABCMeta):
@abc.abstractmethod
def handle(self, thing: Root) -> None:
raise NotImplementedError
class Implementer(Interface):
@singledispatchmethod
def handle(self, thing: Root) -> None:
raise ValueError
@singledispatchmethod
def _handle_child(self, thing: Child) -> None:
print("ok", thing)
@singledispatchmethod
def _handle_parent(self, thing: Parent) -> None:
print("ok", thing)
mypy mytest.py
mytest.py:32: error: Signature of "handle" incompatible with supertype "Interface"
Found 1 error in 1 file (checked 1 source file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment