mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
Refactor a few name finder things.
This commit is contained in:
@@ -91,7 +91,7 @@ class NameFinder(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Exclude `arr[1] =` from the result set.
|
# Exclude `arr[1] =` from the result set.
|
||||||
if not self._name_is_array_assignment(name):
|
if not self._name_is_array_assignment(name, stmt):
|
||||||
# TODO we ignore a lot of elements here that should not be
|
# TODO we ignore a lot of elements here that should not be
|
||||||
# ignored. But then again flow_analysis also stops when the
|
# ignored. But then again flow_analysis also stops when the
|
||||||
# input scope is reached. This is not correct: variables
|
# input scope is reached. This is not correct: variables
|
||||||
@@ -113,7 +113,7 @@ class NameFinder(object):
|
|||||||
if check is flow_analysis.REACHABLE:
|
if check is flow_analysis.REACHABLE:
|
||||||
break
|
break
|
||||||
|
|
||||||
if result and self._is_name_break_scope(name):
|
if result and self._is_name_break_scope(name, stmt):
|
||||||
if self._does_scope_break_immediately(scope, name_list_scope):
|
if self._does_scope_break_immediately(scope, name_list_scope):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -148,15 +148,14 @@ class NameFinder(object):
|
|||||||
result = inst.execute_subscope_by_name('__getattribute__', [name])
|
result = inst.execute_subscope_by_name('__getattribute__', [name])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _is_name_break_scope(self, name):
|
def _is_name_break_scope(self, name, stmt):
|
||||||
"""
|
"""
|
||||||
Returns True except for nested imports and instance variables.
|
Returns True except for nested imports and instance variables.
|
||||||
"""
|
"""
|
||||||
par = name.parent
|
if stmt.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 False
|
return False
|
||||||
elif isinstance(par, pr.Import) and par.is_nested():
|
elif isinstance(stmt, pr.Import) and stmt.is_nested():
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -175,8 +174,8 @@ class NameFinder(object):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _name_is_array_assignment(self, name):
|
def _name_is_array_assignment(self, name, stmt):
|
||||||
if name.parent.isinstance(pr.Statement):
|
if stmt.isinstance(pr.Statement):
|
||||||
def is_execution(calls):
|
def is_execution(calls):
|
||||||
for c in calls:
|
for c in calls:
|
||||||
if isinstance(c, (unicode, str, tokenize.Token)):
|
if isinstance(c, (unicode, str, tokenize.Token)):
|
||||||
@@ -193,7 +192,7 @@ class NameFinder(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
is_exe = False
|
is_exe = False
|
||||||
for assignee, op in name.parent.assignment_details:
|
for assignee, op in stmt.assignment_details:
|
||||||
is_exe |= is_execution(assignee)
|
is_exe |= is_execution(assignee)
|
||||||
|
|
||||||
if is_exe:
|
if is_exe:
|
||||||
|
|||||||
Reference in New Issue
Block a user