1
1
#!/usr/bin/env python3
2
- from string import Template
3
- import re
4
- import os
5
- import ast
6
2
import abc
3
+ import ast
4
+ import os
5
+ import re
6
+ from string import Template
7
7
8
8
import ibis
9
-
9
+ from asthelper import ClassInstanceNameExtractor , ClassVisitor , MethodVisitor
10
10
from utils import *
11
11
from vimenv import *
12
- from asthelper import ClassVisitor , MethodVisitor , ClassInstanceNameExtractor
13
12
14
13
15
14
class InvalidSyntax (Exception ):
@@ -256,7 +255,10 @@ def __init__(self):
256
255
257
256
def _controller_factory (self , env , templater ):
258
257
line = env .current_line
259
- first_word = re .match (r"^\s*(\w+).*" , line ).groups ()[0 ]
258
+ try :
259
+ first_word = re .match (r"^\s*(\w+).*" , line ).groups ()[0 ]
260
+ except Exception :
261
+ first_word = None
260
262
if first_word == "def" :
261
263
return MethodController (env , templater )
262
264
elif first_word == "class" :
@@ -268,18 +270,18 @@ def _controller_factory(self, env, templater):
268
270
if second_word == "def" :
269
271
return MethodController (env , templater )
270
272
271
- raise DocstringUnavailable ("Docstring cannot be created for selected object" )
273
+ raise DocstringUnavailable ("Docstring ERROR: Doctring cannot be created for selected object" )
272
274
273
275
def full_docstring (self , print_hints = False ):
274
276
"""Writes docstring containing arguments, returns, raises, ..."""
275
277
try :
276
278
self .obj_controller .write_docstring (print_hints = print_hints )
277
279
except Exception as e :
278
- print (concat_ ("Doctring ERROR: " , e ))
280
+ raise DocstringUnavailable (concat_ ("Docstring ERROR: " , e ))
279
281
280
282
def oneline_docstring (self ):
281
283
"""Writes only a one-line empty docstring"""
282
284
try :
283
285
self .obj_controller .write_simple_docstring ()
284
286
except Exception as e :
285
- print (concat_ ("Doctring ERROR: " , e ))
287
+ raise DocstringUnavailable (concat_ ("Docstring ERROR: " , e ))
0 commit comments