Skip to content

Understanding __deepcopy__Β #54

@carlos-jenkins

Description

@carlos-jenkins

In section "Copying":

http://www.rafekettler.com/magicmethods.html#copying

Says:

When you want to deep copy an individual attribute, call copy.deepcopy() on that attribute with memodict as the first argument.

Official documentation for Python 3 says:

https://docs.python.org/2/library/copy.html#copy.deepcopy

If the deepcopy() implementation needs to make a deep copy of a component, it should call the deepcopy() function with the component as first argument and the memo dictionary as second argument.

So:

  1. It should be nice that the wording "first", "second", etc, match. It was a little bit confusing for me.
  2. At least as the way I do understand it, memodict doesn't seem to work as documented:
>>> memodict = {}
>>> data = {'a': [1,2,3]}
>>> from copy import deepcopy
>>> deepcopy(data, memodict=memodict)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: deepcopy() got an unexpected keyword argument 'memodict'

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions