@@ -47,10 +47,10 @@ def _docstring_helper(self, obj_indent, docstring):
47
47
48
48
return '\n ' .join (lines )
49
49
50
- def get_method_docstring (self , method_indent , args , returns , yields , raises ):
50
+ def get_method_docstring (self , method_indent , args , returns , yields , raises , print_hints = False ):
51
51
with open (os .path .join (self .location , '..' , 'styles/{}-{}.txt' .format (self .style , 'method' )), 'r' ) as f :
52
52
self .template = ibis .Template (f .read ())
53
- docstring = self .template .render (indent = self .indent , args = args ,
53
+ docstring = self .template .render (indent = self .indent , args = args , hints = print_hints ,
54
54
raises = raises , returns = returns , yields = yields )
55
55
return self ._docstring_helper (method_indent , docstring )
56
56
@@ -71,7 +71,7 @@ class ObjectWithDocstring(abc.ABC):
71
71
72
72
"""
73
73
74
- def __init__ (self , env , templater , style = 'google' ):
74
+ def __init__ (self , env , templater ):
75
75
self .starting_line = env .current_line_nr
76
76
self .env = env
77
77
self .templater = templater
@@ -88,7 +88,7 @@ def _get_sig(self):
88
88
lines = []
89
89
lines_it = self .env .lines_following_cursor ()
90
90
sig_line , first_line = next (lines_it )
91
- indent = re .findall ('^(\s*)' , first_line )[0 ]
91
+ indent = re .findall (r '^(\s*)' , first_line )[0 ]
92
92
93
93
lines .append (first_line )
94
94
@@ -108,7 +108,7 @@ def _object_tree(self):
108
108
109
109
lines .append (first_line )
110
110
111
- obj_indent = re .findall ('^(\s*)' , first_line )[0 ]
111
+ obj_indent = re .findall (r '^(\s*)' , first_line )[0 ]
112
112
expected_indent = concat_ (obj_indent , self .env .python_indent )
113
113
114
114
valid_sig , _ = self ._is_valid (first_line )
@@ -182,8 +182,8 @@ def write_simple_docstring(self):
182
182
183
183
class MethodController (ObjectWithDocstring ):
184
184
185
- def __init__ (self , env , templater , style = 'google' ):
186
- super ().__init__ (env , templater , style )
185
+ def __init__ (self , env , templater ):
186
+ super ().__init__ (env , templater )
187
187
188
188
def _process_tree (self , tree ):
189
189
v = MethodVisitor ()
@@ -193,11 +193,11 @@ def _process_tree(self, tree):
193
193
return args , v .returns , v .yields , raises
194
194
195
195
# TODO: set cursor on appropriate position to fill the docstring
196
- def write_docstring (self ):
196
+ def write_docstring (self , print_hints = False ):
197
197
sig_line , method_indent , tree = self ._object_tree ()
198
198
args , returns , yields , raises = self ._process_tree (tree )
199
199
docstring = self .templater .get_method_docstring (
200
- method_indent , args , returns , yields , raises )
200
+ method_indent , args , returns , yields , raises , print_hints )
201
201
self .env .append_after_line (sig_line , docstring )
202
202
203
203
def _arguments (self , tree ):
@@ -214,8 +214,8 @@ def _arguments(self, tree):
214
214
215
215
class ClassController (ObjectWithDocstring ):
216
216
217
- def __init__ (self , env , templater , style = 'google' ):
218
- super ().__init__ (env , templater , style )
217
+ def __init__ (self , env , templater ):
218
+ super ().__init__ (env , templater )
219
219
220
220
def _process_tree (self , tree ):
221
221
x = ClassInstanceNameExtractor ()
@@ -240,31 +240,31 @@ def __init__(self):
240
240
style = env .python_style
241
241
indent = env .python_indent
242
242
location = env .plugin_root_dir
243
- templater = Templater (location , indent , style )
243
+ templater = Templater (location , indent = indent , style = style )
244
244
245
- self .obj_controller = self ._controller_factory (env , templater , style )
245
+ self .obj_controller = self ._controller_factory (env , templater )
246
246
247
- def _controller_factory (self , env , templater , style ):
247
+ def _controller_factory (self , env , templater ):
248
248
line = env .current_line
249
- first_word = re .match ('^\s*(\w+).*' , line ).groups ()[0 ]
249
+ first_word = re .match (r '^\s*(\w+).*' , line ).groups ()[0 ]
250
250
if first_word == 'def' :
251
- return MethodController (env , templater , style = style )
251
+ return MethodController (env , templater )
252
252
elif first_word == 'class' :
253
- return ClassController (env , templater , style = style )
253
+ return ClassController (env , templater )
254
254
elif first_word == 'async' :
255
- second_word_catch = re .match ('^\s*\w+\s+(\w+).*' , line )
255
+ second_word_catch = re .match (r '^\s*\w+\s+(\w+).*' , line )
256
256
if second_word_catch :
257
257
second_word = second_word_catch .groups ()[0 ]
258
258
if second_word == 'def' :
259
- return MethodController (env , templater , style = style )
259
+ return MethodController (env , templater )
260
260
261
261
raise DocstringUnavailable (
262
262
'Docstring cannot be created for selected object' )
263
263
264
- def full_docstring (self ):
264
+ def full_docstring (self , print_hints = False ):
265
265
""" Writes docstring containing arguments, returns, raises, ... """
266
266
try :
267
- self .obj_controller .write_docstring ()
267
+ self .obj_controller .write_docstring (print_hints = print_hints )
268
268
except Exception as e :
269
269
print (concat_ ('Doctring ERROR: ' , e ))
270
270
0 commit comments