Skip to content

Commit 9956586

Browse files
committed
docstringtypes works
1 parent a6d4d77 commit 9956586

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

autoload/vimpythondocstring.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function! vimpythondocstring#Full()
1717
endfunction
1818

1919
function! vimpythondocstring#FullTypes()
20-
python3 pydocstring.Docstring().full_docstring(types=True)
20+
python3 pydocstring.Docstring().full_docstring(print_hints=True)
2121
endfunction
2222

2323
function! vimpythondocstring#Oneline()

python/asthelper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ def _handle_functions(self, node):
8484

8585
if self.parent:
8686
for arg in node.args.args:
87-
self.arguments.append({'arg': arg.arg, 'type': ast.unparse(arg.annotation)})
87+
type_hint = None
88+
if arg.annotation is not None:
89+
type_hint = ast.unparse(arg.annotation)
90+
self.arguments.append({'arg': arg.arg, 'type': type_hint})
8891
if len(self.arguments) > 0 and (self.arguments[0] == 'self' or self.arguments[0] == 'cls'):
8992
self.arguments.pop(0)
9093

9194
self.returns = new_visitor.returns
9295
self.yields = new_visitor.yields
96+
print(self.arguments)
9397

9498
def visit_Raise(self, node):
9599
r = RaiseNameCollector()

python/pydocstring.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, env, templater):
7777
self.templater = templater
7878

7979
@abc.abstractmethod
80-
def write_docstring(self):
80+
def write_docstring(self, *args, **kwargs):
8181
""" Method to create a docstring for appropriate object
8282
8383
Writes the docstring to correct lines in `self.env` object.
@@ -225,7 +225,7 @@ def _process_tree(self, tree):
225225
att = list(v.attributes)
226226
return att
227227

228-
def write_docstring(self):
228+
def write_docstring(self, *args, **kwargs):
229229
sig_line, class_indent, tree = self._object_tree()
230230
attr = self._process_tree(tree)
231231
docstring = self.templater.get_class_docstring(class_indent, attr)
@@ -267,6 +267,7 @@ def full_docstring(self, print_hints=False):
267267
self.obj_controller.write_docstring(print_hints=print_hints)
268268
except Exception as e:
269269
print(concat_('Doctring ERROR: ', e))
270+
raise e
270271

271272
def oneline_docstring(self):
272273
""" Writes only a one-line empty docstring """

styles/google-method.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
{% if args|len > 0 %}
33
Args:
4-
{% for a in args %}{{indent}}{{a.arg}} {% if hints and a.type %}({{a.type}}){% endif %}:
4+
{% for a in args %}{{indent}}{{a.arg}}{% if hints and a.type %} ({{a.type}}){% endif %}:
55
{% endfor %}{% endif %}{% if returns %}
66
Returns:
77
{{indent}}

0 commit comments

Comments
 (0)