1
0
forked from VimPlug/jedi

use find_types instead of find_names

This commit is contained in:
Dave Halter
2014-01-06 14:29:23 +01:00
parent 0a87f8b02f
commit 53dbec52ab
6 changed files with 13 additions and 12 deletions

View File

@@ -178,7 +178,7 @@ class Evaluator(object):
builtin_scope = builtin.Builtin.scope
yield builtin_scope, builtin_scope.get_defined_names()
def find_name(self, scope, name_str, position=None, search_global=False,
def find_types(self, scope, name_str, position=None, search_global=False,
is_goto=False, resolve_decorator=True):
"""
This is the search function. The most important part to debug.
@@ -310,11 +310,11 @@ class Evaluator(object):
else:
if isinstance(current, pr.NamePart):
# This is the first global lookup.
scopes = self.find_name(scope, current, position=position,
scopes = self.find_types(scope, current, position=position,
search_global=True)
else:
# for pr.Literal
scopes = self.find_name(builtin.Builtin.scope, current.type_as_string())
scopes = self.find_types(builtin.Builtin.scope, current.type_as_string())
# Make instances of those number/string objects.
scopes = itertools.chain.from_iterable(
self.execute(s, (current.value,)) for s in scopes
@@ -380,7 +380,7 @@ class Evaluator(object):
# This is the typical lookup while chaining things.
if filter_private_variable(type, scope, current):
return []
result = imports.strip_imports(self, self.find_name(type, current,
result = imports.strip_imports(self, self.find_types(type, current,
position=position))
return self.follow_path(path, set(result), scope, position=position)
@@ -443,7 +443,7 @@ class Evaluator(object):
search_global = True
follow_res = []
for s in scopes:
follow_res += self.find_name(s, search, pos,
follow_res += self.find_types(s, search, pos,
search_global=search_global, is_goto=True)
return follow_res, search

View File

@@ -178,7 +178,7 @@ def search_params(evaluator, param):
pos = None
from jedi.evaluate import representation as er
for scope in scopes:
s = evaluator.find_name(scope, func_name, position=pos,
s = evaluator.find_types(scope, func_name, position=pos,
search_global=not first,
resolve_decorator=False)

View File

@@ -50,7 +50,7 @@ class NameFinder(object):
if r.is_global():
for token_name in r.token_list[1:]:
if isinstance(token_name, pr.Name):
add = evaluator.find_name(r.parent, str(token_name))
add = evaluator.find_types(r.parent, str(token_name))
else:
# generated objects are used within executions, but these
# objects are in functions, and we have to dynamically
@@ -79,7 +79,7 @@ class NameFinder(object):
c = r.expression_list()[0]
if c in ('*', '**'):
t = 'tuple' if c == '*' else 'dict'
res_new = evaluator.execute(evaluator.find_name(builtin.Builtin.scope, t)[0])
res_new = evaluator.execute(evaluator.find_types(builtin.Builtin.scope, t)[0])
if not r.assignment_details:
# this means that there are no default params,
# so just ignore it.
@@ -258,6 +258,7 @@ class NameFinder(object):
def find(self, scopes, resolve_decorator=True):
filtered = self.filter_name(scopes)
print 'f', filtered
return self._resolve_descriptors(self._remove_statements(filtered,
resolve_decorator))

View File

@@ -212,7 +212,7 @@ class ImportPath(pr.Base):
elif rest:
if is_goto:
scopes = itertools.chain.from_iterable(
self._evaluator.find_name(s, rest[0], is_goto=True)
self._evaluator.find_types(s, rest[0], is_goto=True)
for s in scopes)
else:
scopes = itertools.chain.from_iterable(

View File

@@ -129,7 +129,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
It returns e.g. for a list: append, pop, ...
"""
# `array.type` is a string with the type, e.g. 'list'.
scope = self._evaluator.find_name(builtin.Builtin.scope, self._array.type)[0]
scope = self._evaluator.find_types(builtin.Builtin.scope, self._array.type)[0]
scope = self._evaluator.execute(scope)[0] # builtins only have one class
names = scope.get_defined_names()
return [ArrayMethod(n) for n in names]

View File

@@ -257,7 +257,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
supers.append(cls)
if not supers and self.base.parent != builtin.Builtin.scope:
# add `object` to classes
supers += self._evaluator.find_name(builtin.Builtin.scope, 'object')
supers += self._evaluator.find_types(builtin.Builtin.scope, 'object')
return supers
@memoize_default(default=())
@@ -285,7 +285,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
@memoize_default(default=())
def get_defined_names(self):
result = self.instance_names()
type_cls = self._evaluator.find_name(builtin.Builtin.scope, 'type')[0]
type_cls = self._evaluator.find_types(builtin.Builtin.scope, 'type')[0]
return result + type_cls.base.get_defined_names()
def get_subscope_by_name(self, name):