[Python-ideas] Should range() == range(0)?
Devin Jeanpierre
jeanpierreda at gmail.com
Mon May 7 01:52:00 CEST 2012
On Sun, May 6, 2012 at 5:24 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> Another advantage of doing this, beside consistency, is that it would
> emphasize that range() produces a re-iterable sequence, not just an
> iterator.
How? The empty sequence is the exact case where reiterable objects and
iterators have identical iteration behavior. (Both immediately stop
every time you try.)
> Possible objections and responses:
>
> 1. This would slightly complicate the already messy code and doc for
> range().
>
> Pass, for now
By this, do you mean don't write new documentation? That just defers
the problem to later.
> 3. There is little or no use case.
>
> The justification I have seen for all the other classes behaving as they do
> is expressions like type(x)(), which gets the null object corresponding to
> x. This requires a parameterless call rather than a literal (or display) or
> call with typed arg.
>
> A proper objection this sort would have to argue that range() is less useful
> than all 12+ cases that we have now.
Most of the other types are useful as parameters to something such as
collections.defaultdict. In the case of range, why not use tuple for
this?
Although, I actually like this idea, because it feels more consistent.
I imagine that isn't a good reason to like things though.
-- Devin
More information about the Python-ideas
mailing list