-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (34 loc) · 822 Bytes
/
Copy pathmain.py
File metadata and controls
45 lines (34 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class BaseView:
def handle(self):
return ["base"]
class AuthMixin(BaseView):
def handle(self):
return ["auth"] + super().handle()
class CacheMixin(BaseView):
def handle(self):
return ["cache"] + super().handle()
class ReportView(AuthMixin, CacheMixin):
def handle(self):
return ["report"] + super().handle()
print(ReportView().handle())
# Understand the Inheritance Structure
# BaseView
# ↑
# AuthMixin
# ↑
# ReportView
# and also
# BaseView
# ↑
# CacheMixin
# ↑
# ReportView
# So the inheritance is diamond-shaped:
# BaseView
# / \
# AuthMixin CacheMixin
# \ /
# ReportView
# Python Computes the MRO (Method Resolution Order)
print(ReportView.__mro__)
#(ReportView, AuthMixin, CacheMixin, BaseView, object)