diff --git a/Lib/code.py b/Lib/code.py index 2777c3111..b134886dc 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -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 = ''