pyopenapi/pyswagger

Deepcopy over primitives._model.Model fails.

wuhaochen opened this issue · 0 comments

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.