News for hackers. Stuff that matters.
Re:You can't do that because I hate you by andrewaylett on Thursday December 28, 2023 @05:31PM (#38799552)
Except they didn't -- the result of a statement is turned into a string, and the string is printed. There are standard ways of turning objects into strings, and the `__repr__` function on the `exit` object returns that string. If you call that object then it raises an exception that triggers a REPL to cleanly quit.

The code is here: https://github.com/python/cpython/blob/3.12/Lib/_sitebuiltin...

Re:You can't do that because I hate you by saulpw on Thursday December 28, 2023 @09:44PM (#38801270)
How about making `exit.__repr__` raise a CleanExit exception that gets caught in the outer REPL and then exits?
Re:You can't do that because I hate you by andrewaylett on Friday December 29, 2023 @08:16AM (#38804541)
I'm fairly sure that having any object's `__repr__` throw an exception and exit would lead to even more confusion. Especially if it exits cleanly.

The object shouldn't be in scope anywhere other than the REPL, but that doesn't mean that something, somewhere, isn't stringifying everything because $REASONS and changing the behaviour won't cause an obscure "crash" somewhere unexpected and hard to debug.