Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- class A(ABC):
- def __init__(self):
- self.a = 0
- pass
- @abstractmethod
- def hello(self):
- pass
- @classmethod
- def __subclasshook__(cls, K):
- if K is tuple:
- return True
- return NotImplemented
- class B(A):
- def __init__(self):
- super().__init__()
- def hello(self):
- print('B hello')
- class C(B):
- def __init__(self):
- super().__init__()
- def hello(self):
- print('C hello')
- def chk(self):
- for c in C.__mro__:
- print(c)
- def __getitem__(self, item):
- if item >= 3:
- raise IndexError('index out of range: {}'.format(item))
- return item
- def __len__(self):
- return 3
- def main():
- t = 1, 2, 3
- c = C()
- c.hello()
- c.chk()
- # these are ok
- print(isinstance(c, A))
- print(isinstance(c, B))
- print(isinstance(c, C))
- # what's the use??
- print(issubclass(tuple, A))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement