-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Google style docstrings throw warning target not found: optional #11376
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
Comments
It appears that using Now, what is weird is that the reST lines contain After some digging, you get that reST document: <literal_strong>
x (
<pending_xref py:class="True" py:module="testmodule" refdomain="py" refexplicit="False" refspecific="True" reftarget="int" reftype="class">
<literal_emphasis>
int
<literal_emphasis>
,
<pending_xref py:class="True" py:module="testmodule" refdomain="py" refexplicit="False" refspecific="True" reftarget="optional" reftype="class">
<literal_emphasis>
optional
)
<literal_strong>
y (
<pending_xref py:class="True" py:module="testmodule" refdoc="index" refdomain="py" refexplicit="False" reftarget="int" reftype="class" refwarn="False">
<literal classes="xref py py-class">
int, optional
) In other words, the handler for type fields considers |
Awesome, let me know if I can help! |
Well, actually... I totally forgot about this ! I'll be busy this week but I'll probably have time this week-end. If you want to help / contribute, I'd suggest debugging Sphinx or directly by cloning this repository, modifying the sources, creating a fake test and printing things here and there (only works if the issue is Sphinx related). If this is a docutils issue, digging into the codesource is likely to be complex. |
Oh I'm afraid I'm not familiar enough with Sphinx to give useful insights. I'm unlikely to get some bandwith to have a look at it soon anyway. Also, I don't know where this warning is triggered in the source code so it's kinda hard to know where to start |
Since you are in nitpicky mode, the warning is emitted by the We need to find which transformation is responsible for creating those
you can think of this as a single group for a parameter and its type. This is represented by def func(x, y=2, z=3):
"""_summary_
Args:
x (int): the x
y (int, optional): the y
z (:obj:`int`, optional): the z
"""
pass Then, the Napoleon parser transforms the docstring into: def func(x, y=2, z=3):
"""_summary_
:param x: the x
:type x: int
:param y: the y
:type y: int, optional
:param z: the z
:type z: :obj:`int`, optional
"""
pass Now, the important transformation is done by <desc classes="py function" desctype="function" domain="py" nocontentsentry="False" noindex="False" noindexentry="False" objtype="function">
<desc_signature _toc_name="func()" _toc_parts="('testmodule', 'func')" class="" classes="sig sig-object" fullname="func" ids="testmodule.func" module="testmodule">
<desc_addname classes="sig-prename descclassname" xml:space="preserve">
testmodule.
<desc_name classes="sig-name descname" xml:space="preserve">
func
<desc_parameterlist xml:space="preserve">
<desc_parameter xml:space="preserve">
<desc_sig_name classes="n">
x
<desc_parameter xml:space="preserve">
<desc_sig_name classes="n">
y
<desc_sig_operator classes="o">
=
<inline classes="default_value" support_smartquotes="False">
2
<desc_parameter xml:space="preserve">
<desc_sig_name classes="n">
z
<desc_sig_operator classes="o">
=
<inline classes="default_value" support_smartquotes="False">
3
<desc_content> Then, <desc_content>
<paragraph>
_summary_
<field_list>
<field>
<field_name>
param x
<field_body>
<paragraph>
the x
<field>
<field_name>
type x
<field_body>
<paragraph>
int
<field>
<field_name>
param y
<field_body>
<paragraph>
the y
<field>
<field_name>
type y
<field_body>
<paragraph>
int, optional
<field>
<field_name>
param z
<field_body>
<paragraph>
the z
<field>
<field_name>
type z
<field_body>
<paragraph>
<pending_xref py:class="True" py:module="testmodule" refdoc="index" refdomain="py" refexplicit="False" reftarget="int" reftype="obj" refwarn="False">
<literal classes="xref py py-obj">
int
, optional Now:
After that, we call {
'x': [<#text: 'int'>],
'y': [<#text: 'int, optional'>],
'z': [<pending_xref: <literal...>>, <#text: ', optional'>]}
} Then, you have this: sphinx/sphinx/util/docfields.py Lines 197 to 217 in ba74082
Here, the sphinx/sphinx/domains/python.py Lines 404 to 424 in ba74082
And this is where the thing gets bad. Recall that we are in the context that the node is a single text node, e.g., delims = r'(\s*[\[\]\(\),](?:\s*o[rf]\s)?\s*|\s+o[rf]\s+|\s*\|\s*|\.\.\.)' tells you that if you put something like I cannot tell for the other domains, but here is what I would do for Python:
|
I tried searching in the Google Python Style Guide and there's no mention of using the trailing
|
Remove the use of the "optional" hint from the docstrings to address the following Sphinx warnings. The "optional" hint is not supported by Sphinx and was inconsistently specified for keyword arguments with default values. ``` [...] /path/to/index.py:docstring of idc_index.index.IDCClient.download_from_selection:1: WARNING: py:class reference target not found: optional /path/to/index.py:docstring of idc_index.index.IDCClient.get_dicom_series:1: WARNING: py:class reference target not found: optional /path/to/index.py:docstring of idc_index.index.IDCClient.get_dicom_studies:1: WARNING: py:class reference target not found: optional /path/to/index.py:docstring of idc_index.index.IDCClient.get_patients:1: WARNING: py:class reference target not found: optional [...] ``` For more details, see the related Sphinx issue: * sphinx-doc/sphinx#11376 (Google style docstrings throw warning target not found: optional)
Describe the bug
When trying to document a function with Google Style docstrings, I get the following warning:
I think "optional" is identified as a type, when it shouldn't.
How to Reproduce
conf.py
mycode.py
index.rst
Environment Information
Sphinx extensions
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: