Title:'s Quitter pollutes builtins with exit and quit for non-interactive use
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ralph.corderoy, underrun
Priority: normal Keywords:

Created on 2010-03-24 14:52 by ralph.corderoy, last changed 2013-12-18 16:00 by brett.cannon. This issue is now closed.

Messages (4)
msg101635 - (view) Author: Ralph Corderoy (ralph.corderoy) Date: 2010-03-24 14:52
A friend wrote "exit(0)" in a script without an import of sys.  I
pointed out the error and he said "But it works".  He was right.

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 9.10
    Release:        9.10
    Codename:       karmic
    $ python --version
    Python 2.6.4
    $ python -c 'quit("foo")'
    $ echo $?
    $ python -Sc 'quit("foo")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    NameError: name 'quit' is not defined
    $ python -c 'print quit.__class__, exit.__class__'
    <class 'site.Quitter'> <class 'site.Quitter'>
    $ is polluting, to my mind, the builtin namespace with `exit' and 
`quit'.  Surely this should only happen for interactive use of python? says "They are useful
for the interactive interpreter shell and should not be used in
programs." but it seems to easy for exit, especially, to be used by

Could the pollution only happen if the Python interpreter is an
interactive one?  Or, not as good, when called, could they tell this
isn't an interactive session and error?
msg101645 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-03-24 17:16
While technically could probably detect it is running in an interactive session, changing this behaviour now would be backwards-incompatible and break pre-existing code that relies on this behaviour (which has been around for a long time).
msg206527 - (view) Author: Derek Wilson (underrun) Date: 2013-12-18 15:53
could this be reconsidered for 3.5+? most of the legacy code that you were worried about breaking would not port without tonnes of work anyway.

it would also be nice to modify quitter's repr actually exit (so you don't get that ridiculously annoying "Use exit() or Ctrl-D (i.e. EOF) to exit" message). but that would be dangerous to do if it were not available only in the interactive interpreter. while that is my motivation for wanting quitter out of the global namespace, i do understand that is a different ticket. which i will submit. :-)
msg206530 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-12-18 16:00
I still don't think it's worth the potential breakage to remove these from the built-in namespace; there is enough code in Python 3 to not warrant breaking them, nor making any porting harder for those still on Python 2. You can ask on python-dev, though, to see how other core devs feel because I don't feel strongly enough to block it.
Date User Action Args
2013-12-18 16:00:10brett.cannonsetmessages: + msg206530
2013-12-18 15:53:25underrunsetnosy: + underrun

messages: + msg206527
versions: + Python 3.5, - Python 2.6, Python 2.5
2010-03-24 17:16:17brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg101645

resolution: wont fix
2010-03-24 14:52:36ralph.corderoycreate