8000 introduced "local_function" decorator, which is similar to local_comm… · python-rope/ropemode@6ba1153 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ba1153

Browse files
author
angri
committed
introduced "local_function" decorator, which is similar to local_command,
but suppresses exceptions. methods definition_location, get_calltip, get_doc, completions, extended_completions now use it. thanks Anton Beloglazov for patch
1 parent 7feeee2 commit 6ba1153

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

ropemode/decorators.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ def lispfunction(func):
4747
exceptions.ModuleSyntaxError,
4848
exceptions.BadIdentifierError)
4949

50-
def _exception_handler(func):
50+
def _exception_handler(func, raise_exceptions, error_return):
5151
def newfunc(*args, **kwds):
5252
try:
5353
return func(*args, **kwds)
5454
except exceptions.RopeError, e:
5555
short = None
5656
if isinstance(e, input_exceptions):
57+
if not raise_exceptions:
58+
return error_return
5759
short = _exception_message(e)
5860
logger(str(traceback.format_exc()), short)
5961
newfunc.__name__ = func.__name__
@@ -72,10 +74,12 @@ def decorator(func):
7274
return func
7375
return decorator
7476

75-
76-
def local_command(key=None, prefix=False, shortcut=None, name=None):
77+
def local_command(key=None, prefix=False, shortcut=None,
78+
name=None, raise_exceptions=True,
79+
error_return=None):
7780
def decorator(func, name=name):
78-
func = _exception_handler(func)
81+
func = _exception_handler(func, raise_exceptions,
82+
error_return)
7983
func.kind = 'local'
8084
func.prefix = prefix
8185
func.local_key = key
@@ -86,10 +90,15 @@ def decorator(func, name=name):
8690
return func
8791
return decorator
8892

93+
def local_function(error_return=None):
94+
return local_command(raise_exceptions=False,
95+
error_return=error_return)
8996

90-
def global_command(key=None, prefix=False):
97+
def global_command(key=None, prefix=False, raise_exceptions=True,
98+
error_return=None):
9199
def decorator(func):
92-
func = _exception_handler(func)
100+
func = _exception_handler(func, raise_exceptions,
101+
error_return)
93102
func.kind = 'global'
94103
func.prefix = prefix
95104
func.global_key = key

ropemode/interface.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def goto_definition(self):
157157
def pop_mark(self):
158158
self.env.pop_mark()
159159

160-
@decorators.local_command()
160+
@decorators.local_function()
161161
def definition_location(self):
162162
definition = self._base_definition_location()
163163
if definition:
@@ -182,7 +182,7 @@ def show_doc(self, prefix):
182182
self._check_project()
183183
self._base_show_doc(prefix, self._base_get_doc(codeassist.get_doc))
184184

185-
@decorators.local_command()
185+
@decorators.local_function()
186186
def get_calltip(self):
187187
self._check_project()
188188
def _get_doc(project, text, offset, *args, **kwds):
@@ -203,7 +203,7 @@ def _base_show_doc(self, prefix, docs):
203203
else:
204204
self.env.message('No docs available!')
205205

206-
@decorators.local_command()
206+
@decorators.local_function()
207207
def get_doc(self):
208208
self._check_project()
209209
return self._base_get_doc(codeassist.get_doc)
@@ -275,11 +275,11 @@ def lucky_assist(self, prefix):
275275
def auto_import(self):
276276
_CodeAssist(self, self.env).auto_import()
277277

278-
@decorators.local_command()
278+
@decorators.local_function([])
279279
def completions(self):
280280
return _CodeAssist(self, self.env).completions()
281281

282-
@decorators.local_command()
282+
@decorators.local_function([])
283283
def extended_completions(self):
284284
return _CodeAssist(self, self.env).extended_completions()
285285

0 commit comments

Comments
 (0)
0