Skip to content

Commit

Permalink
fixed unbound dict slice
Browse files Browse the repository at this point in the history
  • Loading branch information
randomir committed May 2, 2017
1 parent 492cc4a commit 260c21f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plucky/structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ def _extract_from_dict(self, selector):
failing-back, again, to an empty list.
"""
if isinstance(selector, slice):
keys = xrange(selector.start or 0,
selector.stop or sys.maxint,
selector.step or 1)
# never fallback to maxint, it case `4::2` filter all even numerical keys >=4
start = selector.start or 0
step = selector.step or 1
if selector.stop is None:
keys = [k for k in self.obj.keys() if k >= start and (k - start) % step == 0]
else:
keys = xrange(start, selector.stop, step)
else:
keys = [selector]

Expand Down

0 comments on commit 260c21f

Please sign in to comment.