Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding __deepcopy__ #54

Open
carlos-jenkins opened this issue Jul 12, 2016 · 0 comments
Open

Understanding __deepcopy__ #54

carlos-jenkins opened this issue Jul 12, 2016 · 0 comments

Comments

@carlos-jenkins
Copy link

carlos-jenkins commented Jul 12, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant