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
Fix Python docstring type handling bug #10738
Conversation
Is the A |
@AA-Turner Yeah, you can see an example here: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
I've noticed the issue in projects like pytorch/captum. |
The link you provided is from the now-archived A |
https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html seems to be the up-to-date copy. |
@AA-Turner So, actually I may have confused Google's style guide with NumPy's style guide. NumPy's official style guidelines show Google's style guide though doesn't seem to explicitly mention it: https://google.github.io/styleguide/pyguide.html Edit: I see you found a google style guide that shows |
I entirely forgot that this PR doesn't touch A |
@AA-Turner Yeah, we can do that. Though I'm not 100% sure of the regex works as intended. My usage of the or operator slightly removed the spaces around Instead of outputting this:
It now outputs this:
It's a subtle difference of |
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@AA-Turner We can merge the PR now in its current form as it resolves the issue! Example: The |
Please add tests ensuring the behaviour doesn't regress in the future. A |
I have a slight concern over this change in that it encourages non-standard descriptions of typing -- for example if I had an object that was a I don't know if napoleon supports the type-annotation format though, and cannot test at the moment (on mobile). A |
@AA-Turner Do you happen to know which testing file I should add the tests to? And yeah, that could be a better format. Though using Also, as far as I'm aware, napoleon handles
|
See tests/test_ext_napoleon_docstring.py, around line 160 for an exemplar. Thanks for confirming the 'proper' style works. Please also add a CHANGES entry and add yourself to AUTHORS. A |
@AA-Turner Thanks! I've added myself to the AUTHORS file and added a new test for the changes. For the CHANGES file, I wasn't 100% sure what to say for the change, so let me know if I need to change it or anything else |
So, the tests don't currently seem to fail if the changes in this PR haven't been introduced. I think that part of the existing code may have already been capable of handing cases with ' |
@AA-Turner Testing now verifies that functionality introduced in this PR remains present. As the changes in this PR were on a single line in I think that this PR is finally ready for merging! |
Looks good otherwise, please could you also look at the flake8 failure and then ping me. A |
@AA-Turner I've fixed the formatting for flake8 |
Thanks Ben! A |
This PR ensures that NumPy style docstrings using '
of
' are properly handled.For example:
According to the regex used here: https://github.com/sphinx-doc/sphinx/blob/master/sphinx/domains/python.py#L381, only some of the variables in the above function's docstring will be properly handled. Anything with '
of
' in it will not be properly separated by the regex code. This PR fixes this issue.If this PR is on the wrong branch, let me know!
Feature or Bugfix
Purpose
Detail
Below are some examples of failures made visible by using Intersphinx. Notably types using '
of
' are not properly hyperlinked.Relates