forked from VimPlug/jedi
Fix an issue with sys.path. Also moved the names closure for isinstance checks away (used for sys.path stuff) and use a get_code check instead, which is more flexible.
This commit is contained in:
@@ -402,25 +402,6 @@ def check_flow_information(evaluator, flow, search_name_part, pos):
|
||||
|
||||
|
||||
def _check_isinstance_type(evaluator, stmt, search_name):
|
||||
def names(call, use_previous=False):
|
||||
def check(call):
|
||||
while call is not None:
|
||||
if not isinstance(call, pr.Call): # Could be an Array.
|
||||
raise ValueError
|
||||
yield unicode(call.name)
|
||||
if use_previous:
|
||||
call = call.previous
|
||||
else:
|
||||
call = call.next
|
||||
|
||||
try:
|
||||
if use_previous:
|
||||
return list(check(call))
|
||||
else:
|
||||
return list(reversed(list(check(call))))
|
||||
except ValueError:
|
||||
return []
|
||||
|
||||
try:
|
||||
expression_list = stmt.expression_list()
|
||||
# this might be removed if we analyze and, etc
|
||||
@@ -437,7 +418,12 @@ def _check_isinstance_type(evaluator, stmt, search_name):
|
||||
assert len(classes) == 1
|
||||
assert isinstance(obj[0], pr.Call)
|
||||
|
||||
assert names(obj[0]) == names(search_name.parent, search_name)
|
||||
prev = search_name.parent
|
||||
while prev.previous is not None:
|
||||
prev = prev.previous
|
||||
# Do a simple get_code comparison. They should just have the same code,
|
||||
# and everything will be all right.
|
||||
assert obj[0].get_code() == prev.get_code()
|
||||
assert isinstance(classes[0], pr.StatementElement) # can be type or tuple
|
||||
except AssertionError:
|
||||
return []
|
||||
|
||||
@@ -88,17 +88,14 @@ def _paths_from_insert(module_path, exe):
|
||||
|
||||
def _paths_from_call_expression(module_path, call):
|
||||
""" extract the path from either "sys.path.append" or "sys.path.insert" """
|
||||
if not call.next_is_execution():
|
||||
return
|
||||
names = call.names()
|
||||
if names[:3] != ['sys', 'path', 'append'] and names[:3] != ['sys', 'path', 'insert']:
|
||||
return []
|
||||
if not call.next.next.next_is_execution():
|
||||
return []
|
||||
|
||||
n = call.name
|
||||
if not isinstance(n, pr.Name) or len(n.names) != 3:
|
||||
return
|
||||
names = [unicode(x) for x in n.names]
|
||||
if names[:2] != ['sys', 'path']:
|
||||
return
|
||||
cmd = names[2]
|
||||
exe = call.next
|
||||
exe = call.next.next.next
|
||||
path = None
|
||||
if cmd == 'insert' and len(exe) == 2:
|
||||
path = _paths_from_insert(module_path, exe)
|
||||
|
||||
@@ -1396,6 +1396,21 @@ class Call(StatementElement):
|
||||
def get_code(self):
|
||||
return self.name.get_code() + super(Call, self).get_code()
|
||||
|
||||
def names(self):
|
||||
"""
|
||||
Generate an array of string names. If a call is not just names,
|
||||
raise an error.
|
||||
"""
|
||||
def check(call):
|
||||
while call is not None:
|
||||
if not isinstance(call, Call): # Could be an Array.
|
||||
break
|
||||
yield unicode(call.name)
|
||||
call = call.next
|
||||
|
||||
return list(check(self))
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (type(self).__name__, self.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user