Skip to content

Commit a444aab

Browse files
committed
Fixed PEP-8 discrepancy in Prototype pattern
1 parent 557677b commit a444aab

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

prototype.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
from copy import deepcopy
1+
import copy
22

33

44
class Prototype:
55
def __init__(self):
6-
self._objs = {}
6+
self._objects = {}
77

8-
def registerObject(self, name, obj):
9-
"""
10-
register an object.
11-
"""
12-
self._objs[name] = obj
8+
def register_object(self, name, obj):
9+
"""Register an object"""
10+
self._objects[name] = obj
1311

14-
def unregisterObject(self, name):
15-
"""unregister an object"""
16-
del self._objs[name]
12+
def unregister_object(self, name):
13+
"""Unregister an object"""
14+
del self._objects[name]
1715

1816
def clone(self, name, **attr):
19-
"""clone a registered object and add/replace attr"""
20-
obj = deepcopy(self._objs[name])
17+
"""Clone a registered object and update inner attributes dictionary"""
18+
obj = copy.deepcopy(self._objects.get(name))
2119
obj.__dict__.update(attr)
2220
return obj
2321

2422

25-
if __name__ == '__main__':
23+
def main():
2624
class A:
27-
pass
25+
pass
2826

2927
a = A()
3028
prototype = Prototype()
31-
prototype.registerObject("a", a)
32-
b = prototype.clone("a", a=1, b=2, c=3)
29+
prototype.register_object('a', a)
30+
b = prototype.clone('a', a=1, b=2, c=3)
3331

3432
print(a)
3533
print(b.a, b.b, b.c)
34+
35+
36+
if __name__ == '__main__':
37+
main()

0 commit comments

Comments
 (0)