mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +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)
|
||||
|
||||
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]
|
||||
name = str(expr_list[0].name)
|
||||
start_pos = stmt.start_pos[0] - 1, stmt.start_pos[1] + 30000
|
||||
|
||||
@@ -279,8 +279,6 @@ class Builtin(CompiledObject):
|
||||
# access it.
|
||||
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):
|
||||
"""Used to have an object to return for generators."""
|
||||
|
||||
@@ -52,21 +52,27 @@ class NameFinder(object):
|
||||
break_scopes = []
|
||||
# here is the position stuff happening (sorting of variables)
|
||||
for name in sorted(name_list, key=lambda n: n.start_pos, reverse=True):
|
||||
p = name.parent.parent if name.parent else None
|
||||
if isinstance(p, er.InstanceElement) \
|
||||
and isinstance(p.var, pr.Class):
|
||||
p = p.var
|
||||
if self.name_str == name.get_code() and p not in break_scopes:
|
||||
parpar = name.parent.parent if name.parent else None
|
||||
if isinstance(parpar, er.InstanceElement) \
|
||||
and isinstance(parpar.var, pr.Class):
|
||||
parpar = parpar.var
|
||||
if self.name_str == name.get_code() and parpar not in break_scopes:
|
||||
if not self._name_is_array_assignment(name):
|
||||
result.append(name) # `arr[1] =` is not the definition
|
||||
# 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.
|
||||
# in if/else.
|
||||
if result and not self._name_is_no_break_scope(name):
|
||||
if not name.parent or p == s:
|
||||
if result and self._name_is_break_scope(name):
|
||||
#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
|
||||
break_scopes.append(p)
|
||||
else:
|
||||
break
|
||||
break_scopes.append(parpar)
|
||||
if result:
|
||||
break
|
||||
|
||||
@@ -98,7 +104,7 @@ class NameFinder(object):
|
||||
result = inst.execute_subscope_by_name('__getattribute__', [name])
|
||||
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
|
||||
behind a name.
|
||||
@@ -106,11 +112,11 @@ class NameFinder(object):
|
||||
par = name.parent
|
||||
if par.isinstance(pr.Statement):
|
||||
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:
|
||||
# TODO multi-level import non-breakable
|
||||
return True
|
||||
return False
|
||||
return True
|
||||
|
||||
def _name_is_array_assignment(self, name):
|
||||
if name.parent.isinstance(pr.Statement):
|
||||
|
||||
@@ -499,5 +499,4 @@ class FunctionExecution(Executable):
|
||||
return pr.Scope.get_statement_for_position(self, pos)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % \
|
||||
(type(self).__name__, self.base)
|
||||
return "<%s of %s>" % (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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user