Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
29 changes: 28 additions & 1 deletion Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ class TestTracebackFormat(unittest.TestCase, TracebackFormatMixin):

@cpython_only
@force_not_colorized_test_class
class TestFallbackTracebackFormat(unittest.TestCase, TracebackFormatMixin):
class TestFallbackFormatWhenPrinterRaises(unittest.TestCase, TracebackFormatMixin):
Comment thread
johnslavik marked this conversation as resolved.
Outdated
DEBUG_RANGES = False
def setUp(self) -> None:
self.original_unraisable_hook = sys.unraisablehook
Expand All @@ -2282,6 +2282,33 @@ def tearDown(self) -> None:
sys.unraisablehook = self.original_unraisable_hook
return super().tearDown()

@cpython_only
@force_not_colorized_test_class
class TestFallbackFormatWhenIOUnavailable(unittest.TestCase, TracebackFormatMixin):
def setUp(self) -> None:
import io
self.original_io = io
self.original_hook = traceback._print_exception_bltin
traceback._print_exception_bltin = object()
sys.modules['io'] = types.SimpleNamespace(StringIO=io.StringIO)
return super().setUp()

Comment thread
johnslavik marked this conversation as resolved.
Outdated
def test_unhashable(self):
raise unittest.SkipTest(
"io unavailable (test requires source lines to be captured in tracebacks)")

def test_traceback_format_with_cleared_frames(self):
raise unittest.SkipTest(
"io unavailable (test requires source lines to be captured in tracebacks)")
def test_traceback_format(self):
raise unittest.SkipTest(
"io unavailable (test requires source lines to be captured in tracebacks)")

def tearDown(self) -> None:
sys.modules['io'] = self.original_io
traceback._print_exception_bltin = self.original_hook
return super().tearDown()

class BaseExceptionReportingTests:

def get_exception(self, exception_or_callable):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tracebacks will be displayed in fallback mode even if :func:`io.open` is lost.
Patch by Bartosz Sławecki.
Comment thread
johnslavik marked this conversation as resolved.
3 changes: 3 additions & 0 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *
npath = PyList_Size(syspath);

open = PyObject_GetAttr(io, &_Py_ID(open));
if (open == NULL) {
goto error;
Comment thread
johnslavik marked this conversation as resolved.
Comment thread
johnslavik marked this conversation as resolved.
}
for (i = 0; i < npath; i++) {
v = PyList_GetItem(syspath, i);
if (v == NULL) {
Expand Down
Loading