Looks promising. The new coding pasting could be a huge quality of life improvement. I hate having to create temporary files or fiddling about with `if __name__ == '__main__'` just to test something in isolation real quick.
Was going to comment exactly this - the pasting on the old repl makes it a real pain and probably a hindrance to many new learners who just want to see what happens. This is really big for these kinds of people.
Until the 3.13 release, here's a trick on pasting: the paste function from https://nedbatchelder.com/blog/201904/startuppy.html will accept pasted input and then evaluate it as code (after EOF is sent via Ctrl+D on Linux/Mac or Ctrl+Z Enter on Windows).
Adding that function to a $PYTHONSTARTUP file will make it available automatically every time you launch the REPL.
It's definitely a hack, but it's a pretty decent workaround for now. I'll likely continue to use it even after the new REPL launches because the textwrap.dedent call will auto-unindent indented code (when pasting from a markdown or reStructuredText file for example).
The actual change here is minor in code and function but Big in implication. It signals that the development finalt after decades of EVERY SINGLE NEW USER going “Why can’t it…” the first time they hit this strange behavior, the old stubborn developers finalt let go of the battle to die on this molehill and made a nano sized step towards an easier world for the end users.
Considering how much Python is valued for being easy to use, it’s incredible it took this long for this to happen.
Any step in improving the interactivity of development workflows is commendable. If you're interested in defining a direction for where REPL features should take us, checkout REPL workflows in Clojure and The Glamorous Toolkit (Smalltalk).
I think there's a bit of a misunderstanding regarding exit. exit is not a keyword or a REPL command, it's actually a function exposed in the builtin package. you can run "import builtins; builtins.exit()" and see that is there
To clarify, there are two things here: why exit exists in the REPL, and why it's a function. The exit() function is available only in the REPL, and it appears built-in, but it isn't part of the built-in namespace. Instead, exit is loaded automatically by the site module.
The line builtins.exit = _sitebuiltins.Quitter('exit', eof) shows that exit is set as a function. The Quitter class, which exit is an instance of, has a __call__ method, making it callable, so it as a function.
I don't believe you're wrong not understanding it; it's just that the process isn’t typically explained in detail, especially what happens when you start the REPL. This is why the message "Use exit() instead..." exists in the REPL, because of the need for clarification.
In a nutshell, exit is a function loaded into the built-ins by the site.py module, which automatically activates when the REPL starts. This automatic loading is what makes exit, help, __copyright__ and others available only in the interactive sessions.
It seems great to change the REPL to treat it like a statement! This is obviously a better user experience. I also think it's somewhat funny given Python's history on "should common functionality be accessed through statements or functions"[1]!
[1] I hope it's obvious that special-casing exit in the REPL is a much more constrained special case than print being a keyword and the difference in scope makes all the difference in balancing accessibility and consistency.
There’s a sense in which it’s pedantically correct - ‘exit’ (and ‘help’) are not Python keywords outside of the REPL, so a beginner might try to use it in a script (maybe like sys.exit()?) and be confused. But I think the convenience is worth it.
Yes, but it goes against the principles of "Explicit is better than implicit" and "There should be one-- and preferably only one—-obvious way to do it." We use parentheses () to call a function. print was a keyword in Python2, now, with print(), it's clear that we are calling for the execution.
It's fun because `exit` alone in the REPL will return an object, and you can get the `exit.eof`, where is the message of what the keyword shortcut to call exit is, and it changes depending on the OS.
note that `exit()` on a script will also not work, as the exit function is only loaded on REPL. To make it work on a script, you will need to import the sys package and later call sys.exit()
`exit()` absolutely works in a script assuming that the `site` module was not bypassed at startup via `python -S`. I understand that `sys.exit()` and others are preferred.
I'm surprised anyone uses the built in REPL when iPython exists. I'm sure there are plenty of good reasons, but for me it's the first install in every project.