Skip to content

Commit 4187162

Browse files
committed
implement __setslice__ for Python2.7
1 parent 39d5f4d commit 4187162

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lib/iris/cube.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ def __setitem__(self, key, cube_or_sequence):
272272

273273
super(CubeList, self).__setitem__(key, cube_or_sequence)
274274

275+
# __setslice__ is only required for python2.7 compatibility.
276+
def __setslice__(self, *args):
277+
cubes = args[-1]
278+
if isinstance(cubes, Cube) or not isinstance(
279+
cubes, collections.Iterable):
280+
raise TypeError('Assigning to a slice of a cubelist requires '
281+
'a sequence of cubes.')
282+
elif not all([isinstance(cube, Cube) for cube in cubes]):
283+
raise ValueError('Elements of cubelists must be Cube instances.')
284+
285+
super(CubeList, self).__setslice__(*args)
286+
275287
def append(self, cube):
276288
"""
277289
Append a cube.

0 commit comments

Comments
 (0)