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

Deepcopy not working #73

Closed
guardeivid opened this issue Feb 27, 2019 · 2 comments
Closed

Deepcopy not working #73

guardeivid opened this issue Feb 27, 2019 · 2 comments

Comments

@guardeivid
Copy link

Hi, I tried to use deepcopy and the following error occurs:

from copy import deepcopy
from mappyfile.ordereddict import DefaultOrderedDict

d = DefaultOrderedDict()
d['__type__'] = 'layer'

e = deepcopy(d)
print(e)
Traceback (most recent call last):
  File "C:\OSGeo4W\apps\Python36\lib\code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 18, in <module>
  File "C:\OSGeo4W\apps\Python36\lib\copy.py", line 161, in deepcopy
    y = copier(memo)
  File "C:\OSGeo4W\apps\Python36\lib\site-packages\mappyfile\ordereddict.py", line 61, in __deepcopy__
    copy.deepcopy(self.items()))
  File "C:\OSGeo4W\apps\Python36\lib\copy.py", line 169, in deepcopy
    rv = reductor(4)
TypeError: can't pickle odict_items objects

This is happening in Python >= 3.5

Following the logic maybe it should be like this?

# ordereddict.py

    def __deepcopy__(self, memo):
        return type(self)(self.default_factory, copy.deepcopy(iter(self.items())))
@geographika
Copy link
Owner

@guardeivid - thanks for the report and suggested fix. Should be fixed with the commit - df590b5

I had to use list() rather than iter() or Python2 breaks. Unit test also added. This will be part of the next patch release.

@guardeivid
Copy link
Author

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

2 participants