Skip to content

Commit

Permalink
ENH: Removing self from python arguments in docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Nov 5, 2024
1 parent c4c52c3 commit ba662f9
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions snippets/python-mode/.yas-setup.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ Groups:
"Split python argument string ARG-STRING.
The result is a list ((name, type, default), ...) of argument names, types and
default values."
(mapcar (lambda (x) ; organize output
(when (string-match python-split-arg-regex x)
(list
(match-string-no-properties 1 x) ; name
(match-string-no-properties 3 x) ; type
(match-string-no-properties 5 x) ; default
)))
(split-string arg-string python-split-arg-separator t)))
default values. An argument named `self` is omitted."
(remove
nil
(mapcar (lambda (x) ; organize output
(when (and
(not (equal "self" x))
(string-match python-split-arg-regex x)
)
(list
(match-string-no-properties 1 x) ; name
(match-string-no-properties 3 x) ; type
(match-string-no-properties 5 x) ; default
)))
(split-string arg-string python-split-arg-separator t))))

(defun python-args-to-docstring ()
"Return docstring format for the python arguments in yas-text."
Expand Down Expand Up @@ -108,6 +113,14 @@ default values."
'("foobar" nil nil)))
))

(ert-deftest test-argument-self ()
"If an argument is called `self`, it must be omitted"
(should (equal
(python-split-args "self, _foo=\"this\"")
(list '("_foo" nil "\"this\"")
))
))

;; For manual testing and development:

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

0 comments on commit ba662f9

Please sign in to comment.