Fix InterfaceMagic compatibility with IPython >= 9.6 #41039
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since IPython 9.6 (with Python 3.12+), the traceback formatter in
IPython.core.ultratb.ListTB._format_exception_only()introduced a stricter assertion that requiresSyntaxError.textto be a string.When interface cell magics are invoked with invalid options (e.g.,
'%%gap foo'), Sage's InterfaceMagic.cell_magic() raised a SyntaxError without setting the .text attribute. This caused IPython 8.27+ to trigger an additional AssertionError during traceback rendering:This fix ensures that the SyntaxError has a properly formatted .text attribute set before raising it, preventing the assertion failure and providing better error messages.
The fix also includes a regression test verifying that the .text attribute is correctly set.
Fix errors raised in #41036 https://github.com/sagemath/sage/actions/runs/18470853388
you can refer to ipython/ipython@db0fde0
📝 Checklist
⌛ Dependencies