1
1
"""
2
2
Helpers and decorators, primarily for internal or advanced use.
3
3
"""
4
- import inspect
5
4
import textwrap
6
5
7
6
from functools import wraps
8
- from inspect import getfullargspec , signature
7
+ from inspect import signature , Parameter
9
8
10
9
11
10
# TODO: calling all functions as eg directory(c, '/foo/bar/') (with initial c)
@@ -127,13 +126,14 @@ def munge_docstring(f, inner):
127
126
# (modified) signature; leverages the fact that autodoc_docstring_signature
128
127
# is True by default.
129
128
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 ())
132
130
# 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 )
137
137
# Get signature first line for Sphinx autodoc_docstring_signature
138
138
docstring = textwrap .dedent (inner .__doc__ or "" ).strip ()
139
139
# Construct :param: list
@@ -144,4 +144,4 @@ def munge_docstring(f, inner):
144
144
:param runner:
145
145
Callable runner function or method. Should ideally be a bound method on the given context object!
146
146
""" # noqa
147
- return f"{ sig } \n { docstring } \n \n { params } "
147
+ return f"{ f . __name__ } { sig } \n { docstring } \n \n { params } "
0 commit comments