Exclude the physical-type aliases from the default numpydoc xref aliases - #103
Merged
astrofrog merged 2 commits intoJun 24, 2026
Merged
Conversation
…ses so quoted option values such as 'power' are no longer turned into spurious cross-references, leaving them available as an explicit opt-in and fixing the malformed :ref: value so that opt-in renders correctly
1 task
pllim
approved these changes
Jun 9, 2026
pllim
left a comment
Member
There was a problem hiding this comment.
At least for the problem I saw, this PR seems to fix it. Yay!
larrybradley
approved these changes
Jun 9, 2026
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
astrofrog
marked this pull request as ready for review
June 9, 2026 22:31
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.
This is to fix astropy issue #19868: in the
rendered
simple_normdocs, the'power'option ofstretch : {'linear', 'sqrt', 'power', ...}is turned into a hyperlink to the power physical type. It's a meaningless link —'power'there is a literal option value, not a unit physical type.This happens because
sphinx_astropy/conf/v2.pybuildsnumpydoc_xref_aliases_astropy_physical_typewith keys that are quoted strings ('power','energy','time', ...) and folds them into the defaultnumpydoc_xref_astropy_aliases.Numpydoc gives a quoted string a single meaning regardless of context, but the
common context is an enum of literal options:
Here
'power'is a literal choice, not a type — but it's the same token the alias is keyed on, so alias substitution rewrites it into a cross-reference. About a dozen physical-type names collide with ordinary option words (area,energy,force,length,mass,power,pressure,speed,time,volume, ...), so any{...}enum using one of those words gets a spurious link.These aliases were added as an opt-in in #40. The intended use was a parameter whose type is a physical quantity, written as a quoted name — e.g.
length : 'length'linking to astropy's physical-types docs. The original comment documents them as something packages turn on explicitly withnumpydoc_xref_aliases.update(numpydoc_xref_astropy_aliases)— but glossary and physical-type aliases were fused into a single ChainMap, so a package couldn't take the safe glossary aliases without also pulling in the colliding physical-type ones.They also appear never to have actually worked properly anyway: the alias value has a double
:ref:(:ref::ref: '{ptype}' <...>``) since the very first commit (this is also fixed here)The fix is to drop
numpydoc_xref_aliases_astropy_physical_typefrom the defaultnumpydoc_xref_astropy_aliasesChainMap. It stays defined and documented as an explicit opt-in for packages that genuinely want physical-type cross-refs (having it opt-in was the original intent):The glossary aliases remain on by default — they're all hyphenated
-liketerms (time-like, etc.) that don't collide with literal option values, so they're safe(r).This also fixes the double
:ref:, so the opt-in path now renders a correct link instead of literal:ref: 'power'text.In future we could consider not automagically changing 'power' to a ref but having some kind of namespace like
physical_type:powerin docstrings to avoid any ambiguities.