1
0
forked from VimPlug/jedi

catch error in certain non-pep0484 annotations

This commit is contained in:
Claude
2015-12-17 15:23:40 +01:00
parent 8bf2fe77e2
commit 6bee214948
2 changed files with 15 additions and 3 deletions

View File

@@ -29,7 +29,10 @@ def _evaluate_for_annotation(evaluator, annotation):
if (isinstance(definition, CompiledObject) and if (isinstance(definition, CompiledObject) and
isinstance(definition.obj, str)): isinstance(definition.obj, str)):
p = Parser(load_grammar(), definition.obj) p = Parser(load_grammar(), definition.obj)
element = p.module.children[0].children[0] try:
element = p.module.children[0].children[0]
except (AttributeError, IndexError):
continue
element.parent = annotation.parent element.parent = annotation.parent
definitions |= evaluator.eval_element(element) definitions |= evaluator.eval_element(element)
else: else:

View File

@@ -114,14 +114,23 @@ SelfReference().test_method()
def function_with_non_pep_0484_annotation( def function_with_non_pep_0484_annotation(
x: "I can put anything here", x: "I can put anything here",
xx: "", xx: "",
yy: "\r\n;+*&^564835(---^&*34", yy: "\r\n\0;+*&^564835(---^&*34",
y: 3 + 3) -> int("42"): y: 3 + 3,
zz: float) -> int("42"):
# infers int from function call # infers int from function call
#? int() #? int()
x x
# infers int from function call
#? int()
xx
# infers int from function call
#? int()
yy
# infers str from function call # infers str from function call
#? str() #? str()
y y
#? float()
zz
#? #?
function_with_non_pep_0484_annotation(1, 2, 3, "force string") function_with_non_pep_0484_annotation(1, 2, 3, "force string")