Skip to content

Use docstrings of base classes to document inherited parameters and attributes - #951

Merged
mauvilsa merged 2 commits into
mainfrom
fix-attr-docstrings
Aug 10, 2026
Merged

Use docstrings of base classes to document inherited parameters and attributes#951
mauvilsa merged 2 commits into
mainfrom
fix-attr-docstrings

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Docstrings were only looked up in the class itself (plus one extra MRO level between dataclasses), so inherited parameters and attributes ended up undocumented in the help. Most visible with docstring_parse_attribute_docstrings=True on pydantic models, where every field declared in a base model lost its description.

Changes in _optionals.py:

  • parse_docs now collects docstrings from the entire MRO for any kind of class, not only one level between dataclasses. Sources are visited base-classes-first so a derived class overrides what it redefines, and empty descriptions no longer overwrite an inherited one.
  • get_doc_short_description walks the MRO for the nearest class docstring, stopping at the first class that defines its own __init__ since base classes no longer describe the constructor from there on.
  • Base classes that only provide machinery (object, abc.ABC, typing.Generic, enum.Enum, pydantic/attrs bases) are skipped as doc sources. This also fixes group descriptions leaking Create a new model by parsing and validating input data from keyword arguments for pydantic models without a docstring, and the equivalent for abc.ABC.

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

@mauvilsa mauvilsa added bug Something isn't working enhancement New feature or request labels Aug 10, 2026
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a9fe926) to head (3fc73f2).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #951   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8242      8252   +10     
=========================================
+ Hits          8242      8252   +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit 79d9e3e into main Aug 10, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the fix-attr-docstrings branch August 10, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant