Skip to content

Commit 0a64e76

Browse files
authored
Fix ipython#15011, Exception.text may be None (ipython#15012)
And add a test for it.
2 parents f77d3f9 + b91c950 commit 0a64e76

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

IPython/core/ultratb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,11 @@ def _format_exception_only(
338338
if textline == "":
339339
# sep 2025:
340340
# textline = py3compat.cast_unicode(value.text, "utf-8")
341-
assert isinstance(value.text, str)
342-
textline = value.text
341+
if value.text is None:
342+
textline = ""
343+
else:
344+
assert isinstance(value.text, str)
345+
textline = value.text
343346

344347
if textline is not None:
345348
i = 0

tests/test_ultratb.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,10 @@ def eggs(f, g, z=globals()):
498498
except:
499499
handler(*sys.exc_info())
500500
buff.write("")
501+
502+
503+
def testSyntaxError():
504+
cell = "raise SyntaxError()"
505+
expected = "SyntaxError\n"
506+
with tt.AssertPrints(expected):
507+
ip.run_cell(cell)

0 commit comments

Comments
 (0)