Skip to content

Commit

Permalink
py3k: Correctly handle string input to slicers.
Browse files Browse the repository at this point in the history
In Python 3, str has the __iter__ method, so just checking for it causes
some invalid iteration through the string characters.
  • Loading branch information
QuLogic committed Sep 16, 2015
1 parent 244ced6 commit b759876
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,8 @@ def _as_list_of_coords(self, names_or_coords):
Convert a name, coord, or list of names/coords to a list of coords.
"""
# If not iterable, convert to list of a single item
if not hasattr(names_or_coords, '__iter__'):
if (not hasattr(names_or_coords, '__iter__') or
isinstance(names_or_coords, str)):
names_or_coords = [names_or_coords]

coords = []
Expand Down Expand Up @@ -2352,7 +2353,8 @@ def slices_over(self, ref_to_slice):
"""
# Required to handle a mix between types.
if not hasattr(ref_to_slice, '__iter__'):
if (not hasattr(ref_to_slice, '__iter__') or
isinstance(ref_to_slice, str)):
ref_to_slice = [ref_to_slice]

slice_dims = set()
Expand Down Expand Up @@ -2412,7 +2414,8 @@ def slices(self, ref_to_slice, ordered=True):
raise TypeError("'ordered' argument to slices must be boolean.")

# Required to handle a mix between types
if not hasattr(ref_to_slice, '__iter__'):
if (not hasattr(ref_to_slice, '__iter__') or
isinstance(ref_to_slice, str)):
ref_to_slice = [ref_to_slice]

dim_to_slice = []
Expand Down

0 comments on commit b759876

Please sign in to comment.