-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: add checks on the returns section in the docstrings (#23138) #23432
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
Changes from 7 commits
e0f9689
20b32e7
f2d6449
0d34a88
b09c322
a556925
a1384d4
2f3f5bf
e62de14
fdad765
58a0a91
a116a49
5ea7881
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -527,8 +527,35 @@ def validate_one(func_name): | |
err.message)) | ||
|
||
if doc.is_function_or_method: | ||
if not doc.returns and "return" in doc.method_source: | ||
errs.append('No Returns section found') | ||
if not doc.returns: | ||
if "return" in doc.method_source: | ||
igorfassen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errs.append('No Returns section found') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @datapythonista @WillAyd : How does this validation handle situations where we use an empty (BTW, I realize that this already in the codebase, but it only struck me just now) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afaik, in Python all the functions return I don't think the validation checks in the code whether there is a return or not. This change should be to avoid giving a name to what is being returned if it's just a single value. In my opinion, saying that the function We want to name the values returned if the return is a tuple, for example Does this make sense to you @gfyoung? Update: Just saw the code (sorry, reviewing from the phone, which is tricky). I forgot we were checking the code for a return statement. I think we should change and use a regex that doesn't capture the bare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so replacing (maybe I should have another look at what's in doc.method_source) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created #23488 to take care of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need a regex for this? Wouldn't it just be better documented as an optional return value if such a branch is possible to hit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean, but it's better if you mention this approach in #23488, where this will be implemented. |
||
else: | ||
returns_errs = [] | ||
if len(doc.returns) == 1 and doc.returns[0][1]: | ||
returns_errs.append('The first line of the Returns section ' | ||
'should contain only the type, unless ' | ||
'multiple values are being returned.') | ||
missing_desc, missing_cap, missing_period = False, False, False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With that said is this even required? It seems like you could simplify things without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
for name, type_, desc in doc.returns: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the value of I'd still like to have the names of the return fields that are failing in the returned error messages, and not give the user something like:
@WillAyd can you propose your preferred solution for this? For me the best would be the original one:
I think with the way it is implemented now it should be perfectly readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when there is a single return and the first line is correctly written (ie no name is given), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm totally indifferent as I really think this is an edge case. Whatever can be done simply and accurately works for me! |
||
desc = ''.join(desc) | ||
missing_desc = missing_desc or not desc | ||
missing_cap = missing_cap or desc and not desc[0].isupper() | ||
missing_period = (missing_period | ||
or desc and not desc.endswith('.')) | ||
if missing_desc: | ||
returns_errs.append('Return value has no description.') | ||
if missing_cap: | ||
returns_errs.append('Return value description should start ' | ||
'with a capital letter.') | ||
if missing_period: | ||
returns_errs.append('Return value description should finish ' | ||
'with ".".') | ||
if returns_errs: | ||
errs.append('Errors in Returns section') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you are emulating what you saw with the parameters section, but do we need this? Doesn't look like we are testing for it and I don't necessarily see the utility of it alongside the actual errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, it's not as useful here as in the parameters section, as functions with multiple values are quite rare |
||
for returns_err in returns_errs: | ||
errs.append('\t{}'.format(returns_err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this better as is. Appending seems more idiomatic than adding an intermediary list comp |
||
|
||
if not doc.yields and "yield" in doc.method_source: | ||
errs.append('No Yields section found') | ||
|
||
|
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.
We can test this now. I guess we can't know whether we're missing the type or the description. We should return a message that considers both, so the user always know what to do. And test this case.
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.
indeed, with the current modifications, in this case the error message is Return value has no description
should I replace it by something like Return value has no type or description ?
(well, in the case where a tuple is returned, that would mean that both type and name are missing)
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.
while writing that, I realize that I do not check, in the case of multiple return values, if all of them have both a name and a type