Skip to content

Commit

Permalink
Ignore 'self' when it is the first function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
macurovc committed Nov 23, 2021
1 parent 4d729f5 commit 21606fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion python-insert-docstring-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first: Type = 1,\n second: Map[some, other] = 2") '("first" "second")))
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first = 1,\n second = 2") '("first" "second")))))
" first = 1,\n second = 2") '("first" "second")))
(should (equal (python-insert-docstring--get-arguments-names-from-string
" self ,\n second = 2") '("second")))))

(ert-deftest prefix-lines-test ()
"Test the function to prefix lines with blanks."
Expand Down
26 changes: 15 additions & 11 deletions python-insert-docstring.el
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,21 @@
"Parse the argument names contained in ARGUMENTS-STRING and return them in a list."
(if (string-equal "" arguments-string)
nil
(mapcar (lambda (string)
"Remove default value if any and trim"
(car (split-string string "=" t python-insert-docstring-blank-or-newline-regex)))
(cl-remove-if (lambda (string)
"Match type data leftovers"
(string-match-p (rx (or "[" "]"))
string))
(mapcar (lambda (single-argument-string)
"Drop type data"
(car (split-string single-argument-string ":")))
(split-string arguments-string ","))))))
(let ((arguments (mapcar (lambda (string)
"Remove default value if any and trim"
(car (split-string string "=" t python-insert-docstring-blank-or-newline-regex)))
(cl-remove-if (lambda (string)
"Match type data leftovers"
(string-match-p (rx (or "[" "]"))
string))
(mapcar (lambda (single-argument-string)
"Drop type data"
(car (split-string single-argument-string ":")))
(split-string arguments-string ","))))))
(if (string-equal (car arguments)
"self")
(cdr arguments)
arguments))))


(defun python-insert-docstring--make-function-data (indentation-string function-name argument-names)
Expand Down

0 comments on commit 21606fb

Please sign in to comment.