dcrosta / xrange

A pure-Python implementation of the xrange builtin
BSD 2-Clause "Simplified" License
17 stars 6 forks source link

Slicing logic #1

Open asazernik opened 12 years ago

asazernik commented 12 years ago

There's a bit of a bug in the slicing logic - specifically, the step passed through the slice refers to something different from the _step in the xrange. See the commit message and patch for the solution.

dcrosta commented 12 years ago

Thanks for finding the bug -- I didn't know that about slice steps (and apparently hadn't thought to try). Unfortunately it looks like there are some bugs remaining -- try adding this to test_xrange.py:

def test_getitem_slice_step(self):
    r = xrange(0, 10, 2)
    self.assertEqual(r[:], xrange(0, 10, 2))
    self.assertEqual(r[0:5], xrange(0, 10, 2))
    self.assertEqual(r[0:5:1], xrange(0, 10, 2))
    self.assertEqual(r[0:5:2], xrange(0, 10, 4))

If you want to take a crack at updating the pull request, please do; if not, I will see if I can fix these issues when time permits.