From 79e999fa797e9fc07c2c442e0cf2475f46c88682 Mon Sep 17 00:00:00 2001 From: Wulian233 <1055917385@qq.com> Date: Sun, 7 Sep 2025 20:35:08 +0800 Subject: [PATCH] port 3.14 --- Doc/library/idle.rst | 8 ++++++-- Lib/idlelib/News3.txt | 2 ++ Lib/idlelib/pyshell.py | 13 +++++++++++++ .../2024-08-30-19-27-28.gh-issue-123369.zPMFHo.rst | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2024-08-30-19-27-28.gh-issue-123369.zPMFHo.rst diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index fabea611e0ebcd..c665d08a76420f 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -102,8 +102,12 @@ Print Window Close Window Close the current window (if an unsaved editor, ask to save; if an unsaved - Shell, ask to quit execution). Calling ``exit()`` or ``close()`` in the Shell - window also closes Shell. If this is the only window, also exit IDLE. + Shell, ask to quit execution). + + You can call ``exit()`` or ``quit()`` to close the Shell. + If the :ref:`new interactive interpreter ` is enabled, + IDLE also supports using ``exit`` or ``quit`` without the need to call them + as functions. If this is the only window, closing it will also exit IDLE. Exit IDLE Close all windows and quit IDLE (ask to save unsaved edit windows). diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index 30784578cc637f..34ddee1a25a4a2 100644 --- a/Lib/idlelib/News3.txt +++ b/Lib/idlelib/News3.txt @@ -3,6 +3,8 @@ What's New in IDLE 3.14.0 Released on 2025-10-07 ========================= +gh-123369: IDLE now support for REPL-specific commands, like help, exit, +license and quit, without the need to call them as functions. gh-112936: IDLE - Include Shell menu in single-process mode, though with Restart Shell and View Last Restart disabled. diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index 74a0e03994f69a..6670222724f737 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -682,6 +682,19 @@ def execfile(self, filename, source=None): def runsource(self, source): "Extend base class method: Stuff the source in the line cache first" filename = self.stuffsource(source) + + # Synchronize the new interactive shell in Python 3.13 + # help, exit, license and quit without the need to call them as functions + # To disable, set the PYTHON_BASIC_REPL environment variable + if not os.getenv('PYTHON_BASIC_REPL'): + REPL_COMMANDS = { + "quit": "quit()", + "exit": "exit()", + "help": "help()", + "license": "license()" + } + source = REPL_COMMANDS.get(source, source) + # at the moment, InteractiveInterpreter expects str assert isinstance(source, str) # InteractiveInterpreter.runsource() calls its runcode() method, diff --git a/Misc/NEWS.d/next/IDLE/2024-08-30-19-27-28.gh-issue-123369.zPMFHo.rst b/Misc/NEWS.d/next/IDLE/2024-08-30-19-27-28.gh-issue-123369.zPMFHo.rst new file mode 100644 index 00000000000000..0f337b2c3ed57b --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2024-08-30-19-27-28.gh-issue-123369.zPMFHo.rst @@ -0,0 +1,2 @@ +IDLE now support for REPL-specific commands, like :kbd:`help`, :kbd:`exit`, +:kbd:`license` and :kbd:`quit`, without the need to call them as functions.