Last active
January 20, 2021 18:07
-
-
Save gdevanla/ee9f0ff13b66a7d2edfa79fede3c7a2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import typing as tp | |
class Abstract: | |
def func1(self, *, x: int, y: str): | |
raise NotImplementedError() | |
class Foo(Abstract): | |
@classmethod | |
def func1(cls, *, x, y): | |
print(x) | |
print(y) | |
class Bar(Abstract): | |
@classmethod | |
def func1(cls, *, x, y): # pylint: disable=unused-argument | |
print(x) | |
def bar1(x: tp.Type[Abstract]): | |
x.func1(10, 20) | |
# alternate implementation | |
class Foo1(: | |
@classmethod | |
def func1(cls, *, x, y): | |
print(x) | |
print(y) | |
class Bar1: | |
@classmethod | |
def func1(cls, *, x): | |
print(x) | |
Abstract1 = tp.Union[tp.Type[Foo1], tp.Type[Bar1]] | |
def bar2(x: Abstract1): | |
if x is Foo: | |
x.func1(10, 20) | |
elif x is Bar: | |
x.func1(10) | |
else: | |
raise ValueError(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment