mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
remove get_set_vars completely from existance
This commit is contained in:
@@ -452,7 +452,7 @@ class Script(object):
|
|||||||
itself, if the name is ``foo``, but not ``foo.bar``.
|
itself, if the name is ``foo``, but not ``foo.bar``.
|
||||||
"""
|
"""
|
||||||
if isinstance(user_stmt, pr.Statement):
|
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 \
|
if name.start_pos <= self._pos <= name.end_pos \
|
||||||
and len(name.names) == 1:
|
and len(name.names) == 1:
|
||||||
return name, name.names[-1]
|
return name, name.names[-1]
|
||||||
@@ -504,7 +504,7 @@ class Script(object):
|
|||||||
c = user_stmt.expression_list()[0]
|
c = user_stmt.expression_list()[0]
|
||||||
if not isinstance(c, unicode) and self._pos < c.start_pos:
|
if not isinstance(c, unicode) and self._pos < c.start_pos:
|
||||||
# the search_name might be before `=`
|
# 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 unicode(v.names[-1]) == search_name]
|
||||||
if not isinstance(user_stmt, pr.Import):
|
if not isinstance(user_stmt, pr.Import):
|
||||||
# import case is looked at with add_import_name option
|
# import case is looked at with add_import_name option
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
stmt = stmt.parent
|
stmt = stmt.parent
|
||||||
# New definition, call cannot be a part of stmt
|
# New definition, call cannot be a part of stmt
|
||||||
if len(call.name) == 1 and call.execution is None \
|
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
|
# Class params are not definitions (like function params). They
|
||||||
# are super classes, that need to be resolved.
|
# are super classes, that need to be resolved.
|
||||||
if not (isinstance(stmt, pr.Param) and isinstance(stmt.parent, pr.Class)):
|
if not (isinstance(stmt, pr.Param) and isinstance(stmt.parent, pr.Class)):
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class Evaluator(object):
|
|||||||
result = left
|
result = left
|
||||||
else:
|
else:
|
||||||
result = precedence.calculate(self, left, operator, result)
|
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
|
# Assignment checking is only important if the statement defines
|
||||||
# multiple variables.
|
# multiple variables.
|
||||||
new_result = []
|
new_result = []
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
|
|||||||
reraise(common.MultiLevelStopIteration, sys.exc_info()[2])
|
reraise(common.MultiLevelStopIteration, sys.exc_info()[2])
|
||||||
if scope.isinstance(pr.ForFlow) and scope.is_list_comp:
|
if scope.isinstance(pr.ForFlow) and scope.is_list_comp:
|
||||||
# is a list comprehension
|
# 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
|
scope = scope.parent
|
||||||
# This is used, because subscopes (Flow scopes) would distort the
|
# This is used, because subscopes (Flow scopes) would distort the
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def fast_parent_copy(obj):
|
|||||||
if isinstance(obj, pr.Statement):
|
if isinstance(obj, pr.Statement):
|
||||||
# Need to set _set_vars, otherwise the cache is not working
|
# Need to set _set_vars, otherwise the cache is not working
|
||||||
# correctly, don't know why.
|
# correctly, don't know why.
|
||||||
obj.get_set_vars()
|
obj.get_defined_names()
|
||||||
|
|
||||||
new_obj = copy.copy(obj)
|
new_obj = copy.copy(obj)
|
||||||
new_elements[obj] = new_obj
|
new_elements[obj] = new_obj
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
# because to follow them and their self variables is too
|
# because to follow them and their self variables is too
|
||||||
# complicated.
|
# complicated.
|
||||||
sub = self._get_method_execution(sub)
|
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.
|
# Only names with the selfname are being added.
|
||||||
# It is also important, that they have a len() of 2,
|
# It is also important, that they have a len() of 2,
|
||||||
# because otherwise, they are just something else
|
# 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
|
Call the default method with the own instance (self implements all
|
||||||
the necessary functions). Add also the params.
|
the necessary functions). Add also the params.
|
||||||
"""
|
"""
|
||||||
return self._get_params() + pr.Scope.get_set_vars(self)
|
return self._get_params() + pr.Scope.get_defined_names(self)
|
||||||
|
|
||||||
get_set_vars = get_defined_names
|
|
||||||
|
|
||||||
def _copy_properties(self, prop):
|
def _copy_properties(self, prop):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class Parser(object):
|
|||||||
param.add_annotation(annotation)
|
param.add_annotation(annotation)
|
||||||
|
|
||||||
# params without vars are usually syntax errors.
|
# 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
|
param.position_nr = pos
|
||||||
names.append(param)
|
names.append(param)
|
||||||
pos += 1
|
pos += 1
|
||||||
|
|||||||
@@ -280,29 +280,6 @@ class Scope(Simple, IsScope, DocstringMixin):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
@Python3Method
|
@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):
|
def get_defined_names(self):
|
||||||
"""
|
"""
|
||||||
Get all defined names in this scope.
|
Get all defined names in this scope.
|
||||||
@@ -317,7 +294,20 @@ class Scope(Simple, IsScope, DocstringMixin):
|
|||||||
>>> parser.module.get_defined_names()
|
>>> parser.module.get_defined_names()
|
||||||
[<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 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
|
@Python3Method
|
||||||
def get_statement_for_position(self, pos, include_imports=False):
|
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.
|
# set no parent here, because globals are not defined in this scope.
|
||||||
self.global_vars.append(name)
|
self.global_vars.append(name)
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_defined_names(self):
|
||||||
n = super(SubModule, self).get_set_vars()
|
n = super(SubModule, self).get_defined_names()
|
||||||
n += self.global_vars
|
n += self.global_vars
|
||||||
return n
|
return n
|
||||||
|
|
||||||
@@ -528,8 +518,8 @@ class Function(Scope):
|
|||||||
string += super(Function, self).get_code(True, indention)
|
string += super(Function, self).get_code(True, indention)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_defined_names(self):
|
||||||
n = super(Function, self).get_set_vars()
|
n = super(Function, self).get_defined_names()
|
||||||
for p in self.params:
|
for p in self.params:
|
||||||
try:
|
try:
|
||||||
n.append(p.get_name())
|
n.append(p.get_name())
|
||||||
@@ -645,7 +635,7 @@ class Flow(Scope):
|
|||||||
string += self.next.get_code()
|
string += self.next.get_code()
|
||||||
return string
|
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
|
Get the names for the flow. This includes also a call to the super
|
||||||
class.
|
class.
|
||||||
@@ -657,13 +647,13 @@ class Flow(Scope):
|
|||||||
if is_internal_call:
|
if is_internal_call:
|
||||||
n = list(self.set_vars)
|
n = list(self.set_vars)
|
||||||
for s in self.inputs:
|
for s in self.inputs:
|
||||||
n += s.get_set_vars()
|
n += s.get_defined_names()
|
||||||
if self.next:
|
if self.next:
|
||||||
n += self.next.get_set_vars(is_internal_call)
|
n += self.next.get_defined_names(is_internal_call)
|
||||||
n += super(Flow, self).get_set_vars()
|
n += super(Flow, self).get_defined_names()
|
||||||
return n
|
return n
|
||||||
else:
|
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):
|
def get_imports(self):
|
||||||
i = super(Flow, self).get_imports()
|
i = super(Flow, self).get_imports()
|
||||||
@@ -692,7 +682,7 @@ class ForFlow(Flow):
|
|||||||
set_stmt.parent = self.use_as_parent
|
set_stmt.parent = self.use_as_parent
|
||||||
self.is_list_comp = is_list_comp
|
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:
|
for s in self.set_vars:
|
||||||
s.parent.parent = self.use_as_parent
|
s.parent.parent = self.use_as_parent
|
||||||
s.parent = self.use_as_parent
|
s.parent = self.use_as_parent
|
||||||
@@ -774,9 +764,6 @@ class Import(Simple):
|
|||||||
else:
|
else:
|
||||||
return [self.namespace]
|
return [self.namespace]
|
||||||
|
|
||||||
def get_set_vars(self):
|
|
||||||
return self.get_defined_names()
|
|
||||||
|
|
||||||
def get_all_import_names(self):
|
def get_all_import_names(self):
|
||||||
n = []
|
n = []
|
||||||
if self.from_ns:
|
if self.from_ns:
|
||||||
@@ -810,7 +797,7 @@ class KeywordStatement(Base):
|
|||||||
else:
|
else:
|
||||||
return '%s %s\n' % (self.name, self._stmt)
|
return '%s %s\n' % (self.name, self._stmt)
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_defined_names(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -881,7 +868,7 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
|
|||||||
else:
|
else:
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_defined_names(self):
|
||||||
""" Get the names for the statement. """
|
""" Get the names for the statement. """
|
||||||
if self._set_vars is None:
|
if self._set_vars is None:
|
||||||
|
|
||||||
@@ -1187,7 +1174,7 @@ class Param(Statement):
|
|||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
""" get the name of the param """
|
""" get the name of the param """
|
||||||
n = self.get_set_vars()
|
n = self.get_defined_names()
|
||||||
if len(n) > 1:
|
if len(n) > 1:
|
||||||
debug.warning("Multiple param names (%s).", n)
|
debug.warning("Multiple param names (%s).", n)
|
||||||
return n[0]
|
return n[0]
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ def inline(script):
|
|||||||
replace_str = '(%s)' % replace_str
|
replace_str = '(%s)' % replace_str
|
||||||
|
|
||||||
# if it's the only assignment, remove the statement
|
# 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]:]
|
line = line[:stmt.start_pos[1]] + line[stmt.end_pos[1]:]
|
||||||
|
|
||||||
dct = _rename(inlines, replace_str)
|
dct = _rename(inlines, replace_str)
|
||||||
|
|||||||
Reference in New Issue
Block a user