11"""
22Helpers and decorators, primarily for internal or advanced use.
33"""
4- import inspect
54import textwrap
65
76from functools import wraps
8- from inspect import getfullargspec , signature
7+ from inspect import signature , Parameter
98
109
1110# TODO: calling all functions as eg directory(c, '/foo/bar/') (with initial c)
@@ -127,13 +126,14 @@ def munge_docstring(f, inner):
127126 # (modified) signature; leverages the fact that autodoc_docstring_signature
128127 # is True by default.
129128 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 ]
129+ parameters = list (sig .parameters .values ())
132130 # 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 ])
131+ del parameters [1 ]
132+ # Append new arguments
133+ parameters .append (Parameter ("sudo" , Parameter .POSITIONAL_OR_KEYWORD , default = False ))
134+ parameters .append (Parameter ("runner_method" , Parameter .POSITIONAL_OR_KEYWORD , default = "run" ))
135+ parameters .append (Parameter ("runner" , Parameter .POSITIONAL_OR_KEYWORD , default = None ))
136+ sig = sig .replace (parameters = parameters )
137137 # Get signature first line for Sphinx autodoc_docstring_signature
138138 docstring = textwrap .dedent (inner .__doc__ or "" ).strip ()
139139 # Construct :param: list
@@ -144,4 +144,4 @@ def munge_docstring(f, inner):
144144:param runner:
145145 Callable runner function or method. Should ideally be a bound method on the given context object!
146146""" # noqa
147- return f"{ sig } \n { docstring } \n \n { params } "
147+ return f"{ f . __name__ } { sig } \n { docstring } \n \n { params } "
0 commit comments