Prototype python example - clone method

candido.ale 7 months ago updated by Alexander Shvets 7 months ago 0

In the prototype python example the `clone` method of the `Prototype` class performs the following steps:

- assign to the instance `self` copies of the current attributes

- return a new copy of the object

"By chance" `deepcopy` is enough to produce a complete copy of the object, so `p2` is really a copy of `p1`, but:

- the initial attributes of `p1` are discarded, and also `p1` got new copies of them uselessly

- if `deepcopy` were not able to deal with circular references the `prototype` attribute of `p2.circular_reference` would not be updated

If I am right, maybe I'm missing something, the operations are simply done in the wrong order, so firstly the `deepcopy` of `p1` should be generated, then its attributes should be replaced.

Thank you for your wonderful work,