From 86481b1d504ee1f25ac1a8a5dadbe58ee8e12161 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 8 Apr 2015 00:34:02 +0200 Subject: [PATCH] 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. --- mopidy/models.py | 2 ++ tests/models/test_models.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mopidy/models.py b/mopidy/models.py index 35f1f9eb..af409570 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -224,6 +224,8 @@ class ImmutableObject(object): :type values: dict :rtype: new instance of the model being copied """ + if not values: + return self other = copy.copy(self) for key, value in values.items(): if key not in self._fields: diff --git a/tests/models/test_models.py b/tests/models/test_models.py index 8f72dd34..ef484fa9 100644 --- a/tests/models/test_models.py +++ b/tests/models/test_models.py @@ -12,7 +12,7 @@ class GenericCopyTest(unittest.TestCase): def compare(self, orig, other): self.assertEqual(orig, other) - self.assertNotEqual(id(orig), id(other)) + self.assertEqual(id(orig), id(other)) def test_copying_track(self): track = Track()