On 2018-11-20 00:19, Steven D'Aprano wrote:
On the bug tracker, there is a proposal to enhance range objects so that
printing them will display a snapshot of the values included, including
the end points. For example:

print(range(10))

currently displays "range(10)". The proposal is for the __str__ method
to instead return "<range object [0, 1, ..., 8, 9]>".

https://bugs.python.org/issue35200

print(range(2, 200, 3)) would display

<range object [2, 5, ..., 194, 197]>

Note that the original proposal was for range objects' __repr__ to
display this behaviour. But given the loss of eval(repr(obj)) round
tripping, and the risk of breaking backwards compatibility, it was
decided that isn't acceptable but using the same display for __str__
(and hence produced by print) would be nearly as useful but without the
downsides.

The developer who proposed the feature, Julien, now wants to reject the
feature request. I think it is still a useful feature for range objects.
What do others think? Is this worth re-opening?

Well, if it's not going to round-trip, and it's going to be more verbose, then I think it shouldn't be making the step size implicit.

Maybe something more like: <range object, start 2, step 3, max 197>

But, overall, I'm ±0.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to