-
Notifications
You must be signed in to change notification settings - Fork 4
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
blank lines between parameters #15
Comments
Hi Lukas! Thanks for your report :) Yes, this might cause a problem since the Parameters are in the class DocstringProcessorWithBlanks(DocstringProcessor):
param_like_sections = [s for s in DocstringProcessor.param_like_sections
if s != 'Parameters']
text_sections = ['Parameters'] + DocstringProcessor.text_sections Or simply put all class DocstringProcessorWithBlanks(DocstringProcessor):
param_like_sections = []
text_sections = DocstringProcessor.text_sections + \
DocstringProcessor.param_like_sections |
Thanks for the quick reply, Philipp! Haha, sorry should have directly tried to strip it down, then my question would have been more specific... So, as it turns out for simple functions blank lines are fine. However, in class methods blank lines don't work. Example just with functionsCodeimport docrep
docstrings = docrep.DocstringProcessor()
@docstrings.get_sectionsf('do_something')
@docstrings.dedent
def do_something(a, b):
"""
Add two numbers
Parameters
----------
a: int
The first number
b: int
The second number
Returns
-------
int
`a` + `b`"""
return a + b
@docstrings.dedent
def do_more(c, *args, **kwargs):
"""
Add two numbers and multiply it by c
Parameters
----------
c: int
multiplication parameter
%(do_something.parameters)s
Returns
-------
int
(`a` + `b`) * c"""
return do_something(*args, **kwargs) * c
print(do_more.__doc__) Output as desired
Example using a class and method docstringsCodeimport docrep
docstrings = docrep.DocstringProcessor()
class A:
@docstrings.get_sectionsf('do_something')
@docstrings.dedent
def do_something(a, b):
"""
Add two numbers
Parameters
----------
a: int
The first number
b: int
The second number
Returns
-------
int
`a` + `b`"""
return a + b
@docstrings.dedent
def do_more(c, *args, **kwargs):
"""
Add two numbers and multiply it by c
Parameters
----------
c: int
multiplication parameter
%(do_something.parameters)s
Returns
-------
int
(`a` + `b`) * c"""
return do_something(*args, **kwargs) * c
a = A
print(a.do_more.__doc__) Output: parameter
|
Both of your suggestions seem to work. Thanks, Philipp, that way I can keep my blank lines. |
Great 😄
This is weird because actually the As a little comment: the sections in the def func(a=1):
"""
An awesome function
Parameters
----------
a: int
A parameter
And here we have a paragraph that has nothing to
do with the Parameters section
""" will cause problems if you have the |
Good to know, I'll look out for that, but I guess typically this won't be an issue as the parameters section usually is followed by the results section. |
FYI: I am currently using this 'bug' as a feature. If I want to stop certain parameters from being inherited by subclasses I but them after a line break. This way I can re-define those specific parameters in subclasses without having duplicates (or without having the deal with removing them from the docrep dict). This pertains to the feature request I just posted (issue #16) |
Does
docrep
require the parameters in the docstring to be written without a blank line separating them? It seems like a blank line is taken as the end of the parameter section.Would it be possible to allow blank lines such that the raw docs look a little neater?
The text was updated successfully, but these errors were encountered: