Use docstrings of base classes to document inherited parameters and attributes - #951
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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=Trueon pydantic models, where every field declared in a base model lost its description.Changes in
_optionals.py:parse_docsnow 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_descriptionwalks 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.object,abc.ABC,typing.Generic,enum.Enum,pydantic/attrsbases) are skipped as doc sources. This also fixes group descriptions leakingCreate a new model by parsing and validating input data from keyword argumentsfor pydantic models without a docstring, and the equivalent forabc.ABC.Before submitting