-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrides.py
55 lines (36 loc) · 1.04 KB
/
overrides.py
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
46
47
48
49
50
51
52
53
54
55
'''
Extremely Simple interface to show sharing + overrides
'''
class Base(object):
def __init__(self):
self.attrs = {}
def __str__(self):
return '%s'%self.attrs
def test(self):
return 'foo'
def setAttr(self, key, value):
self.attrs[key] = value
class Derived(Base):
def __init__(self, base):
self.baseattrs = base.attrs
self.attrs = {}
def setAttr(self, key, value):
self.attrs[key] = value
def getAttr(self, key):
if key in self.attrs:
return self.attrs[key]
elif key in self.baseattrs:
return self.baseattrs[key]
return None
def __str__(self):
dictie = dict(self.baseattrs.items() + self.attrs.items())
return '%s'%dictie
if __name__ == '__main__':
root = Base()
root.setAttr('a', 1)
root.setAttr('b', 2)
blah = Derived(root)
blah.setAttr('c',3)
blah.setAttr('a',666)
print blah.test()
print blah