Implement copy magic methods on Model

- Add Model.__copy__
- Add Model.__deepcopy__
This commit is contained in:
Alex Turek 2016-06-25 10:44:52 -07:00 committed by Brian Waldon
parent 59c79b8c21
commit 9d89de02df
1 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from . import exceptions
class Model(dict):
def __init__(self, *args, **kwargs):
# we overload setattr so set this manually
d = dict(*args, **kwargs)
@ -91,6 +92,12 @@ class Model(dict):
def copy(self):
return copy.deepcopy(dict(self))
def __copy__(self):
return self.copy()
def __deepcopy__(self, memo):
return copy.deepcopy(dict(self), memo)
def update(self, other):
mutation = dict(self.items())
mutation.update(other)