Skip to content

Commit 5b91b80

Browse files
authoredMar 20, 2023
Add special cases of param names to ignore (#13)
1 parent 5120fea commit 5b91b80

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
 

‎README.md

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ RET numpydoc</kbd>
130130
description if <code>numpydoc-insertion-style</code> is
131131
<code>nil</code>.
132132
</dd>
133+
<dt>numpydoc-ignored-params</dt>
134+
<dd>
135+
All function parameters with names listed here will be ignored
136+
when generating a docstring.
137+
</dd>
133138
</dl>
134139

135140
## Examples

‎numpydoc.el

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ text, and below the Examples section."
127127
:group 'numpydoc
128128
:type 'string)
129129

130+
(defcustom numpydoc-ignored-params (list "" "self" "cls" "*" "*args" "**kwargs" "/")
131+
"All function parameters with names listed here will be ignored
132+
when generating a docstring."
133+
:group 'numpydoc
134+
:type '(repeat string))
135+
130136
;;; package implementation code.
131137

132138
(cl-defstruct numpydoc--def
@@ -266,7 +272,7 @@ This function assumes the cursor to be in the function body."
266272
rawsig))))))
267273
;; function args as a list of structures (remove some special cases)
268274
(args (-remove (lambda (x)
269-
(-contains-p (list "" "self" "*" "/")
275+
(-contains-p numpydoc-ignored-params
270276
(numpydoc--arg-name x)))
271277
(-map #'numpydoc--arg-str-to-struct rawargs)))
272278
;; look for exceptions in the function body

‎tests/test-numpydoc.el

+33-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ def f(
5252
hh: str = \"str, str, str, str\",
5353
ii: tuple[int, ...] = (4, 6),
5454
jj: str = \"str,str\",
55+
)")
56+
(fsig-ignored-args "\
57+
def func_with_ignored_args(
58+
self,
59+
a1: int,
60+
a2: str,
61+
*args,
62+
**kwargs,
5563
)"))
5664
(it "Checks arg parsing 1"
5765
(let ((a (make-numpydoc--arg :name "a" :type "int" :defval nil))
@@ -136,7 +144,31 @@ def f(
136144
(expect gg :to-equal (nth 6 args))
137145
(expect hh :to-equal (nth 7 args))
138146
(expect ii :to-equal (nth 8 args))
139-
(expect jj :to-equal (nth 9 args)))))
147+
(expect jj :to-equal (nth 9 args))))
148+
(it "Checks arg parsing for ignored param names"
149+
(let* ((numpydoc-ignored-params (list "self" "*args" "**kwargs"))
150+
(self (make-numpydoc--arg :name "self"
151+
:type nil
152+
:defval nil))
153+
(a1 (make-numpydoc--arg :name "a1"
154+
:type "int"
155+
:defval nil))
156+
(a2 (make-numpydoc--arg :name "a2"
157+
:type "str"
158+
:defval nil))
159+
(pyargs (make-numpydoc--arg :name "*args"
160+
:type nil
161+
:defval nil))
162+
(kwargs (make-numpydoc--arg :name "**kwargs"
163+
:type nil
164+
:defval nil))
165+
166+
(args (numpydoc--def-args (numpydoc--parse-def fsig-ignored-args))))
167+
(expect a1 :to-equal (car args))
168+
(expect a2 :to-equal (nth 1 args))
169+
(expect args :not :to-contain self)
170+
(expect args :not :to-contain pyargs)
171+
(expect args :not :to-contain kwargs))))
140172

141173
(provide 'test-numpydoc)
142174
;;; test-numpydoc.el ends here

0 commit comments

Comments
 (0)
Please sign in to comment.