GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Expand relative cross-references against the object the docstring was written on by devtechedge · Pull Request #342 · mkdocstrings/python

Conversation

@devtechedge

@devtechedge devtechedge commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

With inherited_members enabled, the docstring of a base class member is rendered in the docs of the inheriting class. In AutorefsHook.expand_identifier, leading-dot relative cross-references found in such docstrings walk up from current_object, which for an inherited member is a Griffe alias living under the inheriting class. A reference written on pkga.sub.Base.MAPPING therefore expands to pkgb.Thing in the docs of a package that subclasses Base, instead of pkga.Thing, silently linking to a wrong target or aborting strict builds when the consumer has relative_crossrefs disabled.

This change anchors the dot-walk on the docstring's parent, the object the docstring was actually written on, when that object is reachable, and falls back to the current object otherwise. This mirrors how get_context already uses docstring.parent for source location. The reproducer and root-cause analysis in #341 describe exactly this behavior, including the frequenz-sdk build failure against frequenz-quantities.

A regression test in tests/test_rendering.py builds two in-memory modules with cross-module inheritance and asserts a ....Thing reference in an inherited member's docstring expands to pkga.Thing; it fails on main and passes with this change. A control assertion also checks that non-inherited objects still expand identically.

Re-export aliases are anchored uniformly by this change: since docstring.parent of a re-export alias points at the private defining object, relative references there now expand against it. If different treatment is preferred for re-exports, happy to follow maintainer guidance. Whether the consumer's relative_crossrefs setting should gate expansion of a dependency's docstring at all is out of scope for this PR.

Fixes #341

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devtechedge
fix: Expand relative cross-references against the object the docstrin…
70996f3
…g was written on

With inherited members enabled, docstrings of base class members are
rendered in the docs of the inheriting class, where the current object
is a Griffe alias living under the inheriting class. Leading-dot
relative cross-references found in such docstrings were therefore
expanded against the consumer's tree instead of the dependency's tree,
resolving to wrong targets or failing strict builds.

Anchor the dot-walk on the docstring's parent (the defining object)
when it is reachable, falling back to the current object otherwise.
@pawamoy pawamoy self-assigned this Sep 17, 2026
@devtechedge

devtechedge commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Hello - gentle follow-up on the inherited relative-crossref fix whenever the queue allows.

With inherited_members enabled, AutorefsHook.expand_identifier walked leading-dot relative cross-references from current_object, which for an inherited member is a Griffe alias under the inheriting class, so a reference written on pkga.sub.Base.MAPPING could expand to pkgb.Thing instead of pkga.Thing (Fixes #341).

This anchors the dot-walk on docstring.parent (the object the docstring was actually written on) when reachable, falling back to the current object otherwise, matching how get_context already uses docstring.parent for source location. The change lives in src/mkdocstrings_handlers/python/_internal/rendering.py.

A regression in tests/test_rendering.py builds two in-memory modules with cross-module inheritance and asserts a ....Thing reference in an inherited member's docstring expands to pkga.Thing; it fails on main and passes with this change, with a control that non-inherited objects still expand identically.

Quality checks are green across platforms; several lowest-direct / Windows / 3.15 legs fail on this PR the same way they already fail on main at the base commit, so they are not introduced here.

Happy to special-case re-export aliases differently, or gate expansion on the consumer's relative_crossrefs setting, if that is the preferred shape.

No rush - still ready whenever it fits.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pawamoy
pawamoy approved these changes Sep 22, 2026
View reviewed changes

@pawamoy pawamoy left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, looking good!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pawamoy
pawamoy merged commit a9a4ca3 into mkdocstrings:main Sep 22, 2026
20 of 33 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@llucax

llucax commented Sep 22, 2026

Copy link
Copy Markdown

Thanks for the fix. Do you have any ideas about when this might be released?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pawamoy

pawamoy commented Sep 22, 2026

Copy link
Copy Markdown
Member

Today 🙂

llucax reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devtechedge

devtechedge commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, Timothée.

Anchoring on docstring.parent felt right once I saw get_context already uses it for source location, so the fix followed the file's own logic.

The cross-module inheritance case was genuinely fun to pin down with the in-memory Griffe modules, and it taught me a lot about how aliases carry docstrings. 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pawamoy

pawamoy commented Sep 22, 2026

Copy link
Copy Markdown
Member

@devtechedge please spare your tokens, and next time please also follow our PR template.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 24, 2026
bug: relative cross-references in inherited members still depend on the consumer's relative_crossrefs setting #344
Closed
bug: relative cross-references in inherited members still depend on the consumer's relative_crossrefs setting #345
Closed
@llucax llucax mentioned this pull request Oct 2, 2026
regression(2.0.9): relative cross-references in re-exported and inherited objects expand against private modules #346
Open
@llucax llucax mentioned this pull request Oct 13, 2026
Stop using mkdocstrings relative cross-references frequenz-floss/frequenz-repo-config-python#655
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pawamoy pawamoy pawamoy approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@pawamoy pawamoy

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bug: relative cross-references in inherited members are expanded against the inheriting class

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@devtechedge @llucax @pawamoy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.