Skip to content

Commit feecc37

Browse files
authored
Fix/rename (#37)
* Fix rename test file for more clearly * Fix method/variable naming camelCase to sanake_case
1 parent 5849cdf commit feecc37

File tree

14 files changed

+163
-31
lines changed

14 files changed

+163
-31
lines changed

CHANGES.rst

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Version 0.1.6
2+
-------------
3+
Released on Nov 19th 2017
4+
5+
- Minor changes
6+
7+
- Change function name camelCase to snake_case
8+
- Change variable name camelCase to snake_case
9+
10+
see https://github.com/heavenshell/vim-pydocstring/issues/34
11+
112
Version 0.1.5
213
-------------
314
Released on Nov 18th 2017

autoload/pydocstring.vim

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Insert Docstring.
22
" Author: Shinya Ohyanagi <[email protected]>
3-
" Version: 0.1.5
3+
" Version: 0.1.6
44
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
55
" Description: Generate Python docstring to your Python script file.
66
" License: BSD, see LICENSE for more details.
@@ -48,26 +48,26 @@ function! s:parseClass(line)
4848
" do that by just delete every white spaces and the whole parenthesics if
4949
" existed.
5050
let header = substitute(a:line, '\s\|(.*\|:', '', 'g')
51-
let parse = {'type': 'class', 'header': header, 'args': '', 'returnType': ''}
51+
let parse = {'type': 'class', 'header': header, 'args': '', 'return_type': ''}
5252
return parse
5353
endfunction
5454

55-
function! s:parseFunc(type, line)
55+
function! s:parse_func(type, line)
5656
let header = substitute(a:line, '\s\|(.*\|:', '', 'g')
5757

58-
let argsStr = substitute(a:line, '\s\|.*(\|).*', '', 'g')
59-
let args = split(argsStr, ',')
58+
let args_str = substitute(a:line, '\s\|.*(\|).*', '', 'g')
59+
let args = split(args_str, ',')
6060

61-
let arrowIndex = match(a:line, "->")
62-
if arrowIndex != -1
63-
let substring = strpart(a:line, arrowIndex + 2)
61+
let arrow_index = match(a:line, "->")
62+
if arrow_index != -1
63+
let substring = strpart(a:line, arrow_index + 2)
6464
" issue #28 `\W*` would deleted `.`.
65-
let returnType = substitute(substring, '[^0-9A-Za-z_.]*', '', 'g')
65+
let return_type = substitute(substring, '[^0-9A-Za-z_.]*', '', 'g')
6666
else
67-
let returnType = ''
67+
let return_type = ''
6868
endif
6969

70-
let parse = {'type': a:type, 'header': header, 'args': args, 'returnType': returnType}
70+
let parse = {'type': a:type, 'header': header, 'args': args, 'return_type': return_type}
7171
return parse
7272
endfunction
7373

@@ -90,7 +90,7 @@ function! s:parse(line)
9090
return 0
9191
endif
9292

93-
return s:parseFunc(type, str)
93+
return s:parse_func(type, str)
9494
endfunction
9595

9696
" Vim Script does not support lambda function...
@@ -104,7 +104,7 @@ endfunction
104104
" Check if we should show args in the docstring. We won't do that in case:
105105
" - There's no args.
106106
" - There's only one arg that match with g:pydocstring_ignore_args_pattern
107-
function! s:shouldIncludeArgs(args)
107+
function! s:should_include_args(args)
108108
if len(a:args) == 0
109109
return 0
110110
endif
@@ -124,33 +124,33 @@ endfunction
124124
" g:pydocstring_ignore_args_pattern
125125
"
126126
" Return 1 for True, and 0 for False
127-
function! s:shouldUseOneLineDocString(type, args, returnType)
127+
function! s:should_use_one_line_docstring(type, args, return_type)
128128
if a:type != 'def'
129129
return 1
130130
endif
131131

132-
if a:returnType != ''
132+
if a:return_type != ''
133133
return 0
134134
endif
135135

136-
return !s:shouldIncludeArgs(a:args)
136+
return !s:should_include_args(a:args)
137137
endfunction
138138

139139
function! s:builddocstring(strs, indent, nested_indent)
140140
let type = a:strs['type']
141141
let prefix = a:strs['header']
142142
let args = a:strs['args']
143-
let returnType = a:strs['returnType']
143+
let return_type = a:strs['return_type']
144144

145-
if s:shouldUseOneLineDocString(type, args, returnType)
145+
if s:should_use_one_line_docstring(type, args, return_type)
146146
return s:readoneline(a:indent, prefix)
147147
endif
148148

149149
let tmpl = ''
150150
let docstrings = []
151151
let lines = s:readtmpl('multi')
152152
let has_return_type = 0
153-
if match(lines, '\c{{_returnType_}}') != -1
153+
if match(lines, '\c{{_returnType_}}\|\c{{_return_type_}}') != -1
154154
let has_return_type = 1
155155
endif
156156
for line in lines
@@ -186,7 +186,7 @@ function! s:builddocstring(strs, indent, nested_indent)
186186
" '''
187187
" {{_header_}}
188188
" :param {{_args_}}:
189-
" :rtype: {{_returnType_}}
189+
" :rtype: {{_return_type_}}
190190
" '''
191191
let template = substitute(template, ':$', '', 'g')
192192
endif
@@ -203,9 +203,9 @@ function! s:builddocstring(strs, indent, nested_indent)
203203
elseif line =~ '{{_indent_}}'
204204
let arg = substitute(line, '{{_indent_}}', a:indent, 'g')
205205
call add(docstrings, arg)
206-
elseif line =~ '{{_returnType_}}'
207-
if strlen(returnType) != 0
208-
let rt = substitute(line, '{{_returnType_}}', returnType, '')
206+
elseif line =~ '{{_returnType_}}\|{{_return_type_}}'
207+
if strlen(return_type) != 0
208+
let rt = substitute(line, '{{_returnType_}}\|{{_return_type_}}', return_type, '')
209209
call add(docstrings, a:indent . rt)
210210
else
211211
call remove(docstrings, -1)

doc/pydocstring.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*pydocstring.txt* Generate Python docstring to your Python code.
22

3-
Version: 0.1.5
3+
Version: 0.1.6
44
Author: Shinya Ohynagi <[email protected]>
55
Repository: http://github.com/heavenshell/vim-pydocstring/
66
License: BSD, see LICENSE for more details.
@@ -141,12 +141,13 @@ Template variables.
141141
|{{_lf_}}| Assign line break.
142142
|{{_indent_}}| Assign indent.
143143
|{{_nested_indent_}}| Assign indent.
144-
|{{_returnType_}}| Function or method return type.
144+
|{{_return_type_}}| Function or method return type.
145+
|{{_returnType_}}| Same as |{{_return_type_}}||.
145146
|{{_name_}}| Argument name, should only be used in `arg.txt`
146147
|{{_type_}}| Argument type, should only be used in `arg.txt`
147148

148149
There's some rules for parsing template:
149-
- `{{_header_}`, `{{_args}}` and `{{_returnType_}}` should be on their own
150+
- `{{_header_}`, `{{_args}}` and `{{_return_type_}}` should be on their own
150151
line.
151152
- Pydocstring will insert a emmpty line between each parts, so you don't
152153
need to include empty line in your template. Please see the default template

ftplugin/python/pydocstring.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" File: pydocstring.vim
22
" Author: Shinya Ohyanagi <[email protected]>
3-
" Version: 0.1.5
3+
" Version: 0.1.6
44
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
55
" Description: Generate Python docstring to your Python script file.
66
" License: BSD, see LICENSE for more details.

template/pydocstring/multi.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""{{_header_}}
22

33
:param {{_args_}}:
4-
:rtype: {{_returnType_}}
4+
:rtype: {{_return_type_}}
55
"""
File renamed without changes.

test/issue_return_type.vader

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# vim:set et sw=4 ts=4 tw=79:
2+
# Test for {{_returnType_}} not BCBreak.
3+
Execute (Setup template dir):
4+
Save g:pydocstring_templates_dir
5+
let g:pydocstring_templates_dir = './templates/return_type/'
6+
7+
Given python (def foo no arg return str):
8+
def foo() -> str:
9+
pass
10+
11+
Execute:
12+
Pydocstring
13+
14+
Expect python:
15+
def foo() -> str:
16+
"""foo
17+
18+
:rtype: str
19+
"""
20+
pass
21+
22+
Given python (def foo with 1 arg return str):
23+
def foo(sample_var) -> str:
24+
pass
25+
Execute:
26+
Pydocstring
27+
28+
Expect python:
29+
def foo(sample_var) -> str:
30+
"""foo
31+
32+
:param sample_var:
33+
34+
:rtype: str
35+
"""
36+
pass
37+
38+
Given python (def foo 2 args return str):
39+
def foo(arg1, arg2) -> str:
40+
pass
41+
Execute:
42+
Pydocstring
43+
44+
Expect python:
45+
def foo(arg1, arg2) -> str:
46+
"""foo
47+
48+
:param arg1:
49+
:param arg2:
50+
51+
:rtype: str
52+
"""
53+
pass
54+
55+
Given python (def foo 1 arg with type and return int):
56+
def foo(n: int) -> int:
57+
pass
58+
59+
Execute:
60+
Pydocstring
61+
62+
Expect python:
63+
def foo(n: int) -> int:
64+
"""foo
65+
66+
:param n:
67+
:type n: int
68+
69+
:rtype: int
70+
"""
71+
pass
72+
73+
Given python (def foo 2 args with type and return int):
74+
def foo(n: int, m: str) -> int:
75+
pass
76+
77+
Execute:
78+
Pydocstring
79+
80+
Expect python:
81+
def foo(n: int, m: str) -> int:
82+
"""foo
83+
84+
:param n:
85+
:type n: int
86+
:param m:
87+
:type m: str
88+
89+
:rtype: int
90+
"""
91+
pass
92+
93+
94+
Given python (def foo 1 arg with type, 1 none, and return int):
95+
def foo(n: int, arg) -> int:
96+
pass
97+
98+
Execute:
99+
Pydocstring
100+
101+
Expect python:
102+
def foo(n: int, arg) -> int:
103+
"""foo
104+
105+
:param n:
106+
:type n: int
107+
:param arg:
108+
109+
:rtype: int
110+
"""
111+
pass
112+

test/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# If nvim is available in PATH, then we prefer to use nvim
99
# since it works better with nodemon
10-
if hash nvim 2>/dev/null ; then
10+
if hash nvim 2>/dev/null ; then
1111
VIM_EXE="nvim"
1212
fi
1313

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""{{_header_}}
22

33
{{_args_}}:{{_lf_}}{{_indent_}} the ...
4-
return ({{_returnType_}}):
4+
return ({{_return_type_}}):
55
"""

test/templates/numpy/multi.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
{{_indent_}}Returns
88
{{_indent_}}-------
99

10-
returnVar : {{_returnType_}}
10+
returnVar : {{_return_type_}}
1111
"""

test/templates/return_type/arg.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{_name_}}:{{_lf_}}{{_indent_}}:type {{_name_}}: {{_type_}}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

test/templates/return_type/multi.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""{{_header_}}
2+
3+
:param {{_args_}}:
4+
:rtype: {{_returnType_}}
5+
"""
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""{{_header_}}"""

0 commit comments

Comments
 (0)