-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Make _field_accessor manage the docstring format #24072
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
DOC: Make _field_accessor manage the docstring format #24072
Conversation
Hello @charlesdong1991! Thanks for submitting the PR.
|
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 can make this simpler, see comment.
if not docstring.startswith("\n"): | ||
docstring = "".join(("\n", docstring)) | ||
if not docstring.endswith("\n"): | ||
docstring = "".join((docstring, "\n")) | ||
f.__doc__ = docstring |
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'd make it as simple as:
f.__doc__ = docstring | |
f.__doc__ = '\n{}\n'.format(docstring) |
Without the code you added.
Then, in the calls to _field_accessor
we need to remove the \n
and spaces around the description. I think that should work in all cases.
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.
oh, okay, @datapythonista thanks for the review, i did think about this solution, then i thought if in the call to _field_accessor
, we already used \n, then directly adding \n will be redundant... so i made a if
judgement first..
but agree that if remove the \n
added before, then this should not be the problem and look much simpler...
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 may have to do what you did if at some point we have something like:
_doc = """
Some summary.
"""
foo = _field_accessor(..., _doc)
But we'll complicate things at that point, if they ever happen. And to join two strings, I think it's better to use '\n' + foo
of '\n{}'.format(foo)
than using a join.
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.
okay, thanks for the tip!! @datapythonista
Codecov Report
@@ Coverage Diff @@
## master #24072 +/- ##
==========================================
+ Coverage 42.38% 42.39% +<.01%
==========================================
Files 161 161
Lines 51699 51709 +10
==========================================
+ Hits 21913 21920 +7
- Misses 29786 29789 +3
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #24072 +/- ##
==========================================
+ Coverage 42.38% 42.39% +<.01%
==========================================
Files 161 161
Lines 51699 51709 +10
==========================================
+ Hits 21913 21920 +7
- Misses 29786 29789 +3
Continue to review full report at Codecov.
|
git diff upstream/master -u -- "*.py" | flake8 --diff