1 from copy import deepcopy
2 from types import MethodType
3
4
6 """
7 Prototype design pattern abstract class.
8
9 - External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Creational-Pattern-Usage}
10 - External Prototype Pattern documentation: U{https://en.wikipedia.org/wiki/Prototype_pattern}
11 """
13 """
14 Copy the prototype this object and optionally update attributes.
15
16 @param attributes: Keyword arguments of any attributes you wish to update.
17 @return: A copy of this object with the updated attributes.
18 """
19 obj = deepcopy(self)
20 for attribute in attributes:
21 if callable(attributes[attribute]):
22 setattr(obj, attribute, MethodType(attributes[attribute], obj))
23 else:
24 setattr(obj, attribute, attributes[attribute])
25
26 return obj
27