start to get rid of the get_set_vars/get_defined_names distinction

This commit is contained in:
Dave Halter
2014-04-14 12:28:14 +02:00
parent 4c53a64ca0
commit 237af765b7
3 changed files with 7 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ def defined_names(evaluator, scope):
pair = next(get_names_of_scope(evaluator, scope, star_search=False,
include_builtin=False), None)
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)]

View File

@@ -167,8 +167,8 @@ class ImportPath(pr.Base):
# This is not an existing Import statement. Therefore, set position to
# 0 (0 is not a valid line number).
zero = (0, 0)
names = ((name_part.string, name_part.start_pos)
for name_part in i.namespace.names[1:])
names = [(name_part.string, name_part.start_pos)
for name_part in i.namespace.names[1:]]
n = pr.Name(i._sub_module, names, zero, zero, self.import_stmt)
new = pr.Import(i._sub_module, zero, zero, n)
new.parent = parent

View File

@@ -315,18 +315,9 @@ class Scope(Simple, IsScope, DocstringMixin):
... b.c = z
... '''))
>>> 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>]
"""
return [n for n in self.get_set_vars()
if isinstance(n, Import) or (len(n) == 1)]
return self.get_set_vars()
@Python3Method
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):
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
# (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
if parent is not None:
self.parent = parent