remove get_set_vars completely from existance

This commit is contained in:
Dave Halter
2014-04-14 12:40:59 +02:00
parent 237af765b7
commit 6a40c9b671
9 changed files with 37 additions and 52 deletions

View File

@@ -452,7 +452,7 @@ class Script(object):
itself, if the name is ``foo``, but not ``foo.bar``.
"""
if isinstance(user_stmt, pr.Statement):
for name in user_stmt.get_set_vars():
for name in user_stmt.get_defined_names():
if name.start_pos <= self._pos <= name.end_pos \
and len(name.names) == 1:
return name, name.names[-1]
@@ -504,7 +504,7 @@ class Script(object):
c = user_stmt.expression_list()[0]
if not isinstance(c, unicode) and self._pos < c.start_pos:
# the search_name might be before `=`
definitions = [v for v in user_stmt.get_set_vars()
definitions = [v for v in user_stmt.get_defined_names()
if unicode(v.names[-1]) == search_name]
if not isinstance(user_stmt, pr.Import):
# import case is looked at with add_import_name option

View File

@@ -42,7 +42,7 @@ def usages(evaluator, definitions, search_name, mods):
stmt = stmt.parent
# New definition, call cannot be a part of stmt
if len(call.name) == 1 and call.execution is None \
and call.name in stmt.get_set_vars():
and call.name in stmt.get_defined_names():
# Class params are not definitions (like function params). They
# are super classes, that need to be resolved.
if not (isinstance(stmt, pr.Param) and isinstance(stmt.parent, pr.Class)):

View File

@@ -142,7 +142,7 @@ class Evaluator(object):
result = left
else:
result = precedence.calculate(self, left, operator, result)
elif len(stmt.get_set_vars()) > 1 and seek_name and ass_details:
elif len(stmt.get_defined_names()) > 1 and seek_name and ass_details:
# Assignment checking is only important if the statement defines
# multiple variables.
new_result = []

View File

@@ -447,7 +447,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
reraise(common.MultiLevelStopIteration, sys.exc_info()[2])
if scope.isinstance(pr.ForFlow) and scope.is_list_comp:
# is a list comprehension
yield scope, scope.get_set_vars(is_internal_call=True)
yield scope, scope.get_defined_names(is_internal_call=True)
scope = scope.parent
# This is used, because subscopes (Flow scopes) would distort the

View File

@@ -14,7 +14,7 @@ def fast_parent_copy(obj):
if isinstance(obj, pr.Statement):
# Need to set _set_vars, otherwise the cache is not working
# correctly, don't know why.
obj.get_set_vars()
obj.get_defined_names()
new_obj = copy.copy(obj)
new_elements[obj] = new_obj

View File

@@ -109,7 +109,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
# because to follow them and their self variables is too
# complicated.
sub = self._get_method_execution(sub)
for n in sub.get_set_vars():
for n in sub.get_defined_names():
# Only names with the selfname are being added.
# It is also important, that they have a len() of 2,
# because otherwise, they are just something else
@@ -446,9 +446,7 @@ class FunctionExecution(Executable):
Call the default method with the own instance (self implements all
the necessary functions). Add also the params.
"""
return self._get_params() + pr.Scope.get_set_vars(self)
get_set_vars = get_defined_names
return self._get_params() + pr.Scope.get_defined_names(self)
def _copy_properties(self, prop):
"""

View File

@@ -191,7 +191,7 @@ class Parser(object):
param.add_annotation(annotation)
# params without vars are usually syntax errors.
if param and (param.get_set_vars()):
if param and (param.get_defined_names()):
param.position_nr = pos
names.append(param)
pos += 1

View File

@@ -280,29 +280,6 @@ class Scope(Simple, IsScope, DocstringMixin):
return string
@Python3Method
def get_set_vars(self):
"""
Get all the names, that are active and accessible in the current
scope. See :meth:`get_defined_names` for examples.
:return: list of Name
:rtype: list
"""
n = []
for stmt in self.statements:
try:
n += stmt.get_set_vars(True)
except TypeError:
n += stmt.get_set_vars()
# function and class names
n += [s.name for s in self.subscopes]
for i in self.imports:
if not i.star:
n += i.get_defined_names()
return n
def get_defined_names(self):
"""
Get all defined names in this scope.
@@ -317,7 +294,20 @@ class Scope(Simple, IsScope, DocstringMixin):
>>> parser.module.get_defined_names()
[<Name: a@2,0>, <Name: b@3,0>, <Name: b.c@4,0>]
"""
return self.get_set_vars()
n = []
for stmt in self.statements:
try:
n += stmt.get_defined_names(True)
except TypeError:
n += stmt.get_defined_names()
# function and class names
n += [s.name for s in self.subscopes]
for i in self.imports:
if not i.star:
n += i.get_defined_names()
return n
@Python3Method
def get_statement_for_position(self, pos, include_imports=False):
@@ -408,8 +398,8 @@ class SubModule(Scope, Module):
# set no parent here, because globals are not defined in this scope.
self.global_vars.append(name)
def get_set_vars(self):
n = super(SubModule, self).get_set_vars()
def get_defined_names(self):
n = super(SubModule, self).get_defined_names()
n += self.global_vars
return n
@@ -528,8 +518,8 @@ class Function(Scope):
string += super(Function, self).get_code(True, indention)
return string
def get_set_vars(self):
n = super(Function, self).get_set_vars()
def get_defined_names(self):
n = super(Function, self).get_defined_names()
for p in self.params:
try:
n.append(p.get_name())
@@ -645,7 +635,7 @@ class Flow(Scope):
string += self.next.get_code()
return string
def get_set_vars(self, is_internal_call=False):
def get_defined_names(self, is_internal_call=False):
"""
Get the names for the flow. This includes also a call to the super
class.
@@ -657,13 +647,13 @@ class Flow(Scope):
if is_internal_call:
n = list(self.set_vars)
for s in self.inputs:
n += s.get_set_vars()
n += s.get_defined_names()
if self.next:
n += self.next.get_set_vars(is_internal_call)
n += super(Flow, self).get_set_vars()
n += self.next.get_defined_names(is_internal_call)
n += super(Flow, self).get_defined_names()
return n
else:
return self.get_parent_until((Class, Function)).get_set_vars()
return self.get_parent_until((Class, Function)).get_defined_names()
def get_imports(self):
i = super(Flow, self).get_imports()
@@ -692,7 +682,7 @@ class ForFlow(Flow):
set_stmt.parent = self.use_as_parent
self.is_list_comp = is_list_comp
self.set_vars = set_stmt.get_set_vars()
self.set_vars = set_stmt.get_defined_names()
for s in self.set_vars:
s.parent.parent = self.use_as_parent
s.parent = self.use_as_parent
@@ -774,9 +764,6 @@ class Import(Simple):
else:
return [self.namespace]
def get_set_vars(self):
return self.get_defined_names()
def get_all_import_names(self):
n = []
if self.from_ns:
@@ -810,7 +797,7 @@ class KeywordStatement(Base):
else:
return '%s %s\n' % (self.name, self._stmt)
def get_set_vars(self):
def get_defined_names(self):
return []
@property
@@ -881,7 +868,7 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
else:
return code
def get_set_vars(self):
def get_defined_names(self):
""" Get the names for the statement. """
if self._set_vars is None:
@@ -1187,7 +1174,7 @@ class Param(Statement):
def get_name(self):
""" get the name of the param """
n = self.get_set_vars()
n = self.get_defined_names()
if len(n) > 1:
debug.warning("Multiple param names (%s).", n)
return n[0]

View File

@@ -188,7 +188,7 @@ def inline(script):
replace_str = '(%s)' % replace_str
# if it's the only assignment, remove the statement
if len(stmt.get_set_vars()) == 1:
if len(stmt.get_defined_names()) == 1:
line = line[:stmt.start_pos[1]] + line[stmt.end_pos[1]:]
dct = _rename(inlines, replace_str)