@@ -47,10 +47,10 @@ def _docstring_helper(self, obj_indent, docstring):
4747
4848 return '\n ' .join (lines )
4949
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 ):
5151 with open (os .path .join (self .location , '..' , 'styles/{}-{}.txt' .format (self .style , 'method' )), 'r' ) as f :
5252 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 ,
5454 raises = raises , returns = returns , yields = yields )
5555 return self ._docstring_helper (method_indent , docstring )
5656
@@ -71,7 +71,7 @@ class ObjectWithDocstring(abc.ABC):
7171
7272 """
7373
74- def __init__ (self , env , templater , style = 'google' ):
74+ def __init__ (self , env , templater ):
7575 self .starting_line = env .current_line_nr
7676 self .env = env
7777 self .templater = templater
@@ -88,7 +88,7 @@ def _get_sig(self):
8888 lines = []
8989 lines_it = self .env .lines_following_cursor ()
9090 sig_line , first_line = next (lines_it )
91- indent = re .findall ('^(\s*)' , first_line )[0 ]
91+ indent = re .findall (r '^(\s*)' , first_line )[0 ]
9292
9393 lines .append (first_line )
9494
@@ -108,7 +108,7 @@ def _object_tree(self):
108108
109109 lines .append (first_line )
110110
111- obj_indent = re .findall ('^(\s*)' , first_line )[0 ]
111+ obj_indent = re .findall (r '^(\s*)' , first_line )[0 ]
112112 expected_indent = concat_ (obj_indent , self .env .python_indent )
113113
114114 valid_sig , _ = self ._is_valid (first_line )
@@ -182,8 +182,8 @@ def write_simple_docstring(self):
182182
183183class MethodController (ObjectWithDocstring ):
184184
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 )
187187
188188 def _process_tree (self , tree ):
189189 v = MethodVisitor ()
@@ -193,11 +193,11 @@ def _process_tree(self, tree):
193193 return args , v .returns , v .yields , raises
194194
195195 # TODO: set cursor on appropriate position to fill the docstring
196- def write_docstring (self ):
196+ def write_docstring (self , print_hints = False ):
197197 sig_line , method_indent , tree = self ._object_tree ()
198198 args , returns , yields , raises = self ._process_tree (tree )
199199 docstring = self .templater .get_method_docstring (
200- method_indent , args , returns , yields , raises )
200+ method_indent , args , returns , yields , raises , print_hints )
201201 self .env .append_after_line (sig_line , docstring )
202202
203203 def _arguments (self , tree ):
@@ -214,8 +214,8 @@ def _arguments(self, tree):
214214
215215class ClassController (ObjectWithDocstring ):
216216
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 )
219219
220220 def _process_tree (self , tree ):
221221 x = ClassInstanceNameExtractor ()
@@ -240,31 +240,31 @@ def __init__(self):
240240 style = env .python_style
241241 indent = env .python_indent
242242 location = env .plugin_root_dir
243- templater = Templater (location , indent , style )
243+ templater = Templater (location , indent = indent , style = style )
244244
245- self .obj_controller = self ._controller_factory (env , templater , style )
245+ self .obj_controller = self ._controller_factory (env , templater )
246246
247- def _controller_factory (self , env , templater , style ):
247+ def _controller_factory (self , env , templater ):
248248 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 ]
250250 if first_word == 'def' :
251- return MethodController (env , templater , style = style )
251+ return MethodController (env , templater )
252252 elif first_word == 'class' :
253- return ClassController (env , templater , style = style )
253+ return ClassController (env , templater )
254254 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 )
256256 if second_word_catch :
257257 second_word = second_word_catch .groups ()[0 ]
258258 if second_word == 'def' :
259- return MethodController (env , templater , style = style )
259+ return MethodController (env , templater )
260260
261261 raise DocstringUnavailable (
262262 'Docstring cannot be created for selected object' )
263263
264- def full_docstring (self ):
264+ def full_docstring (self , print_hints = False ):
265265 """ Writes docstring containing arguments, returns, raises, ... """
266266 try :
267- self .obj_controller .write_docstring ()
267+ self .obj_controller .write_docstring (print_hints = print_hints )
268268 except Exception as e :
269269 print (concat_ ('Doctring ERROR: ' , e ))
270270
0 commit comments