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 over primitives._model.Model fails. #166

Open
wuhaochen opened this issue Oct 5, 2018 · 0 comments
Open

Deepcopy over primitives._model.Model fails. #166

wuhaochen opened this issue Oct 5, 2018 · 0 comments

Comments

@wuhaochen
Copy link

Example:

import copy
import pyswagger

m = pyswagger.primitives._model.Model()
nm = copy.deepcopy(m) 

Got:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-156-f6bcd0227185> in <module>()
----> 1 nm = deepcopy(m)

/usr/lib64/python2.7/copy.pyc in deepcopy(x, memo, _nil)
    170             y = _deepcopy_atomic(x, memo)
    171         else:
--> 172             copier = getattr(x, "__deepcopy__", None)
    173             if copier:
    174                 y = copier(memo)

KeyError: '__deepcopy__'

This is because of using dict.__getitem__ as __getattr__ in the Model class. On the occasion that an attribute is not found, it throws a KeyError instead of an AttributeError and it's not handled by python's getattr function.

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