8000 [3.9] bpo-43048: RecursionError traceback RecursionError bugfix for cpy3.9 (GH-24460) by vlad17 · Pull Request #24460 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] bpo-43048: RecursionError traceback RecursionError bugfix for cpy3.9 (GH-24460) #24460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
iritkatriel comments
  • Loading branch information
vlad17 committed Feb 6, 2021
commit cdfef13d8e6f553f72917f197b638fe7bbbfc449
2 changes: 1 addition & 1 deletion Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_base_exception(self):
lst = traceback.format_exception_only(e.__class__, e)
self.assertEqual(lst, ['KeyboardInterrupt\n'])

def test_traceback_recursionerror(self):
def test_traceback_context_recursionerror(self):
# Test that for long traceback chains traceback does not itself
# raise a recursion error while printing (Issue43048)

Expand Down
11 changes: 8 additions & 3 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import collections
import itertools
import linecache
import warnings
import sys

__all__ = ['extract_stack', 'extract_tb', 'format_exception',
Expand Down Expand Up @@ -489,6 +488,7 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
_seen=_seen)
else:
cause = None
self._truncated_context = False
if (exc_value and exc_value.__context__ is not None
and id(exc_value.__context__) not in _seen):
try:
Expand All @@ -501,8 +501,7 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
capture_locals=capture_locals,
_seen=_seen)
except RecursionError:
warnings.warn(
'A RecursionError occurred while processing an exception; truncating traceback.');
self._truncated_context = True
context = None
else:
context = None
Expand Down Expand Up @@ -626,6 +625,12 @@ def format(self, *, chain=True):
not self.__suppress_context__):
yield from self.__context__.format(chain=chain)
yield _context_message
if self._truncated_context:
yield (
'Warning: during handling of the above exception, '
'more exceptions occurred, but were truncated to avoid '
'stack overflow in the exception handler. '
'See https://bugs.python.org/issue43048 for details.\n')
if self.stack:
yield 'Traceback (most recent call last):\n'
yield from self.stack.format()
Expand Down
0