-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
bug: Google docstrings: no support for non-multiple or non-named values in Yields section #263
Comments
Hey again @the-13th-letter, thanks for the great report. I agree with the suggestion to make |
:)
I thought about that as well, but I don't have a good case for this. Just a couple of disjointed random thoughts.
So yeah, I don't really know what to do with Receives. And I don't think I'm the right person to ask about that either, because I use neither Receives nor the NumPy docstring format in general. |
Thanks for your thoughts.
Then I'd vote we make "Receives" consistent with the rest, for the sake of consistency. Both Google-style and Numpydoc-style are underspecified, so I always allowed myself some wiggle-room with the goal of making both styles more similar, structurally speaking. |
…s parsing The Returns, Yields and Receives section parsers only really differ in their fallbacks and the names of their configuration settings, not so much in their general parsing behavior and the expected formatting of the section contents. This commit is an attempt to factor out the following functionality: * Read the section contents as a single block, or as multiple blocks, depending on the `multiple` setting. * Parse each block's first line as a named parameter, or an unnamed parameter, depending on the `named` setting. * Unpack `Generator` and `Iterator` types in the return annotation. Optionally error out if the return annotation is not of these types. * Optionally destructure the return tuple if `multiple` is in effect. Issue-263: #263
[Griffe now handles non-multiple yields and returns similarly.] [YIELDS] There is thus no need for an empty argument name and type annotation. [YIELDS]: mkdocstrings/griffe#263
Description of the bug
In Google-style docstrings, Griffe (and mkdocstrings-python) don't treat Yields and Returns sections identically when it comes to returning multiple and/or named items. In particular, for Returns sections, the
returns_multiple_items
andreturns_named_values
configuration options exist and do as advertised. For Yields sections, no such dedicated options exist, and those options are ignored. As a consequence, for multiple values, there is no way to document the yielded tuple of values as a tuple; it must be faked via a single item tuple, the type repeated (actually: overruled) in the docstring, and the description must be written with hanging indentation.Note: The Google style guide, at least as of version 8487c08, treats "Yields:" and "Returns:" identically and requires them to document a tuple of returned values as a tuple, explicitly forbidding the
numpy
-style named tuple return values.To Reproduce
Given the following example module
yielding_test
and parsed with options
returns_multiple_items
andreturns_named_value
as false, the dump from Griffe shows thatyield_one
supposedly has two return values (reusing the type annotation for the "second" return value) and thatyield_two
also has two return values, the second one being unnamed.Full traceback
Full Griffe dump
Note that the
docstring.parsed[1].value
arrays contain one item for thereturns_*
functions, and two items for theyields_*
functions. The latter is unexpected.Expected behavior
On a high level, I expect the output for the
yields_one
andyields_two
to be similar to the respectivereturn_one
andreturn_two
output (except for"kind": "returns"
vs."kind": "yields"
).On a lower level, I expect the
returns_multiple_items
andreturns_named_value
options to also be respected when parsing Yields sections.Environment information
Running Griffe v0.44.0 on Linux, installed via PyPI.
Additional context
Support for non-multiple return values and named return values seems to have originated in #137 (0.35.0, 2023-08-24) and #196 (0.36.0, 2023-09-01). In both cases only the Returns section handling was adapted, and Yields section handling was left untouched.
Additional comments
I do not advocate adding additional configuration options
yields_multiple_items
/yields_named_value
or similar to handle this case. It makes sense to reuse the existingreturns_*
options, because Google style treats Returns and Yields so similarly.I tried my hand at copying the respective code from
src/griffe/docstrings/google.py:_read_returns_section
to_read_yields_section
, but I had trouble setting up new tests intests/test_docstrings/test_google.py
. I don't know enough about Griffe's internals (orpytest
) to properly debug whether the copied code is bad or whether my tests are bad. (Or both.) So, no pull request, just a bug report. Sorry.The text was updated successfully, but these errors were encountered: