[Python-ideas] Pass a function as the argument "step" of range()

Chris Angelico rosuav at gmail.com
Sat Jul 4 02:28:59 CEST 2015


On Sat, Jul 4, 2015 at 10:17 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Also, I think 'numbers' should be narrowed to 'integers' (or whatever is
>> actually accepted).  The idea of allowing floats has been proposed at least
>> once, probably more, and rejected.
>
> Unfortunately, we don't have a great word for "implements __index__", as
> "integer" at least arguably implies specifically "int".

I'm not sure that actually matters - even if the parameters can be any
objects that implement __index__, the range still represents a
sequence of ints:

>>> class X:
...  def __index__(self): return 4
...
>>> range(X())
range(0, 4)
>>> list(range(X()))
[0, 1, 2, 3]
>>> [type(n) for n in range(X())]
[<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>]


Saying "sequence of integers" seems fine to me.

ChrisA


More information about the Python-ideas mailing list