Permalink
Browse files

Remove the copy() method and make __copy__ an error. (#400)

Please use deepcopy() instead of copy().
  • Loading branch information...
ssteinbach authored and jminor committed Dec 14, 2018
1 parent d044054 commit bbf248a7d3b2481d79677851286ed033bfb2a3a3
@@ -147,13 +147,9 @@ def is_unknown_schema(self):
return False

def __copy__(self):
result = self.__class__()
result._data = copy.copy(self._data)

return result

def copy(self):
return self.__copy__()
raise NotImplementedError(
"Shallow copying is not permitted. Use a deep copy."
)

def __deepcopy__(self, md):
result = type(self)()
@@ -58,7 +58,7 @@
)
# Make a copy of the media ref specifying the byte range for the fragment
media_ref1 = fragmented_media_ref.copy()
media_ref1 = fragmented_media_ref.deepcopy()
media_ref1.available_range=otio.opentime.TimeRange(
otio.opentime.RationalTime(0, 1),
otio.opentime.RationalTime(2.002, 1)
@@ -145,7 +145,7 @@ def test_media_pl_from_mem(self):

# Make a copy of the media ref specifying the byte range for the
# segment
media_ref1 = segmented_media_ref.copy()
media_ref1 = segmented_media_ref.deepcopy()
media_ref1.available_range = otio.opentime.TimeRange(
otio.opentime.RationalTime(0, 1),
otio.opentime.RationalTime(2.002, 1)
@@ -677,7 +677,7 @@ def test_explicit_master_pl_from_mem(self):

# Make a copy of the media ref specifying the byte range for the
# segment
media_ref1 = segmented_media_ref.copy()
media_ref1 = segmented_media_ref.deepcopy()
media_ref1.available_range = otio.opentime.TimeRange(
otio.opentime.RationalTime(0, 1),
otio.opentime.RationalTime(2.002, 1)
@@ -711,7 +711,7 @@ def test_range(self):
# (and also clears out its parent pointers).
del sq
sq = otio.schema.Track(
children=[it, it.copy(), it.copy(), it.copy()],
children=[it, it.deepcopy(), it.deepcopy(), it.deepcopy()],
)
self.assertEqual(
sq.range_of_child_at_index(index=1),
@@ -949,11 +949,7 @@ def test_range_nested(self):
]
)

# Subtle point, but copy() of a Track returns a new Track with a copy
# of all of its metadata, but not of its children. To get that you
# need to deepcopy().
self.assertEqual(len(track), 3)
self.assertEqual(len(track.copy()), 0)
self.assertEqual(len(track.deepcopy()), 3)

# make a nested track with 3 sub-tracks, each with 3 clips
@@ -316,16 +316,6 @@ def test_copy(self):
)
)

it_copy = it.copy()
self.assertIsOTIOEquivalentTo(it, it_copy)
it.metadata["foo"] = "bar2"
# shallow copy, should change both dictionaries
self.assertEqual(it_copy.metadata["foo"], "bar2")

# name should be different
it.name = "foo"
self.assertNotEqual(it_copy.name, it.name)

# deep copy should have different dictionaries
it_dcopy = it.deepcopy()
it_dcopy.metadata["foo"] = "not bar"
@@ -354,17 +344,7 @@ def test_copy_library(self):
)
)

# shallow test
import copy
it_copy = copy.copy(it)
self.assertIsOTIOEquivalentTo(it, it_copy)
it.metadata["foo"] = "bar2"
# shallow copy, should change both dictionaries
self.assertEqual(it_copy.metadata["foo"], "bar2")

# name should be different
it.name = "foo"
self.assertNotEqual(it_copy.name, it.name)

# deep copy should have different dictionaries
it_dcopy = copy.deepcopy(it)
@@ -75,16 +75,9 @@ def test_copy_lib(self):

import copy

# shallow copy
so_cp = copy.copy(so)
so_cp._data["meta_data"]["foo"] = "not bar"
self.assertEqual(so._data, so_cp._data)

so.foo = "bar"
so_cp = copy.copy(so)
# copy only copies members of the _data dictionary, *not* other attrs.
with self.assertRaises(AttributeError):
so_cp.foo
# shallow copy is an error
with self.assertRaises(NotImplementedError):
so_cp = copy.copy(so)

# deep copy
so_cp = copy.deepcopy(so)
@@ -103,7 +96,10 @@ class Foo(otio.core.SerializableObject):

import copy

foo_copy = copy.copy(foo)
with self.assertRaises(NotImplementedError):
foo_copy = copy.copy(foo)

foo_copy = copy.deepcopy(foo)

self.assertEqual(Foo, type(foo_copy))

@@ -79,7 +79,7 @@ def test_expand_surrounded_by_clips(self):
seq.append(trx)
cl_2 = copy.deepcopy(cl)
cl_2.name = name + "_post"
seq.append(copy.copy(cl))
seq.append(copy.deepcopy(cl))

pre_duration = copy.deepcopy(seq[0].source_range.duration)

0 comments on commit bbf248a

Please sign in to comment.