-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
require Return section only if return is not None nor commentary #25008
require Return section only if return is not None nor commentary #25008
Conversation
Hello @dluiscosta! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 19, 2019 at 06:04 Hours UTC |
Added another "return" occurrence to the docstring in the test, on the beginning of a line. |
Codecov Report
@@ Coverage Diff @@
## master #25008 +/- ##
==========================================
+ Coverage 92.38% 92.38% +<.01%
==========================================
Files 166 166
Lines 52401 52401
==========================================
+ Hits 48409 48410 +1
+ Misses 3992 3991 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25008 +/- ##
==========================================
- Coverage 91.73% 87.76% -3.98%
==========================================
Files 173 173
Lines 52839 57856 +5017
==========================================
+ Hits 48472 50775 +2303
- Misses 4367 7081 +2714
Continue to review full report at Codecov.
|
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.
I think we should use a more reliable approach, see comments.
scripts/validate_docstrings.py
Outdated
gathered.extend(gather_returns(child)) | ||
return gathered | ||
# Walk the tree recursively and gather the return nodes. | ||
return_values = [r.value for r in gather_returns(root)] |
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.
As opposing to using ast.walk()
to iterate over all the nodes on the method's AST, here I'm recursively walking the tree myself.
The reason for that is to respect cases like the following:
def A():
def B():
return "Hello World!"
print(B())
return None
In this case, there is a inner function which returns a string, but the function being evaluated itself always return None, thus shouldn't have a Returns section on the docstring.
If I read all the nodes indiscriminately, as happens with ast.walk()
, I can't distinguish returns inside nested functions from returns on the function actually being evaluated. If I search trough it myself, though, I can prune the recursion when I reach a (nested) function node, thus ignoring it's entire subtree and possible return nodes in it.
I'd appreciate some help understanding the reason for the current Travis fail. Other than that, I have made the suggested changes and apparently fixed the previous problems, @datapythonista, @WillAyd. |
Travis failure is unrelated to your change and was resolved in #25225 . If you can merge master and re push should go away |
Merge updated master to solve Travis issue.
Thanks @WillAyd, solved it. |
scripts/validate_docstrings.py
Outdated
if tree: | ||
root = tree[0] | ||
|
||
def gather_returns(node): |
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.
Hmm is there any way to simplify what is going on here? Is there no way to extract the .returns
from the AST directly instead of having to recurse everything?
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.
In our case, there isn't.
The AST provides the .walk()
method to iterate through nodes. According to the doc, it
is useful if you only want to modify nodes in place and don’t care about the context.
Without context, there is no way to tell if a return node is inside a nested inner function or not, which is needed for one of the requirements raised by @datapythonista.
I explain this a bit further here.
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.
looks good, just few comments
if True: | ||
return | ||
else: | ||
return None |
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.
can you add a test for a property that returns something (without the Returns section, which is the correct).
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.
such a test was already present before this PR:
def return_not_documented(self):
"""
Lacks section for Returns
"""
return "Hello world!"
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.
it is negative test, not like the one being commented here, so it's inside the BadReturns class
Co-Authored-By: dluiscosta <dluiscosta@gmail.com>
I don't understand why the tests are failing. Locally, everything is fine. I tried once again to merge master, which had solved a previous problem, but this time it didn't help. |
@dluiscosta can you merge master? Should resolve Py27 failure |
Hey @datapythonista, @WillAyd, is there something left to be done here? |
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.
OK by me - @datapythonista
Thanks @dluiscosta! |
* upstream/master: (110 commits) DOC: hardcode contributors for 0.24.x releases (pandas-dev#25662) DOC: restore toctree maxdepth (pandas-dev#25134) BUG: Redefine IndexOpsMixin.size, fix pandas-dev#25580. (pandas-dev#25584) BUG: to_csv line endings with compression (pandas-dev#25625) DOC: file obj for to_csv must be newline='' (pandas-dev#25624) Suppress incorrect warning in nargsort for timezone-aware DatetimeIndex (pandas-dev#25629) TST: fix incorrect sparse test (now failing on scipy master) (pandas-dev#25653) CLN: Removed debugging code (pandas-dev#25647) DOC: require Return section only if return is not None nor commentary (pandas-dev#25008) DOC:Remove hard-coded examples from _flex_doc_SERIES (pandas-dev#24589) (pandas-dev#25524) TST: xref pandas-dev#25630 (pandas-dev#25643) BUG: Fix pandas-dev#25481 by fixing the error message in TypeError (pandas-dev#25540) Fixturize tests/frame/test_mutate_columns.py (pandas-dev#25642) Fixturize tests/frame/test_join.py (pandas-dev#25639) Fixturize tests/frame/test_combine_concat.py (pandas-dev#25634) Fixturize tests/frame/test_asof.py (pandas-dev#25628) BUG: Fix user-facing AssertionError with to_html (pandas-dev#25608) (pandas-dev#25620) DOC: resolve all GL03 docstring validation errors (pandas-dev#25525) TST: failing wheel building on PY2 and old numpy (pandas-dev#25631) DOC: Remove makePanel from docs (pandas-dev#25609) (pandas-dev#25612) ...
Updated return lookup at source in validate_docstrings.py:
Updated test_validate_docstrings.py: