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

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

Messages (2)
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")'
    foo
    $ echo $?
    1
    $ 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'>
    $

site.py is polluting, to my mind, the builtin namespace with `exit' and 
`quit'.  Surely this should only happen for interactive use of python?

http://docs.python.org/library/constants.html#exit 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
mistake.

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 site.py 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).
History
Date User Action Args
2010-03-24 17:16:17brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg101645

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