Fix crash on prime after single-character superscript - #32066
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Please fill out the rest of the PR checklist (I see Claude coauthorship but no AI disclosure) and provide a minimal script that demonstrates the issue. |
This comment has been minimized.
This comment has been minimized.
|
Please don't make an issue, the PR is enough. @jameslin9968 is at the SciPy sprints with us. |
|
|
Thanks for the review, @scottshambaugh. I've updated the PR description:
No pre-existing issue was filed for this crash, so the checklist's "closes #" is marked N/A. Happy to open one if you'd prefer it tracked separately. |
|
Edit: Got it reproducing locally. |
scottshambaugh
left a comment
There was a problem hiding this comment.
My preference would be for the new comments to be trimmed way down, but this looks good to me otherwise.
A prime (apostrophe) following a single-character superscript such as
``$x^2'$`` raised ``AttributeError: 'Char' object has no attribute
'children'``. A single-character superscript is parsed as a bare ``Char``,
whereas the apostrophe handling in ``Parser.subsuper`` assumed the
superscript was an ``Hlist`` and called ``super.children.extend(...)``.
The braced form ``$x^{2}'$`` already produced an ``Hlist`` and worked.
Wrap a non-``Hlist`` superscript in an ``Hlist`` before appending the
prime glyphs, matching the braced case.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
0986c14 to
720a33e
Compare
|
Thanks @scottshambaugh, @tacaswell. Trimmed the comments in both the fix and the test down to one line each. Force-pushed. |
|
Thank you @jameslin9968 and it was great to talk to you at the sprints today. I hope we hear from you agian! |
…066-on-v3.11.x Backport PR #32066 on branch v3.11.x (Fix crash on prime after single-character superscript)
A prime (apostrophe) following a single-character superscript such as
$x^2'$raisedAttributeError: 'Char' object has no attribute 'children'. A single-character superscript is parsed as a bareChar, whereas the apostrophe handling inParser.subsuperassumed the superscript was anHlistand calledsuper.children.extend(...). The braced form$x^{2}'$already produced anHlistand worked.The fix wraps a non-
Hlistsuperscript in anHlistbefore appending the prime glyphs, matching the braced case.PR summary
Minimal reproduction (crashes on current
main/ released matplotlib):With this PR the expression renders correctly, matching the already-working braced form
$x^{2}'$.AI Disclosure
This PR was authored with substantial AI assistance (Claude). AI was used to localize the bug in
Parser.subsuper, write the fix, and generate the parametrized regression tests intest_mathtext.py. All changes were run and verified locally: the new tests fail without the fix and pass with it, and the fulltest_mathtext.pysuite passes (732 passed / 0 failed).PR checklist
test_mathtext.py)