Skip to content

Deepcopy over primitives._model.Model fails. #166

Open
@wuhaochen

Description

@wuhaochen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions