Patch #1446372: quit and exit can now be called from the interactive
authorGeorg Brandl <georg@python.org>
Thu, 9 Mar 2006 23:22:06 +0000 (23:22 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 9 Mar 2006 23:22:06 +0000 (23:22 +0000)
interpreter to exit.

Lib/site.py
Misc/NEWS

index 2207ec59cdc05ea8b3eb411d604c70583808d65d..3fc75377b12c39696f261bce11bb5a193e562455 100644 (file)
@@ -227,12 +227,21 @@ def setquit():
 
     """
     if os.sep == ':':
-        exit = 'Use Cmd-Q to quit.'
+        eof = 'Cmd-Q'
     elif os.sep == '\\':
-        exit = 'Use Ctrl-Z plus Return to exit.'
+        eof = 'Ctrl-Z plus Return'
     else:
-        exit = 'Use Ctrl-D (i.e. EOF) to exit.'
-    __builtin__.quit = __builtin__.exit = exit
+        eof = 'Ctrl-D (i.e. EOF)'
+    
+    class Quitter(object):
+        def __init__(self, name):
+            self.name = name
+        def __repr__(self):
+            return 'Use %s() or %s to exit' % (self.name, eof)
+        def __call__(self, code=None):
+            raise SystemExit(code)
+    __builtin__.quit = Quitter('quit')
+    __builtin__.exit = Quitter('exit')
 
 
 class _Printer(object):
index ed4e97be7a50348d51465324fa1a0a48c3ef6a74..0ed682a4f45f32fccf565d752e8e674c767ae25d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Patch #1446372: quit and exit can now be called from the interactive
+  interpreter to exit.
+
 - Patch #1434038: property() now uses the getter's docstring if there is
   no "doc" argument given. This makes it possible to legitimately use
   property() as a decorator to produce a read-only property.