- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add option for autodoc to hide undocumented parameters but show undocumented return types #9792
add option for autodoc to hide undocumented parameters but show undocumented return types #9792
Conversation
Thank you for your proposal. Nice proposal. I need to know more cases that are difficult to describe the return value. Do you have real examples? It would be helpful for me to imagine how this proposal is worth.
Actually, the new option generates type hints to the documented parameters and the return value. So current proposal does not mention about the latter one. So "documented_params_and_returnvalue" describes the behavior more than now.
LGTM.
Yes, please. You also have to add testcases for the new option. Please refer |
Hm, I would not say it is difficult to describe the return value. On the contrary, there are cases where the return value is perfectly described by its type. I don't have a real-world example that I can disclose, but here is a reasonable fictional example: Assume we use """Serialize this object to be transmittable.""" The method has no parameters, so autodoc will add no annotations. Now there might be the question: To what is it serialized? """Serialize this object to be transmittable.
:return: the serialized object
:rtype bytes:
""" Now we have two extra lines in the documentation and one of them is redundant information. Our documentation gets bloated by that (imagine 20 more of this kind). The description of the return value is not really helpful, but we need it for autodoc to generate the return type annotation. Why don't we just use Assume we are writing a library and use sphinx to generate an API documentation for a 3rd party that'll use the lib. Internally we use some exposed methods in a special way, which we achieve by setting an optional flag parameter. We don't want this flag parameter to be documented, because the library users are not supposed to use this flag. Yes, we could use a level of redirection to hide the internal methods, but that bloats our code just to make sphinx work the way we need. Also it will break extensions like Now, assume we use the proposed feature ( In this case the return type is added without the need for the return value description. The resulting docstring is concise, contains all information needed to document how this method is to be used and no redundant information: """Serialize this object to be transmittable.
:rtype bytes:
"""
I fully agree. I think your proposed option name can be misunderstood:
Ok, I will do so, thanks for the pointers! |
84d0468
to
680bde5
Compare
I added the new option to the documentation (target v4.3.) and wrote two tests with scenarios similar to the ones used for While testing the implementation I realized an oversight I did and corrected it: If the return type is I ran tox with mypy and flake8 (both: no issues) and test-generated the documentation. I think this should be it, please let me know if there is something I should change or add. 👍 |
Thank you for your explanation. It opened up my eyes :-) Now I perfectly understand your situation. +1 for adding the option. The remaining task is naming. I don't still satisfy your (and my) proposal. Indeed, they surely describe their behavior correctly. But they are too descriptive and long. I think the new option will be used more than BTW, the |
Note: I think this will be merged after the 4.3.0 release. So I changed the milestone of this PR to 4.4.0 now. |
ecffab9
to
58a0190
Compare
58a0190
to
33bebf5
Compare
Hi, I rebased the branch. Did you have an idea for the naming? |
I and @shimizukawa discussed the name of this option. And we determined to call it |
…ed_params to documented_params
Merged. Thank you for your great work! |
Add new option for
autodoc_typehints_description_target
to include undocumented return values but not undocumented parameters.Feature or Bugfix
Purpose
def parse_int(val: str) -> int
) and instead of writing in the docstring:return: the integer
it is sufficient to see:rtype: int
.autodoc_typehints_description_target = "documented"
)autodoc_typehints_description_target = "documented_params"
that will suppress type annotation for undocumented parameters, but adds type annotations for undocumented return values.Detail
"documented_params"
) because it does not express that return types are still added. Maybe something link"documented_and_returnvalues"
would be better?augment_descriptions_with_types()
to pass the info if the return type should be annotated or not. This could also be solved by passing the config object. Would that be better?