55import textwrap
66
77from functools import wraps
8- from inspect import getfullargspec , signature
8+ from inspect import getfullargspec , signature , Parameter
9+ from collections import OrderedDict
910
1011
1112# TODO: calling all functions as eg directory(c, '/foo/bar/') (with initial c)
@@ -127,13 +128,14 @@ def munge_docstring(f, inner):
127128 # (modified) signature; leverages the fact that autodoc_docstring_signature
128129 # is True by default.
129130 sig = signature (f )
130- args = [p .name for p in sig .parameters .values () if p .POSITIONAL_ONLY ]
131- defaults = [p .default for p in sig .parameters .values () if p .default is not p .empty ]
131+ parameters = list (sig .parameters .values ())
132132 # Nix positional version of runner arg, which is always 2nd
133- args .extend (["sudo" , "runner_method" , "runner" ])
134- # Add default values (remembering that this tuple matches the _end_ of the
135- # signature...)
136- defaults = tuple (list (defaults or []) + [False , "run" , None ])
133+ del parameters [1 ]
134+ # Append new arguments
135+ parameters .append (Parameter ("sudo" , Parameter .POSITIONAL_OR_KEYWORD , default = False ))
136+ parameters .append (Parameter ("runner_method" , Parameter .POSITIONAL_OR_KEYWORD , default = "run" ))
137+ parameters .append (Parameter ("runner" , Parameter .POSITIONAL_OR_KEYWORD , default = None ))
138+ sig = sig .replace (parameters = parameters )
137139 # Get signature first line for Sphinx autodoc_docstring_signature
138140 docstring = textwrap .dedent (inner .__doc__ or "" ).strip ()
139141 # Construct :param: list
@@ -144,4 +146,4 @@ def munge_docstring(f, inner):
144146:param runner:
145147 Callable runner function or method. Should ideally be a bound method on the given context object!
146148""" # noqa
147- return f"{ sig } \n { docstring } \n \n { params } "
149+ return f"{ f . __name__ } { sig } \n { docstring } \n \n { params } "
0 commit comments