Created
February 20, 2020 15:12
-
-
Save ysangkok/3668fc669c0aa8479a932405795fd4d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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