Title: fix: Expand relative cross-references against the object the docstring was written on by devtechedge · Pull Request #342 · mkdocstrings/python · GitHub
Open Graph Title: fix: Expand relative cross-references against the object the docstring was written on by devtechedge · Pull Request #342 · mkdocstrings/python
X Title: fix: Expand relative cross-references against the object the docstring was written on by devtechedge · Pull Request #342 · mkdocstrings/python
Description: 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
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/mkdocstrings/python/pull/342
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f5e1a2b2-65c7-c0e6-0b2b-d9d56c9b92e7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 84A6:263AB0:19904F:236275:6AF8395D |
| html-safe-nonce | 0092cbc09e49de01bb7e613ba830ae22a663f2607d120b0858764c1c0c770e40 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEE2OjI2M0FCMDoxOTkwNEY6MjM2Mjc1OjZBRjgzOTVEIiwidmlzaXRvcl9pZCI6IjkwNTc4MTI5MTYzODMyNjcxNjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8ab5441d28fe4f6f82c732c5a64ecbc590a1c6e51b497cd7b43f7c555ed2d3f1 |
| hovercard-subject-tag | pull_request:4521334715 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/mkdocstrings/python/pull/342/files |
| twitter:image | https://avatars.githubusercontent.com/u/294291171?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/294291171?s=400&v=4 |
| og:image:alt | 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 ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5713ecd83001b2f55c3509fb7a292bf7d66d0f167c7ae87a9f7eaec5a52bf8db |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/mkdocstrings/python git https://github.com/mkdocstrings/python.git |
| octolytics-dimension-user_id | 75664361 |
| octolytics-dimension-user_login | mkdocstrings |
| octolytics-dimension-repository_id | 422878404 |
| octolytics-dimension-repository_nwo | mkdocstrings/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 422878404 |
| octolytics-dimension-repository_network_root_nwo | mkdocstrings/python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 653be32ff5c755082a4db662491bfbbcfc9112c1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width