forked from VimPlug/jedi
Get hasattr checks completely working
This commit is contained in:
@@ -160,8 +160,9 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
if check_match(cls, exception):
|
if check_match(cls, exception):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check_hasattr(node):
|
def check_hasattr(node, suite):
|
||||||
try:
|
try:
|
||||||
|
assert suite.start_pos <= jedi_obj.start_pos < suite.end_pos
|
||||||
assert node.type == 'power'
|
assert node.type == 'power'
|
||||||
base = node.children[0]
|
base = node.children[0]
|
||||||
assert base.type == 'name' and base.value == 'hasattr'
|
assert base.type == 'name' and base.value == 'hasattr'
|
||||||
@@ -175,14 +176,16 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
assert len(args) == 2
|
assert len(args) == 2
|
||||||
|
|
||||||
# Check name
|
# Check name
|
||||||
assert len(args[1]) == 1
|
key, values = args[1]
|
||||||
names = evaluator.eval_element(args[1][0])
|
assert len(values) == 1
|
||||||
|
names = evaluator.eval_element(values[0])
|
||||||
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
||||||
assert names[0].obj == str(payload[1])
|
assert names[0].obj == str(payload[1])
|
||||||
|
|
||||||
# Check objects
|
# Check objects
|
||||||
assert len(args[0]) == 1
|
key, values = args[0]
|
||||||
objects = evaluator.eval_element(args[0][0])
|
assert len(values) == 1
|
||||||
|
objects = evaluator.eval_element(values[0])
|
||||||
return payload[0] in objects
|
return payload[0] in objects
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return False
|
return False
|
||||||
@@ -195,7 +198,7 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
return True
|
return True
|
||||||
# hasattr check
|
# hasattr check
|
||||||
if exception == AttributeError and obj.isinstance(pr.IfStmt, pr.WhileStmt):
|
if exception == AttributeError and obj.isinstance(pr.IfStmt, pr.WhileStmt):
|
||||||
if check_hasattr(obj.children[1]):
|
if check_hasattr(obj.children[1], obj.children[3]):
|
||||||
return True
|
return True
|
||||||
obj = obj.parent
|
obj = obj.parent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user