models: Shortcut case where copy didn't change anything
We no longer copy in this case and will just give you the same instance back.
This commit is contained in:
parent
0fee1b4b11
commit
86481b1d50
@ -224,6 +224,8 @@ class ImmutableObject(object):
|
|||||||
:type values: dict
|
:type values: dict
|
||||||
:rtype: new instance of the model being copied
|
:rtype: new instance of the model being copied
|
||||||
"""
|
"""
|
||||||
|
if not values:
|
||||||
|
return self
|
||||||
other = copy.copy(self)
|
other = copy.copy(self)
|
||||||
for key, value in values.items():
|
for key, value in values.items():
|
||||||
if key not in self._fields:
|
if key not in self._fields:
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class GenericCopyTest(unittest.TestCase):
|
|||||||
|
|
||||||
def compare(self, orig, other):
|
def compare(self, orig, other):
|
||||||
self.assertEqual(orig, other)
|
self.assertEqual(orig, other)
|
||||||
self.assertNotEqual(id(orig), id(other))
|
self.assertEqual(id(orig), id(other))
|
||||||
|
|
||||||
def test_copying_track(self):
|
def test_copying_track(self):
|
||||||
track = Track()
|
track = Track()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user