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 to include docstrings with stubgen #13284
Conversation
Add a --include-docstrings flag to stubgen This was suggested in python#11965. When using this flag, the .pyi files will include docstrings for Python classes and functions and for C extension functions.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
|
I gave it some more thought and I will have to fix another mistake - Thanks @sobolevn for you comments, I'll fix it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@hauntsaninja Can you review this PR? I would definitely welcome this feature :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
can you also consider adding variable docstring? a_variable: int = 0
"""this is the docstring for a_variable"""class Fields_Obj:
DefaultValue=None
"""Get/set the default value of the data field"""https://stackoverflow.com/questions/6060813/how-to-document-fields-and-properties-in-python |
|
Is there any ETA for this feature to be merged? |
|
@chylek Could you please resolve merge conflicts? This adds a frequently requested feature, so I would merge this (unless there are objections from other maintainers). |
This comment has been minimized.
This comment has been minimized.
mypy/stubgenc.py
Outdated
| function=name, | ||
| args=", ".join(args), | ||
| ret=strip_or_import(signature.ret_type, module, known_modules, imports), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this part completely repeats the other branch? If yes, then please use
if foo:
bar
bazinstead of
if foo:
bar
baz
else:
bazThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more precise, in this case you need:
bar
if foo:
baz
since you always need a type, and docstring should come after (only if the flag is enabled)
|
@chylek While a docs issue unrelated to your PR is being fixed, could you please fix a style issue I found? |
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Thank you for merging my pull request and for the guidance and feedback. |
Description
Closes #11965.
Add a --include-docstrings flag to stubgen. This was suggested in #11965 along with a use case.
When using this flag, the .pyi files will include docstrings for Python classes and functions and for C extension functions.
The flag is optional and does not change the default stubgen behaviour. When using the flag, the resulting function stubs that contain docstring will no longer be one-liners, but functions without a docstring still retain the default one-liner style.
Example input:
output:
Test Plan
Tests
testIncludeDocstringsandtestIgnoreDocstringswere added totest-data/unit/stubgen.testto ensure the code works as intended. All other tests passed as well.C extension docstrings are tested using an updated bash script
misc/test_stubgenc.shwith test data intest-data/pybind11_mypy_demo/stubgen-include-docsin same fashion as in an already existing test.