Skip to content

Commit 82abbf0

Browse files
committed
IDLE now support for REPL-specific commands, like help, exit,
license and quit, without the need to call them as functions.
1 parent f8a736b commit 82abbf0

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

Doc/library/idle.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,14 @@ Print Window
9898
Print the current window to the default printer.
9999

100100
Close Window
101-
Close the current window (if an unsaved editor, ask to save; if an unsaved
102-
Shell, ask to quit execution). Calling ``exit()`` or ``close()`` in the Shell
103-
window also closes Shell. If this is the only window, also exit IDLE.
101+
Close the current window. If there is an unsaved editor, you will be prompted
102+
to save your work. If there is an unsaved Shell, you will be asked whether
103+
you want to quit execution.
104+
105+
In the Shell, you can call ``exit()`` and ``quit()`` to close the Shell.
106+
If the :ref:`new interactive interpreter <tut-interac>` is enabled,
107+
IDLE also supports using ``exit`` and ``quit`` without the need to call them
108+
as functions. If this is the only window, closing it will also exit IDLE.
104109

105110
Exit IDLE
106111
Close all windows and quit IDLE (ask to save unsaved edit windows).

Lib/idlelib/News3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ What's New in IDLE 3.13.0
33
Released on 2024-10-xx
44
=========================
55

6+
gh-123369: IDLE now support for REPL-specific commands, like help, exit,
7+
license and quit, without the need to call them as functions.
68

79
gh-120083: Add explicit black IDLE Hovertip foreground color needed for
810
recent macOS. Fixes Sonoma showing unreadable white on pale yellow.

Lib/idlelib/pyshell.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,21 @@ def execfile(self, filename, source=None):
679679

680680
def runsource(self, source):
681681
"Extend base class method: Stuff the source in the line cache first"
682+
from _pyrepl.main import CAN_USE_PYREPL
682683
filename = self.stuffsource(source)
684+
685+
# Synchronize the new interactive shell in Python 3.13
686+
# help, exit, license and quit without the need to call them as functions
687+
# To disable, set the PYTHON_BASIC_REPL environment variable
688+
if CAN_USE_PYREPL and not os.getenv('PYTHON_BASIC_REPL'):
689+
REPL_COMMANDS = {
690+
"quit": "quit()",
691+
"exit": "exit()",
692+
"help": "help()",
693+
"license": "license()"
694+
}
695+
source = REPL_COMMANDS.get(source, source)
696+
683697
# at the moment, InteractiveInterpreter expects str
684698
assert isinstance(source, str)
685699
# InteractiveInterpreter.runsource() calls its runcode() method,
@@ -1132,7 +1146,7 @@ def short_title(self):
11321146
return self.shell_title
11331147

11341148
COPYRIGHT = \
1135-
'Type "help", "copyright", "credits" or "license()" for more information.'
1149+
'Type "help", "copyright", "credits" or "license" for more information.'
11361150

11371151
def begin(self):
11381152
self.text.mark_set("iomark", "insert")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IDLE now support for REPL-specific commands, like :kbd:`help`, :kbd:`exit`,
2+
:kbd:`license` and :kbd:`quit`, without the need to call them as functions.

0 commit comments

Comments
 (0)