xrange issue 7721

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun May 30 19:34:19 EDT 2010


On Mon, 31 May 2010 00:54:16 +0200, Martin v. Loewis wrote:

>> Assuming that I am correct, can I create myself a login on the bugs
>> tracker and re-open the issue to get this sorted?
> 
> Definitely not. The issue you are looking at has been fixed; whatever
> your issue is (you didn't state it clearly), it must be a different one.
> So if you are going to report anything, please submit a new bug report
> instead.
> 
> For the record, the issue you were looking at was a complaint that the
> documentation is incorrect. This had been fixed by correcting the
> documentation.

I think Mark's point is that the code snippet given isn't a full 
replacement for xrange, since it doesn't support negative step sizes, nor 
does it raise an exception on step=0.

I can see why somebody might argue that the documentation is wrong. The 
given snippet *isn't* a replacement for xrange, but merely an example of 
how you might get xrange-like behaviour over a restricted domain.

Since the docs are read by people with vastly different levels of 
experience, skill and nous, I think it's a reasonable complaint to make. 
I am sure that there will be plenty of people who will take the docs 
literally and be surprised when their code fails because the xrange 
replacement fails.

I'd suggest fixing the docs to make it clear that the snippet is a 
simplified example rather than a replacement, rather than trying to 
complicate the snippet to cover all cases xrange deals with.

In my opinion, all it takes is the addition of two words:

If a larger range is needed, an alternate version can be crafted using 
the itertools module, for example: takewhile(lambda x: x<stop, (start
+i*step for i in count())).




-- 
Steven



More information about the Python-list mailing list