Skip to content

Commit 1334461

Browse files
committed
Use Sphinx style as default
This change affects to the default template and also the vim source file to archive following result: def foo(n: int, m: str) -> int: """foo :param n: :type n: int :param m: :type m: str :rtype: int """ pass The custom template follow Google style still works fine. I prefer to keep an empty line between `rtype` and `param` because: - It's easier to handle the logic. - It look better IMHO. Though, there's a small issue that is not easy to fix. See the following example: def foo(n: int, no_type) -> int: """foo :param n: :type n: int :param no_type :rtype: int """ pass Notice that there's no colon (`:`) after `no_type`.
1 parent c477aaa commit 1334461

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

autoload/pydocstring.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ function! s:builddocstring(strs, indent, nested_indent)
168168
let argTemplate = s:readtmpl('arg')
169169
let argTemplate = join(s:readtmpl('arg'), '')
170170
let argParts = split(arg, ':')
171-
let argTemplate = substitute(argTemplate, '{{_name_}}', argParts[0], '')
172-
let arg = substitute(argTemplate, '{{_type_}}', argParts[1], '')
171+
let argTemplate = substitute(argTemplate, '{{_name_}}', argParts[0], 'g')
172+
let arg = substitute(argTemplate, '{{_type_}}', argParts[1], 'g')
173173
endif
174174

175175
let template = substitute(template, '{{_args_}}', arg, 'g')
176-
let template = substitute(template, '{{_lf_}}', '\n', '')
176+
let template = substitute(template, '{{_lf_}}', '\n', 'g')
177177
let template = substitute(template, '{{_indent_}}', a:indent, 'g')
178178
let template = substitute(template, '{{_nested_indent_}}', a:nested_indent, 'g')
179179
call add(docstrings, a:indent . template)

template/pydocstring/arg.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{_name_}} ({{_type_}})
1+
{{_name_}}:{{_lf_}}{{_indent_}}:type {{_name_}}: {{_type_}}

template/pydocstring/multi.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""{{_header_}}
2-
:param {{_args_}}:
3-
return ({{_returnType_}}):
2+
:param {{_args_}}
3+
:rtype: {{_returnType_}}
44
"""

test/type-hint.vader

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Expect python:
1111
def foo() -> str:
1212
"""foo
1313

14-
return (str):
14+
:rtype: str
1515
"""
1616
pass
1717

@@ -25,9 +25,9 @@ Expect python:
2525
def foo(sample_var) -> str:
2626
"""foo
2727

28-
:param sample_var:
28+
:param sample_var
2929

30-
return (str):
30+
:rtype: str
3131
"""
3232
pass
3333

@@ -41,10 +41,10 @@ Expect python:
4141
def foo(arg1, arg2) -> str:
4242
"""foo
4343

44-
:param arg1:
45-
:param arg2:
44+
:param arg1
45+
:param arg2
4646

47-
return (str):
47+
:rtype: str
4848
"""
4949
pass
5050

@@ -59,9 +59,10 @@ Expect python:
5959
def foo(n: int) -> int:
6060
"""foo
6161

62-
:param n (int):
62+
:param n:
63+
:type n: int
6364

64-
return (int):
65+
:rtype: int
6566
"""
6667
pass
6768

@@ -76,10 +77,12 @@ Expect python:
7677
def foo(n: int, m: str) -> int:
7778
"""foo
7879

79-
:param n (int):
80-
:param m (str):
80+
:param n:
81+
:type n: int
82+
:param m:
83+
:type m: str
8184

82-
return (int):
85+
:rtype: int
8386
"""
8487
pass
8588

@@ -95,10 +98,11 @@ Expect python:
9598
def foo(n: int, arg) -> int:
9699
"""foo
97100

98-
:param n (int):
99-
:param arg:
101+
:param n:
102+
:type n: int
103+
:param arg
100104

101-
return (int):
105+
:rtype: int
102106
"""
103107
pass
104108

0 commit comments

Comments
 (0)