Skip to content

Instantly share code, notes, and snippets.

@ysangkok
Created February 20, 2020 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysangkok/3668fc669c0aa8479a932405795fd4d3 to your computer and use it in GitHub Desktop.
Save ysangkok/3668fc669c0aa8479a932405795fd4d3 to your computer and use it in GitHub Desktop.
from typing import Protocol
class InterfaceAB(Protocol):
def method_a(self) -> None: ...
def method_b(self) -> None: ...
class ClassA:
def method_a(self) -> None:
print("a")
class ClassB:
def method_b(self: InterfaceAB) -> None:
print("b")
self.method_a()
# if I remove ClassA here, I get a type checking error!
class AB(ClassA, ClassB): pass
ab = AB()
ab.method_b()
# % mypy --version
# mypy 0.761
# % mypy mypy-protocol-demo.py
# Success: no issues found in 1 source file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment