aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Lib/code.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-09-17 19:54:19 +0300
committershadchin <shadchin@yandex-team.com>2024-09-17 20:04:48 +0300
commitad73802f079a708231d906dd7273a632db735851 (patch)
treed8b2b9f0b31430e69b777af21f63b432f4b92cc4 /contrib/tools/python3/Lib/code.py
parent7c4e4744ae44dd94daa179458190817615f9e8a1 (diff)
downloadydb-ad73802f079a708231d906dd7273a632db735851.tar.gz
Update Python 3 to 3.12.6
commit_hash:43ed87a61b9efe3a87682fda1f0bff6f7b422cc9
Diffstat (limited to 'contrib/tools/python3/Lib/code.py')
-rw-r--r--contrib/tools/python3/Lib/code.py86
1 files changed, 40 insertions, 46 deletions
diff --git a/contrib/tools/python3/Lib/code.py b/contrib/tools/python3/Lib/code.py
index b4b1ef3b8b..cb7dd44b0a 100644
--- a/contrib/tools/python3/Lib/code.py
+++ b/contrib/tools/python3/Lib/code.py
@@ -105,29 +105,21 @@ class InteractiveInterpreter:
The output is written by self.write(), below.
"""
- type, value, tb = sys.exc_info()
- sys.last_exc = value
- sys.last_type = type
- sys.last_value = value
- sys.last_traceback = tb
- if filename and type is SyntaxError:
- # Work hard to stuff the correct filename in the exception
- try:
- msg, (dummy_filename, lineno, offset, line) = value.args
- except ValueError:
- # Not the format we expect; leave it alone
- pass
- else:
- # Stuff in the right filename
- value = SyntaxError(msg, (filename, lineno, offset, line))
- sys.last_exc = sys.last_value = value
- if sys.excepthook is sys.__excepthook__:
- lines = traceback.format_exception_only(type, value)
- self.write(''.join(lines))
- else:
- # If someone has set sys.excepthook, we let that take precedence
- # over self.write
- self._call_excepthook(type, value, tb)
+ try:
+ typ, value, tb = sys.exc_info()
+ if filename and typ is SyntaxError:
+ # Work hard to stuff the correct filename in the exception
+ try:
+ msg, (dummy_filename, lineno, offset, line) = value.args
+ except ValueError:
+ # Not the format we expect; leave it alone
+ pass
+ else:
+ # Stuff in the right filename
+ value = SyntaxError(msg, (filename, lineno, offset, line))
+ self._showtraceback(typ, value, None)
+ finally:
+ typ = value = tb = None
def showtraceback(self):
"""Display the exception that just occurred.
@@ -137,32 +129,34 @@ class InteractiveInterpreter:
The output is written by self.write(), below.
"""
- sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
- sys.last_traceback = last_tb
- sys.last_exc = ei[1]
try:
- if sys.excepthook is sys.__excepthook__:
- lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
- self.write(''.join(lines))
- else:
- # If someone has set sys.excepthook, we let that take precedence
- # over self.write
- self._call_excepthook(ei[0], ei[1], last_tb)
+ typ, value, tb = sys.exc_info()
+ self._showtraceback(typ, value, tb.tb_next)
finally:
- last_tb = ei = None
+ typ = value = tb = None
- def _call_excepthook(self, typ, value, tb):
- try:
- sys.excepthook(typ, value, tb)
- except SystemExit:
- raise
- except BaseException as e:
- e.__context__ = None
- print('Error in sys.excepthook:', file=sys.stderr)
- sys.__excepthook__(type(e), e, e.__traceback__.tb_next)
- print(file=sys.stderr)
- print('Original exception was:', file=sys.stderr)
- sys.__excepthook__(typ, value, tb)
+ def _showtraceback(self, typ, value, tb):
+ sys.last_type = typ
+ sys.last_traceback = tb
+ sys.last_exc = sys.last_value = value = value.with_traceback(tb)
+ if sys.excepthook is sys.__excepthook__:
+ lines = traceback.format_exception(typ, value, tb)
+ self.write(''.join(lines))
+ else:
+ # If someone has set sys.excepthook, we let that take precedence
+ # over self.write
+ try:
+ sys.excepthook(typ, value, tb)
+ except SystemExit:
+ raise
+ except BaseException as e:
+ e.__context__ = None
+ e = e.with_traceback(e.__traceback__.tb_next)
+ print('Error in sys.excepthook:', file=sys.stderr)
+ sys.__excepthook__(type(e), e, e.__traceback__)
+ print(file=sys.stderr)
+ print('Original exception was:', file=sys.stderr)
+ sys.__excepthook__(typ, value, tb)
def write(self, data):
"""Write a string.