Closed amnona closed 6 years ago
Hey @amnona, just to mention: I also added a with_indent
method that can be used to replace within these kind of docstrings. Here is the example from the docs
In [9]: @docstrings.get_sectionsf('do_something')
...: def second_example_source(a, b):
...: """Summary is on the first line
...:
...: Parameters
...: ----------
...: a: int
...: The first number
...: b: int
...: The second number
...:
...: Returns
...: -------
...: int
...: `a` + `b`"""
...: return a + b
...:
In [10]: @docstrings.with_indent(4) # we indent the replacements with 4 spaces
....: def second_example_target(*args, **kwargs):
....: """Target docstring with summary on the first line
....:
....: Parameters
....: ----------
....: %(do_something.parameters)s
....:
....: Returns
....: -------
....: int
....: (`a` + `b`) * 2"""
....: return second_example_source(*args, **kargs) * 2
In [11]: help(second_example_target)
Help on function second_example_target in module __main__:
second_example_target(*args, **kwargs)
Target docstring with summary on the first line
Parameters
----------
a: int
The first number
b: int
The second number
Returns
-------
int
(`a` + `b`) * 2
I will make a new release now and then it will be available by PyPi and the conda-forge channel.
Handle the case (as in the numpydoc standard) where the short summary is attached to the triple quote. i.e. '''Short summary
... ''' Without this PR, dedent does not remove the spaces at the beginning of Parameters (since lowest number of spaces at line0 is 0) and then the regexp fails.
Don't know if this is the best regexp, but seems to do the job.