Skip to content

Commit 2a37975

Browse files
authored
Fix dict params include bug (#62)
* Fix dict params include bug * Fix remove debug print
1 parent aea9457 commit 2a37975

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

autoload/pydocstring.vim

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function! s:compare(lhs, rhs)
6060
return a:lhs['start'] - a:rhs['start']
6161
endfunction
6262

63-
function! s:parse_args(args_str)
63+
function! s:parse_args_with_types(args_str)
6464
" FIXME Very very work around.
6565
" If Python2 is dead, consider to use Python interface
6666
let args_str = copy(a:args_str)
@@ -154,11 +154,32 @@ function! s:parse_args(args_str)
154154
return map(args, {i, v -> substitute(v['val'], ',', ', ', 'g')})
155155
endfunction
156156

157+
function! s:parse_args(args_str) abort
158+
" TODO FIXME Work around
159+
let args_str = copy(a:args_str)
160+
161+
let args_str = substitute(args_str, '"', "'", 'g')
162+
163+
let pattern = "'[A-z0-9_-]\+':[A-z0-9.-_]\+"
164+
let args_str = substitute(args_str, "\\v'[A-z0-9_-]\+':[A-z0-9.-_'\"]\+", '', 'g')
165+
let args_str = substitute(args_str, '=\({,\+}\|{}\)', '', 'g')
166+
let args_str = substitute(args_str, '\[.*]', '', 'g')
167+
let args = split(args_str, ',')
168+
169+
return args
170+
endfunction
171+
157172
function! s:parse_func(type, line)
158173
let header = substitute(a:line, '\s\|(.*\|:', '', 'g')
159174

160175
let args_str = substitute(a:line, '\s\|.*(\|).*', '', 'g')
161176
if args_str =~ ':' && args_str =~ '['
177+
if match(args_str, '[A-z0-9_$]\+:') >= 0
178+
let args = s:parse_args_with_types(args_str)
179+
else
180+
let args = s:parse_args(args_str)
181+
endif
182+
elseif args_str =~ '=' && (args_str =~ '{' || args_str =~ '[')
162183
let args = s:parse_args(args_str)
163184
elseif args_str =~ ':'
164185
let args = split(args_str, ',')

test/issue_with_dict.vader

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# vim:set et sw=4 ts=4 tw=79:
2+
Given python (def foo with dict params):
3+
def get_adjacency(
4+
facets,
5+
points=None,
6+
max_degree=None,
7+
dtypes={'ints': np.int64, 'floats': np.float32},
8+
):
9+
pass
10+
11+
Execute:
12+
Pydocstring
13+
14+
Expect python:
15+
def get_adjacency(
16+
facets,
17+
points=None,
18+
max_degree=None,
19+
dtypes={'ints': np.int64, 'floats': np.float32},
20+
):
21+
"""get_adjacency
22+
23+
:param facets:
24+
:param points:
25+
:param max_degree:
26+
:param dtypes:
27+
"""
28+
pass
29+
30+
Given python (def foo with list params):
31+
def get_adjacency(
32+
facets,
33+
points=None,
34+
max_degree=None,
35+
dtypes=['ints', 'floats'],
36+
):
37+
pass
38+
39+
Execute:
40+
Pydocstring
41+
42+
Expect python:
43+
def get_adjacency(
44+
facets,
45+
points=None,
46+
max_degree=None,
47+
dtypes=['ints', 'floats'],
48+
):
49+
"""get_adjacency
50+
51+
:param facets:
52+
:param points:
53+
:param max_degree:
54+
:param dtypes:
55+
"""
56+
pass
57+
58+
Given python (def foo with list and dict params):
59+
def get_adjacency(
60+
facets,
61+
points=None,
62+
max_degree=None,
63+
dtypes={'ints': np.int64, 'floats': np.float32},
64+
etypes=['ints', 'floats'],
65+
):
66+
pass
67+
68+
Execute:
69+
Pydocstring
70+
71+
Expect python:
72+
def get_adjacency(
73+
facets,
74+
points=None,
75+
max_degree=None,
76+
dtypes={'ints': np.int64, 'floats': np.float32},
77+
etypes=['ints', 'floats'],
78+
):
79+
"""get_adjacency
80+
81+
:param facets:
82+
:param points:
83+
:param max_degree:
84+
:param dtypes:
85+
:param etypes:
86+
"""
87+
pass

0 commit comments

Comments
 (0)