René's URL Explorer Experiment


Title: bug: relative cross-references in inherited members are expanded against the inheriting class · Issue #341 · mkdocstrings/python · GitHub

Open Graph Title: bug: relative cross-references in inherited members are expanded against the inheriting class · Issue #341 · mkdocstrings/python

X Title: bug: relative cross-references in inherited members are expanded against the inheriting class · Issue #341 · mkdocstrings/python

Description: Description of the bug When a class inherits from a class defined in another package and inherited_members is enabled, mkdocstrings renders the base class member's docstring under the subclass. If that docstring contains a relative cross...

Open Graph Description: Description of the bug When a class inherits from a class defined in another package and inherited_members is enabled, mkdocstrings renders the base class member's docstring under the subclass. If ...

X Description: Description of the bug When a class inherits from a class defined in another package and inherited_members is enabled, mkdocstrings renders the base class member's docstring under the subclass....

Opengraph URL: https://github.com/mkdocstrings/python/issues/341

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: relative cross-references in inherited members are expanded against the inheriting class","articleBody":"### Description of the bug\n\nWhen a class inherits from a class defined in another package and `inherited_members` is enabled, mkdocstrings renders the base class member's docstring under the subclass. If that docstring contains a relative cross-reference, the reference is expanded as if it had been written in the subclass, not where it was actually written.\n\nThe expansion happens in [`AutorefsHook.expand_identifier`](https://github.com/mkdocstrings/python/blob/8125b0d28b039693ff05b8caac981da47eb4cd7c/src/mkdocstrings_handlers/python/_internal/rendering.py#L805-L813), which walks `self.current_object`. For an inherited member, `current_object` is a Griffe `Alias` that lives under the inheriting class, so in the reproducer below `alias.path` is `pkgb.Derived.MAPPING` and `alias.parent` is `pkgb.Derived`, while `alias.docstring.parent` is `pkga.sub.Base.MAPPING`, the object the docstring was actually written on. Walking up N parents therefore climbs the consumer's tree instead of the dependency's.\n\nThat has two visible consequences.\n\nThe expanded identifier points at the wrong place. In the reproducer, ``[`Thing`][....Thing]`` written on `pkga.sub.Base.MAPPING` expands to `pkga.Thing` in pkga's own docs, which is correct, and to `pkgb.Thing` in the docs of a package that subclasses `Base`. When the consumer happens to have an object of that name, as `pkgb` does here, the link silently points at the unrelated object and no warning is emitted.\n\nThe expansion is also gated on the consumer's own `relative_crossrefs` setting, even though the docstring comes from a dependency. A consumer that does not enable that option gets the raw dotted string handed to autorefs:\n\n```\nWARNING - mkdocs_autorefs: index.md: from /path/to/repro/pkga/sub.py:10: (pkgb.Derived.MAPPING) Could not find cross-reference target '....Thing'\n```\n\nwhich is fatal under `strict: true`. The dependency's docstring is correct and its own documentation builds fine, but the downstream build breaks, and the only workaround on the downstream side is to turn `inherited_members` off.\n\nIncidentally, [`get_context`](https://github.com/mkdocstrings/python/blob/8125b0d28b039693ff05b8caac981da47eb4cd7c/src/mkdocstrings_handlers/python/_internal/rendering.py#L842-L848) in the same class already uses `docstring.parent.filepath`, which is why the warning above correctly points at the dependency's source file. The defining object is therefore reachable at that point.\n\n### To Reproduce\n\n```bash\nmkdir -p repro/pkga repro/pkgb repro/docs-a repro/docs-b\ncd repro\n\npython -m venv .venv\n. .venv/bin/activate\npip install -q mkdocs 'mkdocstrings[python]'\n\ncat > pkga/__init__.py \u003c\u003c'EOF'\n\"\"\"Package A (the dependency).\"\"\"\n\nfrom pkga._core import Thing\n\n__all__ = [\"Thing\"]\nEOF\n\ncat > pkga/_core.py \u003c\u003c'EOF'\n\"\"\"Core objects of package A.\"\"\"\n\n\nclass Thing:\n    \"\"\"A thing, defined by package A.\"\"\"\nEOF\n\ncat > pkga/sub.py \u003c\u003c'EOF'\n\"\"\"Sub-module of package A.\"\"\"\n\nfrom typing import Any\n\n\nclass Base:\n    \"\"\"A base class.\"\"\"\n\n    MAPPING: dict[str, Any] = {}\n    \"\"\"The mapping to use for each [`Thing`][....Thing].\"\"\"\nEOF\n\ncat > pkgb/__init__.py \u003c\u003c'EOF'\n\"\"\"Package B (the downstream consumer).\"\"\"\n\nfrom pkga.sub import Base\n\n\nclass Thing:\n    \"\"\"A completely unrelated thing, which happens to have the same name.\"\"\"\n\n\nclass Derived(Base):\n    \"\"\"A class derived from package A's base class.\"\"\"\nEOF\n\necho '# Package A\n\n::: pkga\n\n::: pkga.sub' > docs-a/index.md\n\necho '# Package B\n\n::: pkgb' > docs-b/index.md\n\ncat > mkdocs-a.yml \u003c\u003c'EOF'\nsite_name: pkga\ndocs_dir: docs-a\nsite_dir: site-a\nstrict: true\nplugins:\n- mkdocstrings:\n    handlers:\n      python:\n        options:\n          relative_crossrefs: true\nEOF\n\ncat > mkdocs-b.yml \u003c\u003c'EOF'\nsite_name: pkgb\ndocs_dir: docs-b\nsite_dir: site-b\nstrict: true\nplugins:\n- mkdocstrings:\n    handlers:\n      python:\n        options:\n          preload_modules: [pkga]\n          inherited_members: true\n          # relative_crossrefs is deliberately NOT enabled here\nEOF\n\necho \"### 1. pkga's own docs (relative_crossrefs enabled): reference is correct\"\nmkdocs build -f mkdocs-a.yml 2>&1 | tail -3\ngrep -o 'The mapping to use for each \u003ca[^>]*>' site-a/index.html | tail -1\n\necho\necho \"### 2. pkgb's docs, without relative_crossrefs: the raw dotted string leaks\"\nmkdocs build -f mkdocs-b.yml 2>&1 | tail -3 || true\ngrep -o 'The mapping to use for each .*\\.$' site-b/index.html | tail -1 || true\n\necho\necho \"### 3. pkgb's docs, with relative_crossrefs: expanded against the WRONG class\"\nsed -i 's/          # relative_crossrefs.*/          relative_crossrefs: true/' mkdocs-b.yml\nmkdocs build -f mkdocs-b.yml 2>&1 | tail -3\ngrep -o 'The mapping to use for each \u003ca[^>]*>' site-b/index.html | tail -1\n```\n\nOutput:\n\n```\n### 1. pkga's own docs (relative_crossrefs enabled): reference is correct\nINFO    -  Cleaning site directory\nINFO    -  Building documentation to directory: /tmp/repro/site-a\nINFO    -  Documentation built in 0.40 seconds\nThe mapping to use for each \u003ca class=\"autorefs autorefs-internal\" href=\"#pkga.Thing\">\n\n### 2. pkgb's docs, without relative_crossrefs: the raw dotted string leaks\nWARNING -  mkdocs_autorefs: index.md: from /tmp/repro/pkga/sub.py:10: (pkgb.Derived.MAPPING) Could not find cross-reference target '....Thing'\n\nAborted with 1 warnings in strict mode!\n\n### 3. pkgb's docs, with relative_crossrefs: expanded against the WRONG class\nINFO    -  Cleaning site directory\nINFO    -  Building documentation to directory: /tmp/repro/site-b\nINFO    -  Documentation built in 0.27 seconds\nThe mapping to use for each \u003ca class=\"autorefs autorefs-internal\" href=\"#pkgb.Thing\">\n```\n\nIn the repro `pkga` sits next to `pkgb` for brevity. The real case has `pkga` installed as a dependency in `site-packages`, which changes nothing.\n\n### Full traceback\n\nThere is no traceback. The failure surfaces as the `mkdocs_autorefs` warning shown above, which aborts the build in strict mode.\n\n### Environment information\n\n```bash\npython -m mkdocstrings_handlers.python._internal.debug\n- __System__: Linux-6.12.107+deb13-amd64-x86_64-with-glibc2.42\n- __Python__: cpython 3.12.14\n- __Environment variables__:\n- __Installed packages__:\n  - `mkdocs` v1.6.1\n  - `mkdocstrings` v1.0.6\n  - `mkdocstrings-python` v2.0.8\n  - `mkdocs-autorefs` v1.4.4\n  - `griffelib` v2.3.0\n```\n\n### Additional context\n\nReal-world occurrence: [frequenz-quantities](https://github.com/frequenz-floss/frequenz-quantities) documents `QuantitySchema.TYPE_MAPPING` with ``[`Quantity`][.....Quantity]``, which resolves correctly in its own documentation. [frequenz-sdk-python](https://github.com/frequenz-floss/frequenz-sdk-python) subclasses that schema and builds with `inherited_members: true` and `strict: true`, without `relative_crossrefs`, so its documentation build fails with `Could not find cross-reference target '.....Quantity'`. [Build log](https://github.com/frequenz-floss/frequenz-sdk-python/actions/runs/34208898217/job/102004915946).\n\nOn a possible direction: expanding against `self.current_object.docstring.parent` when it is set would use the object the docstring was written on. One thing to weigh is that this also changes re-export aliases and not only inherited members. For `pkga.Thing`, an alias to `pkga._core.Thing`, `docstring.parent` is `pkga._core.Thing`, so relative references in that docstring would expand against the private module rather than the alias's location. Whether the consumer's `relative_crossrefs` setting should gate the expansion of a dependency's docstring at all looks like a separate decision.\n","author":{"url":"https://github.com/llucax","@type":"Person","name":"llucax"},"datePublished":"2026-09-08T10:30:09Z","url":"https://github.com/mkdocstrings/python/issues/341"}

react-profiling0
react-import-mapreact,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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6c1eafa4-a482-43f1-cc72-66de4d4b3c66
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB3F8:329B1E:18BE59:221904:6AF838E7
html-safe-nonceb67e4047241d6c1051a33e92b53958835878779cb855dbd03a522a626f56b652
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0Y4OjMyOUIxRToxOEJFNTk6MjIxOTA0OjZBRjgzOEU3IiwidmlzaXRvcl9pZCI6Ijc5NTYwNDk0NTAxMzg4NzYxMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac72030dc715a1191c0a6cb935d69d76feafee72b06bc908749ab241a6663b9c89
hovercard-subject-tagissue:5385540527
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/mkdocstrings/python/341/issue_layout
twitter:imagehttps://opengraph.githubassets.com/531fa9954bae3c76949945bce79928fa7ef6846fc273b0480a657f579021c977/mkdocstrings/python/issues/341
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/531fa9954bae3c76949945bce79928fa7ef6846fc273b0480a657f579021c977/mkdocstrings/python/issues/341
og:image:altDescription of the bug When a class inherits from a class defined in another package and inherited_members is enabled, mkdocstrings renders the base class member's docstring under the subclass. If ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamellucax
hostnamegithub.com
expected-hostnamegithub.com
None5713ecd83001b2f55c3509fb7a292bf7d66d0f167c7ae87a9f7eaec5a52bf8db
turbo-cache-controlno-preview
go-importgithub.com/mkdocstrings/python git https://github.com/mkdocstrings/python.git
octolytics-dimension-user_id75664361
octolytics-dimension-user_loginmkdocstrings
octolytics-dimension-repository_id422878404
octolytics-dimension-repository_nwomkdocstrings/python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id422878404
octolytics-dimension-repository_network_root_nwomkdocstrings/python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release653be32ff5c755082a4db662491bfbbcfc9112c1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/mkdocstrings/python/issues/341#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmkdocstrings%2Fpython%2Fissues%2F341
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmkdocstrings%2Fpython%2Fissues%2F341
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=mkdocstrings%2Fpython
Reloadhttps://github.com/mkdocstrings/python/issues/341
Reloadhttps://github.com/mkdocstrings/python/issues/341
Reloadhttps://github.com/mkdocstrings/python/issues/341
mkdocstringshttps://github.com/mkdocstrings
pythonhttps://github.com/mkdocstrings/python
Codehttps://github.com/mkdocstrings/python
Issues6 (6)https://github.com/mkdocstrings/python/issues
Pull requestshttps://github.com/mkdocstrings/python/pulls
Discussionshttps://github.com/mkdocstrings/python/discussions
Actionshttps://github.com/mkdocstrings/python/actions
Security and qualityhttps://github.com/mkdocstrings/python/security
Insightshttps://github.com/mkdocstrings/python/pulse
https://github.com/mkdocstrings/python
New issuehttps://github.com/login?return_to=https://github.com/mkdocstrings/python/issues/341
New issuehttps://github.com/login?return_to=https://github.com/mkdocstrings/python/issues/341
#342https://github.com/mkdocstrings/python/pull/342
bug: relative cross-references in inherited members are expanded against the inheriting classhttps://github.com/mkdocstrings/python/issues/341#top
#342https://github.com/mkdocstrings/python/pull/342
https://github.com/llucax
llucaxhttps://github.com/llucax
on Sep 8, 2026https://github.com/mkdocstrings/python/issues/341#issue-5385540527
AutorefsHook.expand_identifierhttps://github.com/mkdocstrings/python/blob/8125b0d28b039693ff05b8caac981da47eb4cd7c/src/mkdocstrings_handlers/python/_internal/rendering.py#L805-L813
get_contexthttps://github.com/mkdocstrings/python/blob/8125b0d28b039693ff05b8caac981da47eb4cd7c/src/mkdocstrings_handlers/python/_internal/rendering.py#L842-L848
frequenz-quantitieshttps://github.com/frequenz-floss/frequenz-quantities
frequenz-sdk-pythonhttps://github.com/frequenz-floss/frequenz-sdk-python
Build loghttps://github.com/frequenz-floss/frequenz-sdk-python/actions/runs/34208898217/job/102004915946
pawamoyhttps://github.com/pawamoy
on Sep 22, 2026https://github.com/mkdocstrings/python/issues/341#event-31588966322
fix: Expand relative cross-references against the object the docstrin…https://github.com/mkdocstrings/python/commit/a9a4ca3bfd8ee361cd8f7aa63a5079b232adc837
a9a4ca3https://github.com/mkdocstrings/python/commit/a9a4ca3bfd8ee361cd8f7aa63a5079b232adc837
pawamoyhttps://github.com/pawamoy
completedhttps://github.com/mkdocstrings/python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#342https://github.com/mkdocstrings/python/pull/342
on Sep 22, 2026https://github.com/mkdocstrings/python/issues/341#event-31588966350
https://github.com/llucax
llucaxhttps://github.com/llucax
on Sep 24, 2026https://github.com/mkdocstrings/python/issues/341#issuecomment-5810180645
#344https://github.com/mkdocstrings/python/issues/344
Sign up for freehttps://github.com/signup?return_to=https://github.com/mkdocstrings/python/issues/341
Sign in to commenthttps://github.com/login?return_to=https://github.com/mkdocstrings/python/issues/341
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.