Deprecate NotFoundError, because it wasn't used anymore.

This commit is contained in:
Dave Halter
2015-01-08 18:17:37 +01:00
parent 8ec8a74a3f
commit 301b4ca649
2 changed files with 30 additions and 38 deletions

View File

@@ -2,9 +2,7 @@
The API basically only provides one class. You can create a :class:`Script` and The API basically only provides one class. You can create a :class:`Script` and
use its methods. use its methods.
Additionally you can add a debug function with :func:`set_debug_function` and Additionally you can add a debug function with :func:`set_debug_function`.
catch :exc:`NotFoundError` which is being raised if your completion is not
possible.
.. warning:: Please, note that Jedi is **not thread safe**. .. warning:: Please, note that Jedi is **not thread safe**.
""" """
@@ -43,8 +41,13 @@ sys.setrecursionlimit(2000)
class NotFoundError(Exception): class NotFoundError(Exception):
"""A custom error to avoid catching the wrong exceptions.""" """A custom error to avoid catching the wrong exceptions.
# TODO deprecate this.
.. deprecated:: 0.9.0
Not in use anymore, Jedi just returns no goto result if you're not on a
valid name.
.. todo:: Remove!
"""
class Script(object): class Script(object):
@@ -135,13 +138,11 @@ class Script(object):
module = self._parser.module() module = self._parser.module()
names, level, only_modules, unfinished_dotted = \ names, level, only_modules, unfinished_dotted = \
helpers.check_error_statements(module, self._pos) helpers.check_error_statements(module, self._pos)
completions = [] completion_names = []
#print(importer.completion_names(self._evaluator, True))
if names is not None: if names is not None:
imp_names = [n for n in names if n.end_pos < self._pos] imp_names = [n for n in names if n.end_pos < self._pos]
i = imports.get_importer(self._evaluator, imp_names, module, level) i = imports.get_importer(self._evaluator, imp_names, module, level)
c_names = i.completion_names(self._evaluator, only_modules) completion_names = i.completion_names(self._evaluator, only_modules)
completions = [(name, module) for name in c_names]
# TODO this paragraph is necessary, but not sure it works. # TODO this paragraph is necessary, but not sure it works.
context = self._user_context.get_context() context = self._user_context.get_context()
@@ -150,24 +151,24 @@ class Script(object):
if next(context) == 'from': if next(context) == 'from':
# completion is just "import" if before stands from .. # completion is just "import" if before stands from ..
if unfinished_dotted: if unfinished_dotted:
return completions return completion_names
else: else:
return [(k, bs) for k in keywords.keyword_names('import')] return keywords.keyword_names('import')
if isinstance(user_stmt, pr.Import): if isinstance(user_stmt, pr.Import):
module = self._parser.module() module = self._parser.module()
completion_names = imports.completion_names(self._evaluator, completion_names += imports.completion_names(self._evaluator,
user_stmt, self._pos) user_stmt, self._pos)
return completions + [(n, module) for n in completion_names] return completion_names
if names is None and not isinstance(user_stmt, pr.Import): if names is None and not isinstance(user_stmt, pr.Import):
if not path and not dot: if not path and not dot:
# add keywords # add keywords
completions += ((k, b) for k in keywords.keyword_names(all=True)) completion_names += keywords.keyword_names(all=True)
# TODO delete? We should search for valid parser # TODO delete? We should search for valid parser
# transformations. # transformations.
completions += self._simple_complete(path, dot, like) completion_names += self._simple_complete(path, dot, like)
return completions return completion_names
debug.speed('completions start') debug.speed('completions start')
path = self._user_context.get_path_until_cursor() path = self._user_context.get_path_until_cursor()
@@ -180,7 +181,7 @@ class Script(object):
user_stmt = self._parser.user_stmt_with_whitespace() user_stmt = self._parser.user_stmt_with_whitespace()
b = compiled.builtin b = compiled.builtin
completions = get_completions(user_stmt, b) completion_names = get_completions(user_stmt, b)
if not dot: if not dot:
# add named params # add named params
@@ -194,13 +195,13 @@ class Script(object):
# public API and we don't want to make the internal # public API and we don't want to make the internal
# Name object public. # Name object public.
if p._definition.stars == 0: # no *args/**kwargs if p._definition.stars == 0: # no *args/**kwargs
completions.append((p._name, p._name)) completion_names.append(p._name)
needs_dot = not dot and path needs_dot = not dot and path
comps = [] comps = []
comp_dct = {} comp_dct = {}
for c, s in set(completions): for c in set(completion_names):
n = str(c) n = str(c)
if settings.case_insensitive_completion \ if settings.case_insensitive_completion \
and n.lower().startswith(like.lower()) \ and n.lower().startswith(like.lower()) \
@@ -233,30 +234,25 @@ class Script(object):
er.wrap(self._evaluator, scope), er.wrap(self._evaluator, scope),
self._pos self._pos
) )
completions = [] completion_names = []
for names_dict, pos in names_dicts: for names_dict, pos in names_dicts:
names = list(chain.from_iterable(names_dict.values())) names = list(chain.from_iterable(names_dict.values()))
if not names: if not names:
continue continue
names = filter_definition_names(names, self._parser.user_stmt(), pos) completion_names += filter_definition_names(names, self._parser.user_stmt(), pos)
for name in names:
completions.append((name, self._parser.user_scope()))
elif self._get_under_cursor_stmt(path) is None: elif self._get_under_cursor_stmt(path) is None:
return [] return []
else: else:
scopes = list(self._prepare_goto(path, True)) scopes = list(self._prepare_goto(path, True))
completions = [] completion_names = []
debug.dbg('possible completion scopes: %s', scopes) debug.dbg('possible completion scopes: %s', scopes)
for s in scopes: for s in scopes:
names = [] names = []
for names_dict in s.names_dicts(search_global=False): for names_dict in s.names_dicts(search_global=False):
names += chain.from_iterable(names_dict.values()) names += chain.from_iterable(names_dict.values())
names = filter_definition_names(names, self._parser.user_stmt()) completion_names += filter_definition_names(names, self._parser.user_stmt())
return completion_names
for c in names:
completions.append((c, s))
return completions
def _prepare_goto(self, goto_path, is_completion=False): def _prepare_goto(self, goto_path, is_completion=False):
""" """
@@ -300,10 +296,6 @@ class Script(object):
stmt = r.module.statements[-1] stmt = r.module.statements[-1]
except IndexError: except IndexError:
return None return None
raise NotFoundError()
if not isinstance(stmt, (pr.ExprStmt, pr.KeywordStatement)):
raise NotImplementedError
raise NotFoundError()
user_stmt = self._parser.user_stmt() user_stmt = self._parser.user_stmt()
if user_stmt is None: if user_stmt is None:
@@ -692,14 +684,14 @@ class Interpreter(Script):
except AttributeError: except AttributeError:
pass pass
completions = [] completion_names = []
for namespace in namespaces: for namespace in namespaces:
for name in dir(namespace): for name in dir(namespace):
if name.lower().startswith(like.lower()): if name.lower().startswith(like.lower()):
scope = self._parser.module() scope = self._parser.module()
n = FakeName(name, scope) n = FakeName(name, scope)
completions.append((n, scope)) completion_names.append(n)
return completions return completion_names
def defined_names(source, path=None, encoding='utf-8'): def defined_names(source, path=None, encoding='utf-8'):

View File

@@ -99,7 +99,7 @@ from import_tree.rename1 import abc
#< (0, 32), #< (0, 32),
from import_tree.rename1 import not_existing from import_tree.rename1 import not_existing
# Shouldn't work (would raise a NotFoundError, because there's no name.) # Shouldn't raise an error or do anything weird.
from not_existing import * from not_existing import *
# ----------------- # -----------------