diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index e31e842a..cb3e8a4c 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -29,7 +29,10 @@ def _evaluate_for_annotation(evaluator, annotation): if (isinstance(definition, CompiledObject) and isinstance(definition.obj, str)): 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 definitions |= evaluator.eval_element(element) else: diff --git a/test/completion/pep0484.py b/test/completion/pep0484.py index d49f8c58..d6ec8291 100644 --- a/test/completion/pep0484.py +++ b/test/completion/pep0484.py @@ -114,14 +114,23 @@ SelfReference().test_method() def function_with_non_pep_0484_annotation( x: "I can put anything here", xx: "", - yy: "\r\n;+*&^564835(---^&*34", - y: 3 + 3) -> int("42"): + yy: "\r\n\0;+*&^564835(---^&*34", + y: 3 + 3, + zz: float) -> int("42"): # infers int from function call #? int() x + # infers int from function call + #? int() + xx + # infers int from function call + #? int() + yy # infers str from function call #? str() y + #? float() + zz #? function_with_non_pep_0484_annotation(1, 2, 3, "force string")