Update code from v3.14.2-288-g06f9c8ca1c

This commit is contained in:
CPython Developers
2026-02-01 18:55:19 -05:00
committed by Padraic Fanning
parent ab6114d5a2
commit f26ec68657

24
Lib/code.py vendored
View File

@@ -13,7 +13,6 @@ from codeop import CommandCompiler, compile_command
__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
"compile_command"]
class InteractiveInterpreter:
"""Base class for InteractiveConsole.
@@ -126,7 +125,7 @@ class InteractiveInterpreter:
"""
try:
typ, value, tb = sys.exc_info()
self._showtraceback(typ, value, tb.tb_next, '')
self._showtraceback(typ, value, tb.tb_next, "")
finally:
typ = value = tb = None
@@ -140,7 +139,7 @@ class InteractiveInterpreter:
and not value.text and value.lineno is not None
and len(lines) >= value.lineno):
value.text = lines[value.lineno - 1]
sys.last_exc = sys.last_value = value = value.with_traceback(tb)
sys.last_exc = sys.last_value = value
if sys.excepthook is sys.__excepthook__:
self._excepthook(typ, value, tb)
else:
@@ -220,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" %
@@ -288,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 != '':
@@ -366,7 +376,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
console.raw_input = readfunc
else:
try:
import readline
import readline # noqa: F401
except ImportError:
pass
console.interact(banner, exitmsg)
@@ -375,9 +385,9 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(color=True)
parser.add_argument('-q', action='store_true',
help="don't print version and copyright messages")
help="don't print version and copyright messages")
args = parser.parse_args()
if args.q or sys.flags.quiet:
banner = ''