aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/code.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2025-02-28 13:15:55 -0500
committerGitHub <noreply@github.com>2025-02-28 13:15:55 -0500
commitfdcbc29f26448f47201ec40fcf3b6405631c85d3 (patch)
treea9bef4a5ebfdf4db2c7a9387c194e4d86681b7dc /Lib/code.py
parent54965f3fb25b381995a73b09d928c344bd2b86bd (diff)
downloadcpython-fdcbc29f26448f47201ec40fcf3b6405631c85d3.tar.gz
cpython-fdcbc29f26448f47201ec40fcf3b6405631c85d3.zip
gh-130660: Restore sys.ps1 and sys.ps2 after code.interact (#130661)
Diffstat (limited to 'Lib/code.py')
-rw-r--r--Lib/code.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/code.py b/Lib/code.py
index 1cc2ed8b1db..41331dfd071 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -219,12 +219,17 @@ class InteractiveConsole(InteractiveInterpreter):
"""
try:
sys.ps1
+ delete_ps1_after = False
except AttributeError:
sys.ps1 = ">>> "
+ delete_ps1_after = True
try:
- sys.ps2
+ _ps2 = sys.ps2
+ delete_ps2_after = False
except AttributeError:
sys.ps2 = "... "
+ delete_ps2_after = True
+
cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
if banner is None:
self.write("Python %s on %s\n%s\n(%s)\n" %
@@ -287,6 +292,12 @@ class InteractiveConsole(InteractiveInterpreter):
if _quit is not None:
builtins.quit = _quit
+ if delete_ps1_after:
+ del sys.ps1
+
+ if delete_ps2_after:
+ del sys.ps2
+
if exitmsg is None:
self.write('now exiting %s...\n' % self.__class__.__name__)
elif exitmsg != '':