Skip to content

Commit 931b3b0

Browse files
committed
Fix munge_docstring
Signed-off-by: Cristian Le <[email protected]>
1 parent a048604 commit 931b3b0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/patchwork/util.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import textwrap
66

77
from 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

Comments
 (0)