[issue44603] REPL: exit when the user types exit instead of asking them to explicitly type exit()

Steven D'Aprano report at bugs.python.org
Mon Jul 12 08:16:45 EDT 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

I strongly oppose this change. Merely printing an object should not have a side-effect of this magnitude. Standard Python behaviour is that an object's repr should return a useful string, not exit the interpreter.

This is a backwards-incompatible change: right now, it is perfectly safe to print the builtins namespace in the interactive interpreter:

    vars(builtins)

Doing so gives you are rather large dict, but it is safe and useful. If we make exit actually exit the interpreter instead of print a human readable string, printing the builtins will no longer be safe. It will surprisingly exit in the middle of printing the dict.

`exit` is not magic syntax, it is an actual object. It exists in the builtins namespace. We can put it in lists, we can introspect it and treat it like any other object.

And most importantly, we can print it and get a useful string.

It is not user-friendly to introduce magical special cases. To call a function, Python always requires parentheses. In the builtins and stdlib there are no special cases of functions that magically perform some task just by trying to view it in the interactive interpreter.

(Of course third party code can do anything. If somebody wants the `+` operator to exit the interpreter, or len(obj) to erase their hard drive, Python will allow it.)

Making a handful of objects -- help, exit (quit), license -- behave differently to everything else is not user friendly. Consistency is more important than convenience, especially when it comes to something like exit where the side-effect is to exit the interpreter.

What of copyright and credits? I think their design is a mistake, especially copyright. With 11 lines of output, the copyright object seriously uglifies printing the builtins. But at least it doesn't exit the interpreter.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44603>
_______________________________________


More information about the Python-bugs-list mailing list