Skip to content

Commit 86a1378

Browse files
author
Daniel
committed
ENH: Removing self from python arguments in docstring.
1 parent 58041c7 commit 86a1378

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

snippets/python-mode/.yas-setup.el

+22-9
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@ Groups:
5252
"Split python argument string ARG-STRING.
5353
5454
The result is a list ((name, type, default), ...) of argument names, types and
55-
default values."
56-
(mapcar (lambda (x) ; organize output
57-
(when (string-match python-split-arg-regex x)
58-
(list
59-
(match-string-no-properties 1 x) ; name
60-
(match-string-no-properties 3 x) ; type
61-
(match-string-no-properties 5 x) ; default
62-
)))
63-
(split-string arg-string python-split-arg-separator t)))
55+
default values. An argument named `self` is omitted."
56+
(remove
57+
nil
58+
(mapcar (lambda (x) ; organize output
59+
(when (and
60+
(not (equal "self" x))
61+
(string-match python-split-arg-regex x)
62+
)
63+
(list
64+
(match-string-no-properties 1 x) ; name
65+
(match-string-no-properties 3 x) ; type
66+
(match-string-no-properties 5 x) ; default
67+
)))
68+
(split-string arg-string python-split-arg-separator t))))
6469

6570
(defun python-args-to-docstring ()
6671
"Return docstring format for the python arguments in yas-text."
@@ -108,6 +113,14 @@ default values."
108113
'("foobar" nil nil)))
109114
))
110115

116+
(ert-deftest test-argument-self ()
117+
"If an argument is called `self`, it must be omitted"
118+
(should (equal
119+
(python-split-args "self, _foo=\"this\"")
120+
(list '("_foo" nil "\"this\"")
121+
))
122+
))
123+
111124
;; For manual testing and development:
112125

113126
;; (setq yas-text "foo=3, bar: int = 2, baz: Optional[MyType], foobar")

0 commit comments

Comments
 (0)