From a07374d0562c35b65ed2b4902ce90c53b107da0f Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Sun, 12 Feb 2017 00:27:47 +0900 Subject: [PATCH 1/2] Fix #17 Fix lack of end `:`. --- CHANGES.rst | 8 ++++++++ autoload/pydocstring.vim | 24 ++++++++++++++++++++---- doc/pydocstring.txt | 2 +- ftplugin/python/pydocstring.vim | 2 +- template/pydocstring/multi.txt | 2 +- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b6588a8..c0075c0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,11 @@ +Version 0.1.1 +------------- +Released on Feb 12th 2017 + +- Fix bug + If none typed arg, lack of last `:`. + see https://github.com/heavenshell/vim-pydocstring/issues/17 + Version 0.1.0 ------------- Released on Dec 25th 2016 diff --git a/autoload/pydocstring.vim b/autoload/pydocstring.vim index a0e0f28..ff21d80 100644 --- a/autoload/pydocstring.vim +++ b/autoload/pydocstring.vim @@ -1,6 +1,6 @@ " Insert Docstring. " Author: Shinya Ohyanagi -" Version: 0.1.0 +" Version: 0.1.1 " License: This file is placed in the public domain. " WebPage: http://github.com/heavenshell/vim-pydocstriong/ " Description: Generate Python docstring to your Python script file. @@ -163,22 +163,38 @@ function! s:builddocstring(strs, indent, nested_indent) continue endif let template = line - + let typed = 0 if match(arg, ':') != -1 let argTemplate = s:readtmpl('arg') let argTemplate = join(s:readtmpl('arg'), '') let argParts = split(arg, ':') let argTemplate = substitute(argTemplate, '{{_name_}}', argParts[0], 'g') let arg = substitute(argTemplate, '{{_type_}}', argParts[1], 'g') + let typed = 1 endif - let template = substitute(template, '{{_args_}}', arg, 'g') + if typed == 1 + " Fix following bugs. + " `def foo(arg: str):` generates like followings + " ``` + " :param arg: + " :type arg: str: + " ``` + " Template file describes as followings + " ``` + " ''' + " {{_header_}} + " :param {{_args_}}: + " :rtype: {{_returnType_}} + " ''' + let template = substitute(template, ':$', '', 'g') + endif let template = substitute(template, '{{_lf_}}', '\n', 'g') let template = substitute(template, '{{_indent_}}', a:indent, 'g') let template = substitute(template, '{{_nested_indent_}}', a:nested_indent, 'g') call add(docstrings, a:indent . template) endfor - call add(docstrings, '' ) + call add(docstrings, '') endif elseif line =~ '{{_indent_}}' let arg = substitute(line, '{{_indent_}}', a:indent, 'g') diff --git a/doc/pydocstring.txt b/doc/pydocstring.txt index 111be97..1255359 100644 --- a/doc/pydocstring.txt +++ b/doc/pydocstring.txt @@ -1,6 +1,6 @@ *pydocstring.txt* Generate Python docstring to your Python code. -Version: 0.1.0 +Version: 0.1.1 Author: Shinya Ohynagi Repository: http://github.com/heavenshell/vim-pydocstring/ License: BSD, see LICENSE for more details. diff --git a/ftplugin/python/pydocstring.vim b/ftplugin/python/pydocstring.vim index 7c4bda3..6210bd2 100644 --- a/ftplugin/python/pydocstring.vim +++ b/ftplugin/python/pydocstring.vim @@ -1,6 +1,6 @@ " File: pydocstring.vim " Author: Shinya Ohyanagi -" Version: 0.1.0 +" Version: 0.1.1 " WebPage: http://github.com/heavenshell/vim-pydocstriong/ " Description: Generate Python docstring to your Python script file. " License: BSD, see LICENSE for more details. diff --git a/template/pydocstring/multi.txt b/template/pydocstring/multi.txt index a37bb0b..86a1e80 100644 --- a/template/pydocstring/multi.txt +++ b/template/pydocstring/multi.txt @@ -1,4 +1,4 @@ """{{_header_}} -:param {{_args_}} +:param {{_args_}}: :rtype: {{_returnType_}} """ From 60723370de2cb5ce3aa092477b9c21ec3945750c Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Sun, 12 Feb 2017 00:34:13 +0900 Subject: [PATCH 2/2] Fix tests --- test/type-hint.vader | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/type-hint.vader b/test/type-hint.vader index 64bee40..f9b42c3 100644 --- a/test/type-hint.vader +++ b/test/type-hint.vader @@ -25,7 +25,7 @@ Expect python: def foo(sample_var) -> str: """foo - :param sample_var + :param sample_var: :rtype: str """ @@ -41,8 +41,8 @@ Expect python: def foo(arg1, arg2) -> str: """foo - :param arg1 - :param arg2 + :param arg1: + :param arg2: :rtype: str """ @@ -100,7 +100,7 @@ Expect python: :param n: :type n: int - :param arg + :param arg: :rtype: int """