Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,17 @@ def f():
]
self.assertEqual(actual, expected)

def test_memory_error(self):
def f():
raise MemoryError()

actual = self.get_exception(f)
expected = ['Traceback (most recent call last):',
f' File "{__file__}", line {self.callable_line}, in get_exception',
' callable()',
f' File "{__file__}", line {f.__code__.co_firstlineno + 1}, in f',
' raise MemoryError()']
self.assertEqual(actual, expected)


@requires_debug_ranges()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Correctly display the traceback for :exc:`MemoryError` exceptions using the
:mod:`traceback` module. Patch by Pablo Galindo
5 changes: 1 addition & 4 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ print_exception_recursive(struct exception_print_context *ctx, PyObject *value)
void
_PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
{
assert(value != NULL);
assert(file != NULL && file != Py_None);
if (PyExceptionInstance_Check(value)
&& tb != NULL && PyTraceBack_Check(tb)) {
Expand All @@ -1047,10 +1048,6 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)

int unhandled_keyboard_interrupt = _PyRuntime.signals.unhandled_keyboard_interrupt;

if (!value || PyErr_GivenExceptionMatches(value, PyExc_MemoryError)) {
goto fallback;
}

// Try first with the stdlib traceback module
PyObject *traceback_module = PyImport_ImportModule("traceback");

Expand Down