Issue 34815: Change Py_Ellipse str behavior. (original) (raw)

Created on 2018-09-27 06:11 by photofone, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sliceobject.c photofone,2018-09-27 06:11 modified sliceobject.c
Pull Requests
URL Status Linked Edit
PR 9596 closed photofone,2018-09-27 06:14
Messages (8)
msg326522 - (view) Author: tom.r (photofone) * Date: 2018-09-27 06:11
Added ellipsis_str function to Objects/sliceobject.c such that str(Ellipsis)=='...'.
msg326524 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-27 06:23
What is the rationale of this change?
msg326525 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-27 06:45
Thanks for the PR but this seems to be backwards incompatible though I don't know if anyone depends on this and I am curious about the reason to change. Since this was added in e449af7da94 (1996) and I am not sure if this needs to be changed though it's up to Guido to take a call. There seems to be no tests for this in test suite that catches this change too. $ python2.7 Python 2.7.14 (default, Mar 12 2018, 13:54:56) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> str(Ellipsis) 'Ellipsis' >>> repr(Ellipsis) 'Ellipsis' Thanks
msg326526 - (view) Author: tom.r (photofone) * Date: 2018-09-27 06:55
Frankly, because it bothered me that ``...`` evaluates to ``Ellipsis`` but that ``Ellipsis`` could never print as ``...``.
msg326527 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-27 07:06
Are you aware that changing just __str__ will not change the result of repr(), so that nested Ellipsis and Ellipsis in REPL will be still represented by name? >>> print(...) ... >>> print([...]) [Ellipsis] >>> ... Ellipsis But changing also __repr__ will conflict with using "..." for representing recursive collections. >>> a = [] >>> a.append(a) >>> a [[...]]
msg326530 - (view) Author: tom.r (photofone) * Date: 2018-09-27 07:19
Yes. I wanted to change just __str__ because the string value of an Ellipsis should be, well, an ellipsis. The __repr__ representation helps distinguish between recursion and an ellipsis object, so that's fine the way it is.
msg326564 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-09-27 14:25
I'm against this. The str() and repr() of Ellipsis are 'Ellipsis' for a reason: to remind the user that this is "just" an object, not a piece of special syntax.
msg326571 - (view) Author: tom.r (photofone) * Date: 2018-09-27 16:30
That's understandable. Thanks for considering it, closing the patch.
History
Date User Action Args
2022-04-11 14:59:06 admin set github: 78996
2018-09-27 16:30:20 photofone set status: open -> closedmessages: + stage: patch review -> resolved
2018-09-27 14:25:40 gvanrossum set messages: +
2018-09-27 07:19:54 photofone set messages: +
2018-09-27 07:06:47 serhiy.storchaka set messages: +
2018-09-27 06:55:56 photofone set messages: +
2018-09-27 06:45:58 xtreak set messages: +
2018-09-27 06:23:59 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2018-09-27 06:22:46 serhiy.storchaka set nosy: + gvanrossum
2018-09-27 06🔞17 xtreak set nosy: + xtreak
2018-09-27 06:14:28 photofone set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest8994>
2018-09-27 06:11:36 photofone create