mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
restructure NameFinder.filter_name a little bit
This commit is contained in:
@@ -125,7 +125,9 @@ class Evaluator(object):
|
|||||||
result = self.eval_expression_list(expression_list)
|
result = self.eval_expression_list(expression_list)
|
||||||
|
|
||||||
ass_details = stmt.assignment_details
|
ass_details = stmt.assignment_details
|
||||||
if ass_details and ass_details[0][1] != '=' and False:
|
if ass_details and ass_details[0][1] != '=' and not isinstance(stmt,
|
||||||
|
er.InstanceElement) and False: # TODO don't check for this.
|
||||||
|
print('LEFT', ass_details, stmt, stmt.parent)
|
||||||
expr_list, operator = ass_details[0]
|
expr_list, operator = ass_details[0]
|
||||||
name = str(expr_list[0].name)
|
name = str(expr_list[0].name)
|
||||||
start_pos = stmt.start_pos[0] - 1, stmt.start_pos[1] + 30000
|
start_pos = stmt.start_pos[0] - 1, stmt.start_pos[1] + 30000
|
||||||
|
|||||||
@@ -279,8 +279,6 @@ class Builtin(CompiledObject):
|
|||||||
# access it.
|
# access it.
|
||||||
return [d for d in super(Builtin, self).get_defined_names() if d.name != 'None']
|
return [d for d in super(Builtin, self).get_defined_names() if d.name != 'None']
|
||||||
|
|
||||||
get_set_vars = get_defined_names
|
|
||||||
|
|
||||||
|
|
||||||
def _a_generator(foo):
|
def _a_generator(foo):
|
||||||
"""Used to have an object to return for generators."""
|
"""Used to have an object to return for generators."""
|
||||||
|
|||||||
@@ -52,21 +52,27 @@ class NameFinder(object):
|
|||||||
break_scopes = []
|
break_scopes = []
|
||||||
# here is the position stuff happening (sorting of variables)
|
# here is the position stuff happening (sorting of variables)
|
||||||
for name in sorted(name_list, key=lambda n: n.start_pos, reverse=True):
|
for name in sorted(name_list, key=lambda n: n.start_pos, reverse=True):
|
||||||
p = name.parent.parent if name.parent else None
|
parpar = name.parent.parent if name.parent else None
|
||||||
if isinstance(p, er.InstanceElement) \
|
if isinstance(parpar, er.InstanceElement) \
|
||||||
and isinstance(p.var, pr.Class):
|
and isinstance(parpar.var, pr.Class):
|
||||||
p = p.var
|
parpar = parpar.var
|
||||||
if self.name_str == name.get_code() and p not in break_scopes:
|
if self.name_str == name.get_code() and parpar not in break_scopes:
|
||||||
if not self._name_is_array_assignment(name):
|
if not self._name_is_array_assignment(name):
|
||||||
result.append(name) # `arr[1] =` is not the definition
|
result.append(name) # `arr[1] =` is not the definition
|
||||||
# for comparison we need the raw class
|
# for comparison we need the raw class
|
||||||
s = nscope.base if isinstance(nscope, er.Class) else nscope
|
|
||||||
# this means that a definition was found and is not e.g.
|
# this means that a definition was found and is not e.g.
|
||||||
# in if/else.
|
# in if/else.
|
||||||
if result and not self._name_is_no_break_scope(name):
|
if result and self._name_is_break_scope(name):
|
||||||
if not name.parent or p == s:
|
#print result, name.parent, parpar, s
|
||||||
|
if isinstance(parpar, pr.Flow) \
|
||||||
|
or isinstance(parpar, pr.KeywordStatement) \
|
||||||
|
and parpar.name == 'global':
|
||||||
|
s = nscope.base if isinstance(nscope, er.Class) else nscope
|
||||||
|
if parpar == s:
|
||||||
|
break
|
||||||
|
else:
|
||||||
break
|
break
|
||||||
break_scopes.append(p)
|
break_scopes.append(parpar)
|
||||||
if result:
|
if result:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -98,7 +104,7 @@ class NameFinder(object):
|
|||||||
result = inst.execute_subscope_by_name('__getattribute__', [name])
|
result = inst.execute_subscope_by_name('__getattribute__', [name])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _name_is_no_break_scope(self, name):
|
def _name_is_break_scope(self, name):
|
||||||
"""
|
"""
|
||||||
Returns the parent of a name, which means the element which stands
|
Returns the parent of a name, which means the element which stands
|
||||||
behind a name.
|
behind a name.
|
||||||
@@ -106,11 +112,11 @@ class NameFinder(object):
|
|||||||
par = name.parent
|
par = name.parent
|
||||||
if par.isinstance(pr.Statement):
|
if par.isinstance(pr.Statement):
|
||||||
if isinstance(name, er.InstanceElement) and not name.is_class_var:
|
if isinstance(name, er.InstanceElement) and not name.is_class_var:
|
||||||
return True
|
return False
|
||||||
elif isinstance(par, pr.Import) and len(par.namespace) > 1:
|
elif isinstance(par, pr.Import) and len(par.namespace) > 1:
|
||||||
# TODO multi-level import non-breakable
|
# TODO multi-level import non-breakable
|
||||||
return True
|
return False
|
||||||
return False
|
return True
|
||||||
|
|
||||||
def _name_is_array_assignment(self, name):
|
def _name_is_array_assignment(self, name):
|
||||||
if name.parent.isinstance(pr.Statement):
|
if name.parent.isinstance(pr.Statement):
|
||||||
|
|||||||
@@ -499,5 +499,4 @@ class FunctionExecution(Executable):
|
|||||||
return pr.Scope.get_statement_for_position(self, pos)
|
return pr.Scope.get_statement_for_position(self, pos)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % \
|
return "<%s of %s>" % (type(self).__name__, self.base)
|
||||||
(type(self).__name__, self.base)
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
""" Mainly for stupid error reports of @gwrtheyrn. :-) """
|
""" Mostly for stupid error reports of @dbrgn. :-) """
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user