Skip to content

Fix: In packages/griffelib/src/griffe/_internal/merger.py,... - #483

Closed
M001N wants to merge 1 commit into
mkdocstrings:mainfrom
M001N:oss-engine/e27b6eec-e96e1653
Closed

Fix: In packages/griffelib/src/griffe/_internal/merger.py,...#483
M001N wants to merge 1 commit into
mkdocstrings:mainfrom
M001N:oss-engine/e27b6eec-e96e1653

Conversation

@M001N

@M001N M001N commented Aug 17, 2026

Copy link
Copy Markdown

Summary

  1. Changed _merge_stubs_docstring to overwrite obj.docstring whenever stubs.docstring exists AND (obj has no docstring OR obj.analysis == 'dynamic'), leaving statically-analyzed genuine docstrings untouched. 2) In _merge_overload_annotations, added a docstring fallback: if the base function has no docstring or is dynamically analyzed, take the docstring from the first overload that has one, before merging annotations.

Problem

mkdocstrings/griffe issue reference: #447

Root Cause

In packages/griffelib/src/griffe/_internal/merger.py, _merge_stubs_docstring(obj, stubs) used if not obj.docstring and stubs.docstring -- it treated 'has any docstring' as sufficient reason to keep the runtime object's docstring, without checking whether that docstring was genuinely authored (obj.analysis == 'static'/None) versus an auto-generated placeholder from runtime inspection (obj.analysis == 'dynamic'), even though griffe's Object model already tracks this via the analysis: Literal['static','dynamic'] | None attribute (set by the inspector for dynamically-analyzed members). Separately, _merge_overload_annotations(function, overloads) merged parameter/return type annotations from @overload stub signatures onto the base function but never propagated any overload's docstring onto it.

Testing

PASS - all 9 tests in test_merger.py pass (3 new + 6 existing); full suite (minus unrelated test_api.py which fails to import due to missing optional 'mkdocstrings' dependency in this environment, and test_git.py which fails due to a missing pytest-git plugin fixture, both pre-existing/unrelated to this change) shows 1742 passed, 22 skipped, 0 failures caused by this change.

Related Issue

#447

…ocstrings#447)

_merge_stubs_docstring() only filled in a docstring when the runtime
object had none at all, so an auto-generated placeholder docstring
from dynamic/runtime inspection (e.g. a SWIG/pybind11 C-level
signature string) was never replaced by the real, human-authored
docstring from a .pyi stub. Now it also overwrites when the object's
analysis is 'dynamic', while still leaving genuine statically-analyzed
docstrings untouched.

Also propagate an overload's docstring onto the base function when
merging overload-only stub methods, for the same dynamic/missing
docstring cases.
@pawamoy

pawamoy commented Aug 17, 2026

Copy link
Copy Markdown
Member

Thanks @M001N but we already have a PR for this: #481. Let me know if I misunderstood the changes here.

@pawamoy pawamoy closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants