René's URL Explorer Experiment


Title: bug: `merge_init_into_class` renders inherited `__init__` source (leaks site-packages paths) · Issue #333 · mkdocstrings/python · GitHub

Open Graph Title: bug: `merge_init_into_class` renders inherited `__init__` source (leaks site-packages paths) · Issue #333 · mkdocstrings/python

X Title: bug: `merge_init_into_class` renders inherited `__init__` source (leaks site-packages paths) · Issue #333 · mkdocstrings/python

Description: Description of the bug With merge_init_into_class: true, the source block in templates/material/_base/class.html.jinja unconditionally prefers all_members["__init__"] over the class itself: {% if config.merge_init_into_class %} {% if "__...

Open Graph Description: Description of the bug With merge_init_into_class: true, the source block in templates/material/_base/class.html.jinja unconditionally prefers all_members["__init__"] over the class itself: {% if c...

X Description: Description of the bug With merge_init_into_class: true, the source block in templates/material/_base/class.html.jinja unconditionally prefers all_members["__init__"] over the class itsel...

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

X: @github

direct link

Domain: redirect.github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: `merge_init_into_class` renders inherited `__init__` source (leaks site-packages paths)","articleBody":"### Description of the bug\n\nWith `merge_init_into_class: true`, the `source` block in\n`templates/material/_base/class.html.jinja` unconditionally prefers\n`all_members[\"__init__\"]` over the class itself:\n\n```jinja\n{% if config.merge_init_into_class %}\n  {% if \"__init__\" in all_members and all_members[\"__init__\"].source %}\n```\n\n`all_members` includes inherited members, so when a class does not\ndefine `__init__` itself (e.g. any pydantic `BaseModel` subclass, with\n`preload_modules: [pydantic]` so griffe can resolve the base), the\nrendered source block is `pydantic.BaseModel.__init__` with a summary\nlike:\n\n> Source code in `.venv/lib/python3.10/site-packages/pydantic/main.py`\n\ninstead of the documented class's own file. Two problems:\n\n1. The environment-specific `.venv/...` path leaks into published docs.\n2. The source shown is the base class's `__init__`, which is not the\n   documented object's code at all.\n\nAdditionally, when the merged `__init__` has no source, the block\nrenders nothing rather than falling back to the class source.\n\n### To Reproduce\n\nVerified with mkdocs 1.6.1, mkdocstrings 1.0.4, mkdocstrings-python\n2.0.5, griffe 2.1.0, pydantic 2.13.4 on Python 3.10.\n\n```sh\nmkdir -p repro/src/pkg repro/docs && cd repro\npython -m venv .venv && . .venv/bin/activate\npip install mkdocs mkdocs-material \"mkdocstrings[python]\" pydantic\n```\n\n`src/pkg/__init__.py`:\n\n```python\nfrom pydantic import BaseModel\n\n\nclass Model(BaseModel):\n    \"\"\"A pydantic model without its own `__init__`.\"\"\"\n\n    x: int = 0\n```\n\n`docs/index.md`:\n\n```markdown\n::: pkg.Model\n```\n\n`mkdocs.yml`:\n\n```yaml\nsite_name: repro\ntheme:\n  name: material\nplugins:\n  - mkdocstrings:\n      handlers:\n        python:\n          paths: [src]\n          options:\n            merge_init_into_class: true\n            preload_modules: [pydantic]\n            show_source: true\n```\n\nBuild and inspect the rendered source block:\n\n```console\n$ mkdocs build\n$ grep -o \"Source code in \u003ccode>[^\u003c]*\u003c/code>\" site/index.html\nSource code in \u003ccode>.venv/lib/python3.10/site-packages/pydantic/main.py\u003c/code>\n```\n\nExpected: `src/pkg/__init__.py`.\n\nThe mechanism, shown at the griffe level (run from the same directory):\n\n```python\nimport sysconfig\n\nimport griffe\n\nloader = griffe.GriffeLoader(\n    search_paths=[\"src\", sysconfig.get_paths()[\"purelib\"]]\n)\nloader.load(\"pydantic\")\npkg = loader.load(\"pkg\")\nloader.resolve_aliases()\n\ncls = pkg[\"Model\"]\ninit = cls.all_members[\"__init__\"]\nprint(cls.relative_filepath)   # src/pkg/__init__.py\nprint(init.inherited)          # True\nprint(init.relative_filepath)  # .venv/lib/python3.10/site-packages/pydantic/main.py\n```\n\n### Expected behavior\n\nOnly use `__init__`'s source when the class defines it itself\n(griffe exposes `inherited` on the member); otherwise fall back to the\nclass's own source.\n\n### Environment information\n\n```bash\npython -m mkdocstrings_handlers.python._internal.debug  # | xclip -selection clipboard\n```\n\n- __System__: macOS-26.5.1-arm64-arm-64bit\n- __Python__: cpython 3.10.20 (\u003credacted>/.venv/bin/python3)\n- __Environment variables__:\n- __Installed packages__:\n  - `mkdocstrings-python` v2.0.5\n\n### Additional context\n\nI'm using a template override in\n`docs/templates/python/materialx/class.html.jinja`, wired\nup via the `custom_templates` option in `mkdocs.yaml`:\n\n```jinja\n{% extends \"_base/class.html.jinja\" %}\n\n{% block source %}\n  {% import \"language.html.jinja\" as lang with context %}\n  {% if config.show_source %}\n    {% if config.merge_init_into_class\n        and \"__init__\" in all_members\n        and not all_members[\"__init__\"].inherited\n        and all_members[\"__init__\"].source %}\n      {% with init = all_members[\"__init__\"] %}\n        \u003cdetails class=\"mkdocstrings-source\">\n          \u003csummary>{{ lang.t(\"Source code in\") }} \u003ccode>\n            {%- if init.relative_filepath.is_absolute() -%}\n              {{ init.relative_package_filepath }}\n            {%- else -%}\n              {{ init.relative_filepath }}\n            {%- endif -%}\n          \u003c/code>\u003c/summary>\n          {{ init.source|highlight(language=\"python\", linestart=init.lineno or 0, linenums=True) }}\n        \u003c/details>\n      {% endwith %}\n    {% elif class.source %}\n      \u003cdetails class=\"mkdocstrings-source\">\n        \u003csummary>{{ lang.t(\"Source code in\") }} \u003ccode>\n          {%- if class.relative_filepath.is_absolute() -%}\n            {{ class.relative_package_filepath }}\n          {%- else -%}\n            {{ class.relative_filepath }}\n          {%- endif -%}\n        \u003c/code>\u003c/summary>\n        {{ class.source|highlight(language=\"python\", linestart=class.lineno or 0, linenums=True) }}\n      \u003c/details>\n    {% endif %}\n  {% endif %}\n{% endblock source %}\n```","author":{"url":"https://github.com/cdwilson","@type":"Person","name":"cdwilson"},"datePublished":"2026-07-09T15:37:45Z","url":"https://github.com/mkdocstrings/python/issues/333"}

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:d067e1fe-09b3-af25-ff95-2b326154a56d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9326:2E5258:537E59:74287B:6AF855F5
html-safe-noncee17b695d3cf218cb088fee6410544aaaffb79c10358de483d27647a582d429f7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzI2OjJFNTI1ODo1MzdFNTk6NzQyODdCOjZBRjg1NUY1IiwidmlzaXRvcl9pZCI6IjEzMTA2NDU1NjQ2NDI3MTEwMjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc0f71935b39a4c6110ae66fe221c85badd413e045598be062c9de3c5b1067067
hovercard-subject-tagissue:4847679963
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/333/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ccb0b72f7328c23f97d0d475ebaf35cb4d70b7dbc81df252ae8355b690f55873/mkdocstrings/python/issues/333
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ccb0b72f7328c23f97d0d475ebaf35cb4d70b7dbc81df252ae8355b690f55873/mkdocstrings/python/issues/333
og:image:altDescription of the bug With merge_init_into_class: true, the source block in templates/material/_base/class.html.jinja unconditionally prefers all_members["__init__"] over the class itself: {% if c...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecdwilson
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://redirect.github.com/mkdocstrings/python/issues/333#start-of-content
https://redirect.github.com/
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmkdocstrings%2Fpython%2Fissues%2F333
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://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmkdocstrings%2Fpython%2Fissues%2F333
Sign uphttps://redirect.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://redirect.github.com/mkdocstrings/python/issues/333
Reloadhttps://redirect.github.com/mkdocstrings/python/issues/333
Reloadhttps://redirect.github.com/mkdocstrings/python/issues/333
mkdocstringshttps://redirect.github.com/mkdocstrings
pythonhttps://redirect.github.com/mkdocstrings/python
Codehttps://redirect.github.com/mkdocstrings/python
Issues6 (6)https://redirect.github.com/mkdocstrings/python/issues
Pull requestshttps://redirect.github.com/mkdocstrings/python/pulls
Discussionshttps://redirect.github.com/mkdocstrings/python/discussions
Actionshttps://redirect.github.com/mkdocstrings/python/actions
Security and qualityhttps://redirect.github.com/mkdocstrings/python/security
Insightshttps://redirect.github.com/mkdocstrings/python/pulse
https://redirect.github.com/mkdocstrings/python
New issuehttps://redirect.github.com/login?return_to=https://github.com/mkdocstrings/python/issues/333
New issuehttps://redirect.github.com/login?return_to=https://github.com/mkdocstrings/python/issues/333
#338https://github.com/mkdocstrings/python/pull/338
bug: merge_init_into_class renders inherited __init__ source (leaks site-packages paths)https://redirect.github.com/mkdocstrings/python/issues/333#top
#338https://github.com/mkdocstrings/python/pull/338
https://redirect.github.com/pawamoy
featureNew feature or requesthttps://github.com/mkdocstrings/python/issues?q=state%3Aopen%20label%3A%22feature%22
https://github.com/cdwilson
cdwilsonhttps://github.com/cdwilson
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#issue-4847679963
cdwilsonhttps://redirect.github.com/cdwilson
pawamoyhttps://redirect.github.com/pawamoy
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#event-27773017147
cdwilsonhttps://redirect.github.com/cdwilson
unconfirmedThis bug was not reproduced yethttps://redirect.github.com/mkdocstrings/python/issues?q=state%3Aopen%20label%3A%22unconfirmed%22
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#event-27773021534
https://redirect.github.com/pawamoy
pawamoyhttps://redirect.github.com/pawamoy
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#issuecomment-4927080503
@cdwilsonhttps://github.com/cdwilson
#106https://github.com/mkdocstrings/python/issues/106
pawamoyhttps://redirect.github.com/pawamoy
not plannedhttps://redirect.github.com/mkdocstrings/python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#event-27773999066
pawamoyhttps://redirect.github.com/pawamoy
featureNew feature or requesthttps://redirect.github.com/mkdocstrings/python/issues?q=state%3Aopen%20label%3A%22feature%22
unconfirmedThis bug was not reproduced yethttps://redirect.github.com/mkdocstrings/python/issues?q=state%3Aopen%20label%3A%22unconfirmed%22
on Jul 9, 2026https://github.com/mkdocstrings/python/issues/333#event-27774004696
https://redirect.github.com/cdwilson
cdwilsonhttps://redirect.github.com/cdwilson
on Aug 16, 2026https://github.com/mkdocstrings/python/issues/333#issuecomment-5306139192
@pawamoyhttps://github.com/pawamoy
tinydantic/tinydantic#131https://github.com/tinydantic/tinydantic/issues/131
mentionedhttps://github.com/tinydantic/tinydantic/issues/131#issuecomment-5278711958
pawamoyhttps://redirect.github.com/pawamoy
on Aug 16, 2026https://github.com/mkdocstrings/python/issues/333#event-29522466421
https://redirect.github.com/pawamoy
pawamoyhttps://redirect.github.com/pawamoy
on Aug 16, 2026https://github.com/mkdocstrings/python/issues/333#issuecomment-5307532844
cdwilsonhttps://redirect.github.com/cdwilson
on Aug 17, 2026https://github.com/mkdocstrings/python/issues/333#event-29538481326
fix: Don't render environment paths in source block labelshttps://github.com/cdwilson/mkdocstrings-python/commit/181fcc9b2f7a94180d96a3d293cdce8fc5fb56fb
181fcc9https://github.com/cdwilson/mkdocstrings-python/commit/181fcc9b2f7a94180d96a3d293cdce8fc5fb56fb
fix: Don't render environment paths in source block labelshttps://github.com/cdwilson/mkdocstrings-python/commit/cc255c18ff14c23ab9200391fb03a954a107efd7
cc255c1https://github.com/cdwilson/mkdocstrings-python/commit/cc255c18ff14c23ab9200391fb03a954a107efd7
fix: Don't render environment paths in source block labelshttps://github.com/cdwilson/mkdocstrings-python/commit/f0f1871ec6c10e03c989051cfe5ad5b90d1bf33a
f0f1871https://github.com/cdwilson/mkdocstrings-python/commit/f0f1871ec6c10e03c989051cfe5ad5b90d1bf33a
fix: Don't render environment paths in source block labelshttps://github.com/cdwilson/mkdocstrings-python/commit/5400e1c5981cac0dd7ce2d85ac01a2552d68eee4
5400e1chttps://github.com/cdwilson/mkdocstrings-python/commit/5400e1c5981cac0dd7ce2d85ac01a2552d68eee4
pawamoyhttps://redirect.github.com/pawamoy
on Aug 17, 2026https://github.com/mkdocstrings/python/issues/333#event-29570860660
fix: Don't render environment paths in source block labelshttps://github.com/mkdocstrings/python/commit/84ba73e8ca4e54afd29a4fe67b8bfb022e76c794
84ba73ehttps://github.com/mkdocstrings/python/commit/84ba73e8ca4e54afd29a4fe67b8bfb022e76c794
pawamoyhttps://redirect.github.com/pawamoy
completedhttps://redirect.github.com/mkdocstrings/python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#338https://github.com/mkdocstrings/python/pull/338
on Aug 17, 2026https://github.com/mkdocstrings/python/issues/333#event-29570860782
Sign up for freehttps://redirect.github.com/signup?return_to=https://github.com/mkdocstrings/python/issues/333
Sign in to commenthttps://redirect.github.com/login?return_to=https://github.com/mkdocstrings/python/issues/333
pawamoyhttps://redirect.github.com/pawamoy
featureNew feature or requesthttps://github.com/mkdocstrings/python/issues?q=state%3Aopen%20label%3A%22feature%22
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.