Fix isinstance issues.

This commit is contained in:
Dave Halter
2014-09-25 00:36:53 +02:00
parent 59225ceaa3
commit 16f244a1b2

View File

@@ -401,7 +401,26 @@ def check_flow_information(evaluator, flow, search_name_part, pos):
return result
def _check_isinstance_type(evaluator, stmt, search_name_part):
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
@@ -418,8 +437,7 @@ def _check_isinstance_type(evaluator, stmt, search_name_part):
assert len(classes) == 1
assert isinstance(obj[0], pr.Call)
# names fit?
assert unicode(obj[0].name) == unicode(search_name_part.parent)
assert names(obj[0]) == names(search_name.parent, search_name)
assert isinstance(classes[0], pr.StatementElement) # can be type or tuple
except AssertionError:
return []