Skip to content

Commit 07b8703

Browse files
committed
Drop default values
1 parent 1d5e471 commit 07b8703

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

insert-docstring-tests.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
'("first" "second" "third")))
120120
(should (equal (insert-docstring--get-python-arguments-names-from-string
121121
" first: Type\n,\n second:\n Map[some, other]") '("first" "second")))
122+
(should (equal (insert-docstring--get-python-arguments-names-from-string
123+
" first: Type = 1,\n second: Map[some, other] = 2") '("first" "second")))
124+
(should (equal (insert-docstring--get-python-arguments-names-from-string
125+
" first = 1,\n second = 2") '("first" "second")))
122126
)
123127
)
124128

insert-docstring.el

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"Tabulation width in Python files"
3131
:group 'insert-docstring
3232
)
33+
3334
(defcustom insert-docstring--default-python-indentation
3435
(make-string insert-docstring--python-tab-width ? )
3536
"Python indentation string"
@@ -41,6 +42,7 @@
4142
"Regex to find the indentation of a function"
4243
:group 'insert-docstring
4344
)
45+
4446
(defcustom insert-docstring--python-function-name-regex
4547
(rx "def" (+ (or blank "\n"))
4648
(group (+ (not whitespace)))
@@ -54,12 +56,19 @@
5456
"Regex to find the string of arguments of a function"
5557
:group 'insert-docstring
5658
)
59+
5760
(defcustom insert-docstring--python-function-end-regex
5861
(rx ")" (* (not (any ":"))) ":")
5962
"Regex to find the end of a function"
6063
:group 'insert-docstring
6164
)
6265

66+
(defcustom insert-docstring--blank-or-newline-regex
67+
(rx (+ (or blank "\n")))
68+
"Regex to find blanks and newlines (used for trimming)"
69+
:group 'insert-docstring
70+
)
71+
6372

6473
(cl-defstruct insert-docstring--argument-data
6574
"Data associated to a function argument."
@@ -116,16 +125,23 @@
116125
"Parse the argument names contained in ARGUMENTS-STRING and
117126
return them in a list."
118127
(if (string-equal "" arguments-string) nil
119-
(cl-remove-if
128+
(mapcar
120129
(lambda (string)
121-
(string-match-p (rx (or "[" "]")) string)
130+
"Remove default value if any and trim"
131+
(car (split-string string "=" t insert-docstring--blank-or-newline-regex))
122132
)
123-
(mapcar (lambda (single-argument-string)
124-
(car (split-string single-argument-string ":" t
125-
(rx (+ (or blank "\n")))))
126-
)
127-
(split-string arguments-string ",")
128-
)
133+
(cl-remove-if
134+
(lambda (string)
135+
"Match type data leftovers"
136+
(string-match-p (rx (or "[" "]")) string)
137+
)
138+
(mapcar (lambda (single-argument-string)
139+
"Drop type data"
140+
(car (split-string single-argument-string ":"))
141+
)
142+
(split-string arguments-string ",")
143+
)
144+
)
129145
)
130146
)
131147
)

0 commit comments

Comments
 (0)