From 13ba74515db21c39dcdc7d3c4de2cfddc46b41e1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 14 Mar 2018 09:49:59 +0100 Subject: [PATCH] Catch parser errors instead of error recovery when splitting param comments --- jedi/evaluate/pep0484.py | 6 +++++- test/completion/pep0484_comments.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index 7b97a89a..7519ce3b 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -89,7 +89,11 @@ def _split_mypy_param_declaration(decl_text): ['foo', 'Bar[baz, biz]']. """ - node = parse(decl_text).children[0] + try: + node = parse(decl_text, error_recovery=False).children[0] + except ParserSyntaxError: + debug.warning('Comment annotation is not valid Python: %s' % decl_text) + return [] if node.type == 'name': return [node.get_code().strip()] diff --git a/test/completion/pep0484_comments.py b/test/completion/pep0484_comments.py index 87021155..181b698a 100644 --- a/test/completion/pep0484_comments.py +++ b/test/completion/pep0484_comments.py @@ -157,6 +157,11 @@ x = UNKNOWN_NAME2 # type: str #? str() x +def x(a, b): + # type: ([) -> a + #? + a + class Cat(object): def __init__(self, age, friends, name): # type: (int, List[Dog], str) -> None