> I don't see the value myself, but in theory it would make sense to have both bounded and infinite ranges be able to be processed the same way.
My thinking is that if we wanted to represent an unbounded range as a mathematical entity (rather than a tool for iteration), we should let that exist in numpy or another mathematical package so that it can have whatever functionality a mathematician would want it to have without being tied up to the cpython release cycle or backwards compatibility constraints. Steele On Fri, Jun 19, 2020 at 12:47 PM Chris Angelico <ros...@gmail.com> wrote: > On Sat, Jun 20, 2020 at 2:39 AM Steele Farnsworth > <swfarnswo...@gmail.com> wrote: > > If range were to support infinite ranges, range.__len__ would have to be > changed to either raise an error or return float('inf') in these cases. > > That would be a problem that would have to be solved, as would related > concepts like what slicing with negative indices would do - what's > range(0, ...)[:-10] give? This doesn't mean the idea is dead in the > water, but anyone who's proposing it will need to come up with answers > to these questions. > > > I believe __contains__ would also need to have extra checks. > > > > That'd be easy enough. The check "x in r" has to check three things: > is x >= r.start, is r < x.stop, and is (x - r.start) % r.step == 0. > Having an infinite end point would simply remove the need for the > middle check (or have it always be true). > > Be aware that this idea is meaningful ONLY for the 'stop' parameter. > An infinite start or step makes no sense. > > I don't see the value myself, but in theory it would make sense to > have both bounded and infinite ranges be able to be processed the same > way. > > ChrisA > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/KYDECOSQCTAE5QJN5HJICZBJVUNQ45CB/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VD2BHQIGME3ABUSBEQXHYPIWOTBTNMZR/ Code of Conduct: http://python.org/psf/codeofconduct/