This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mdk
Recipients mdk, ncoghlan, rhettinger, seluj78, serhiy.storchaka, steven.daprano
Date 2018-11-12.00:28:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541982524.55.0.788709270274.issue35200@psf.upfronthosting.co.za>
In-reply-to
Content
I understand we like round-tripping represnetations, I think we like them because in much cases it's immediatly and unambiguously understandable by a Python developer.

It's the best representation as it's the one conveying the most information. But `range(0, 10)` convery very few information, one may forget the "begin included, end excluded" rule (or even if the 2nd one is the end of the length). I think the following is more usefull:

>>> range(10)
<range object [0, 1, ..., 8, 9]>
>>> range(10, 2)
<range object []>
>>> range(2, 10)
<range object [2, 3, ..., 8, 9]>
>>> range(2, 10, 2)
<range object [2, 4, 6, 8]>
>>> 



@steven:

I dont think moving this to __str__ would help someone: I've never seen any student try `str(range(10))` in the repl, they all naturally try the bare `range(10)` and they're all presented with un-informative information. If someone is here to teach them to try with str, better try with list(range(10)) or *range(10).

As for repr(range(0)) == repr(range(2, 2)) == repr(range(1, 5, -1)) I do not consider this a bug, they are all strictly equivalent as being the empty range (when speaking of a mathematical object, maybe not the in-memory struct).


@raymond:

I'm also not OK to teach `*repr(10)` during the first class. I personally go for `list(range(10))`, but I can only because I'm physically available when they ask why the information displayed is not what they expect. A lot of people are learning Python at home and they're probably just lost while being presented with the round-tripping representation.


I don't really agree that changing the repr could break code doing `eval(repr(range(10)))`, is it really something people do?


@nick:

I agree changing the repr could break some doctests on function returning ranges, on the other hand I've never seen a function returning a range.
History
Date User Action Args
2018-11-12 00:28:44mdksetrecipients: + mdk, rhettinger, ncoghlan, steven.daprano, serhiy.storchaka, seluj78
2018-11-12 00:28:44mdksetmessageid: <1541982524.55.0.788709270274.issue35200@psf.upfronthosting.co.za>
2018-11-12 00:28:44mdklinkissue35200 messages
2018-11-12 00:28:44mdkcreate