mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 17:58:35 +08:00
fixed isinstance checks
This commit is contained in:
+19
-19
@@ -479,31 +479,31 @@ def check_flow_information(flow, search_name, pos):
|
|||||||
def check_statement_information(stmt, search_name):
|
def check_statement_information(stmt, search_name):
|
||||||
try:
|
try:
|
||||||
commands = stmt.get_commands()
|
commands = stmt.get_commands()
|
||||||
try:
|
# this might be removed if we analyze and, etc
|
||||||
call = commands.get_only_subelement()
|
assert len(commands) == 1
|
||||||
except AttributeError:
|
call = commands[0]
|
||||||
assert False
|
|
||||||
assert type(call) == pr.Call and str(call.name) == 'isinstance'
|
assert type(call) == pr.Call and str(call.name) == 'isinstance'
|
||||||
assert bool(call.execution)
|
assert bool(call.execution)
|
||||||
|
|
||||||
# isinstance check
|
# isinstance check
|
||||||
isinst = call.execution.values
|
isinst = call.execution.values
|
||||||
assert len(isinst) == 2 # has two params
|
assert len(isinst) == 2 # has two params
|
||||||
assert len(isinst[0]) == 1
|
obj, classes = [stmt.get_commands() for stmt in isinst]
|
||||||
assert len(isinst[1]) == 1
|
assert len(obj) == 1
|
||||||
assert isinstance(isinst[0][0], pr.Call)
|
assert len(classes) == 1
|
||||||
|
assert isinstance(obj[0], pr.Call)
|
||||||
# names fit?
|
# names fit?
|
||||||
assert str(isinst[0][0].name) == search_name
|
assert str(obj[0].name) == search_name
|
||||||
classes_call = isinst[1][0] # class_or_type_or_tuple
|
assert isinstance(classes[0], pr.Call) # can be type or tuple
|
||||||
assert isinstance(classes_call, pr.Call)
|
|
||||||
result = []
|
|
||||||
for c in evaluate.follow_call(classes_call):
|
|
||||||
if isinstance(c, er.Array):
|
|
||||||
result += c.get_index_types()
|
|
||||||
else:
|
|
||||||
result.append(c)
|
|
||||||
for i, c in enumerate(result):
|
|
||||||
result[i] = er.Instance(c)
|
|
||||||
return result
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for c in evaluate.follow_call(classes[0]):
|
||||||
|
if isinstance(c, er.Array):
|
||||||
|
result += c.get_index_types()
|
||||||
|
else:
|
||||||
|
result.append(c)
|
||||||
|
for i, c in enumerate(result):
|
||||||
|
result[i] = er.Instance(c)
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user