Skip to content

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 into
GalacticDynamics:versions/v2.0.xfrom
nstarman:backport-870-v2.0.x
Aug 13, 2026
Merged

Backport PR #870 on branch versions/v2.0.x (🐛 fix(quantity): stop _repr_latex_ corrupting units without _repr_latex_)#872
nstarman merged 3 commits into
GalacticDynamics:versions/v2.0.xfrom
nstarman:backport-870-v2.0.x

Conversation

@nstarman

Copy link
Copy Markdown
Contributor

Manual backport of #870 onto versions/v2.0.x. Cherry-picked cleanly, no conflicts.

…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>
@github-actions github-actions Bot added 🧩 unxts-linalg Issues/PRs affecting the unxts.linalg namespace package 🐛 Fix a bug Fix a bug. labels Aug 13, 2026
@nstarman nstarman added this to the v2.0.x milestone Aug 13, 2026
nstarman and others added 2 commits August 13, 2026 20:25
…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>
@nstarman
nstarman requested a review from a team as a code owner August 13, 2026 18:25
@github-actions github-actions Bot added 👷 Add / update CI build system Add or update CI build system. ✅ Add / update / pass tests Add, update, or pass tests. 🧩 unxts-hypothesis Issues/PRs affecting the unxts.hypothesis namespace package 🧩 unxts-interop-gala Issues/PRs affecting the unxts.interop.gala namespace package 🧩 unxts-interop-matplotlib Issues/PRs affecting the unxts.interop.matplotlib namespace package 🧩 unxts-interop-xarray Issues/PRs affecting the unxts.interop.xarray namespace package 🧩 unxts-api Issues/PRs affecting the unxts.api namespace package 🧩 unxts-parametric Issues/PRs affecting the unxts.parametric namespace package 💚 Fix CI build Fix CI Build. labels Aug 13, 2026
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (versions/v2.0.x@02652da). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nstarman
nstarman merged commit 2ef93a0 into GalacticDynamics:versions/v2.0.x Aug 13, 2026
45 checks passed
@nstarman
nstarman deleted the backport-870-v2.0.x branch August 13, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👷 Add / update CI build system Add or update CI build system. ✅ Add / update / pass tests Add, update, or pass tests. 🐛 Fix a bug Fix a bug. 💚 Fix CI build Fix CI Build. 🧩 unxts-api Issues/PRs affecting the unxts.api namespace package 🧩 unxts-hypothesis Issues/PRs affecting the unxts.hypothesis namespace package 🧩 unxts-interop-gala Issues/PRs affecting the unxts.interop.gala namespace package 🧩 unxts-interop-matplotlib Issues/PRs affecting the unxts.interop.matplotlib namespace package 🧩 unxts-interop-xarray Issues/PRs affecting the unxts.interop.xarray namespace package 🧩 unxts-linalg Issues/PRs affecting the unxts.linalg namespace package 🧩 unxts-parametric Issues/PRs affecting the unxts.parametric namespace package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant