forked from VimPlug/jedi
start to get rid of the get_set_vars/get_defined_names distinction
This commit is contained in:
@@ -29,6 +29,7 @@ def defined_names(evaluator, scope):
|
|||||||
pair = next(get_names_of_scope(evaluator, scope, star_search=False,
|
pair = next(get_names_of_scope(evaluator, scope, star_search=False,
|
||||||
include_builtin=False), None)
|
include_builtin=False), None)
|
||||||
names = pair[1] if pair else []
|
names = pair[1] if pair else []
|
||||||
|
names = [n for n in names if isinstance(n, pr.Import) or (len(n) == 1)]
|
||||||
return [Definition(evaluator, d) for d in sorted(names, key=lambda s: s.start_pos)]
|
return [Definition(evaluator, d) for d in sorted(names, key=lambda s: s.start_pos)]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ class ImportPath(pr.Base):
|
|||||||
# This is not an existing Import statement. Therefore, set position to
|
# This is not an existing Import statement. Therefore, set position to
|
||||||
# 0 (0 is not a valid line number).
|
# 0 (0 is not a valid line number).
|
||||||
zero = (0, 0)
|
zero = (0, 0)
|
||||||
names = ((name_part.string, name_part.start_pos)
|
names = [(name_part.string, name_part.start_pos)
|
||||||
for name_part in i.namespace.names[1:])
|
for name_part in i.namespace.names[1:]]
|
||||||
n = pr.Name(i._sub_module, names, zero, zero, self.import_stmt)
|
n = pr.Name(i._sub_module, names, zero, zero, self.import_stmt)
|
||||||
new = pr.Import(i._sub_module, zero, zero, n)
|
new = pr.Import(i._sub_module, zero, zero, n)
|
||||||
new.parent = parent
|
new.parent = parent
|
||||||
|
|||||||
@@ -315,18 +315,9 @@ class Scope(Simple, IsScope, DocstringMixin):
|
|||||||
... b.c = z
|
... b.c = z
|
||||||
... '''))
|
... '''))
|
||||||
>>> parser.module.get_defined_names()
|
>>> parser.module.get_defined_names()
|
||||||
[<Name: a@2,0>, <Name: b@3,0>]
|
|
||||||
|
|
||||||
Note that unlike :meth:`get_set_vars`, assignment to object
|
|
||||||
attribute does not change the result because it does not change
|
|
||||||
the defined names in this scope.
|
|
||||||
|
|
||||||
>>> parser.module.get_set_vars()
|
|
||||||
[<Name: a@2,0>, <Name: b@3,0>, <Name: b.c@4,0>]
|
[<Name: a@2,0>, <Name: b@3,0>, <Name: b.c@4,0>]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return [n for n in self.get_set_vars()
|
return self.get_set_vars()
|
||||||
if isinstance(n, Import) or (len(n) == 1)]
|
|
||||||
|
|
||||||
@Python3Method
|
@Python3Method
|
||||||
def get_statement_for_position(self, pos, include_imports=False):
|
def get_statement_for_position(self, pos, include_imports=False):
|
||||||
@@ -1433,10 +1424,11 @@ class Name(Simple):
|
|||||||
|
|
||||||
def __init__(self, module, names, start_pos, end_pos, parent=None):
|
def __init__(self, module, names, start_pos, end_pos, parent=None):
|
||||||
super(Name, self).__init__(module, start_pos, end_pos)
|
super(Name, self).__init__(module, start_pos, end_pos)
|
||||||
names = tuple(NamePart(n[0], self, n[1]) for n in names)
|
|
||||||
# Cache get_code, because it's used quite often for comparisons
|
# Cache get_code, because it's used quite often for comparisons
|
||||||
# (seen by using the profiler).
|
# (seen by using the profiler).
|
||||||
self._get_code = ".".join(unicode(n) for n in names)
|
self._get_code = ".".join(n[0] for n in names)
|
||||||
|
|
||||||
|
names = tuple(NamePart(n[0], self, n[1]) for n in names)
|
||||||
self.names = names
|
self.names = names
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|||||||
Reference in New Issue
Block a user