Backport PR #870 on branch versions/v2.0.x (🐛 fix(quantity): stop _repr_latex_ corrupting units without _repr_latex_) - #872
Merged
nstarman merged 3 commits intoAug 13, 2026
Conversation
…latex_`
`_repr_latex_` sliced `[1:-1]` off the unit's representation, assuming
astropy's `$...$` wrapping. A unit type with no `_repr_latex_` (e.g.
`unxts.linalg.UnitsMatrix`) falls back to plain `__repr__()`, which carries
no such wrapping -- the slice ate its first and last characters instead:
before: '$[1.,~2.,~3.] \; nitsMatrix("(m, s, kg)"$'
after: '$[1.,~2.,~3.] \; UnitsMatrix("(m, s, kg)")$'
Only strip the `$...$` wrapping when it's actually there, i.e. when
`_repr_latex_` exists; the plain `__repr__()` fallback is used unsliced.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ackport The backport was cut from GalacticDynamics#870's first commit rather than its merged state, so it missed the two changes that came out of review: - `self.unit.__repr__()` -> `repr(self.unit)`. This is what fails the `Format` job here, which runs pylint: `C2801 unnecessary-dunder-call`. - Strip `$...$` only when they are actually present, rather than keying off whether the unit implements `_repr_latex_` at all. That proxy reproduces this very defect one step removed, mangling `r"\mathrm{m}"` into `"mathrm{m"` for an implementation returning an unwrapped string. The length guard matters too: a lone `"$"` satisfies both `startswith` and `endswith`. `mixins.py` is now byte-identical to `main`. The four accompanying tests are lifted from `main`, but *only* those: `main`'s copy of this file also carries `test_pdoc_chains_caller_custom_hook` from GalacticDynamics#869, whose `_chain_custom` does not exist on this branch, so taking the file wholesale would have tested absent code. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Backport of GalacticDynamics#867, which `versions/v2.0.x` never received. Without it every PR against this branch fails `Build & inspect`, this one included: InvalidDistribution: Invalid distribution metadata: '2.5' is not a valid metadata version hatchling now emits `Metadata-Version: 2.5`, and v2.18.0 of the action pins `twine==6.2.0`, which rejects it. v3.0.1 ships twine 7. Applied to all 20 CD workflows, which were all on the same pinned SHA. Unrelated to the `_repr_latex_` fix this PR backports, so it is a separate commit and could equally be split into its own backport PR -- but this branch's CI cannot go green without it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## versions/v2.0.x #872 +/- ##
==================================================
Coverage ? 99.67%
==================================================
Files ? 54
Lines ? 3044
Branches ? 200
==================================================
Hits ? 3034
Misses ? 4
Partials ? 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Manual backport of #870 onto
versions/v2.0.x. Cherry-picked cleanly, no conflicts.