diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index 7519ce3b..10edcb8e 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -80,7 +80,7 @@ def _fix_forward_reference(context, node): return node -def _split_mypy_param_declaration(decl_text): +def _split_comment_param_declaration(decl_text): """ Split decl_text on commas, but group generic expressions together. @@ -99,9 +99,14 @@ def _split_mypy_param_declaration(decl_text): return [node.get_code().strip()] params = [] - for child in node.children: - if child.type in ['name', 'atom_expr', 'power']: - params.append(child.get_code().strip()) + try: + children = node.children + except AttributeError: + return [] + else: + for child in children: + if child.type in ['name', 'atom_expr', 'power']: + params.append(child.get_code().strip()) return params @@ -128,7 +133,7 @@ def infer_param(execution_context, param): match = re.match(r"^#\s*type:\s*\(([^#]*)\)\s*->", comment) if not match: return NO_CONTEXTS - params_comments = _split_mypy_param_declaration(match.group(1)) + params_comments = _split_comment_param_declaration(match.group(1)) # Find the specific param being investigated index = all_params.index(param) diff --git a/test/completion/pep0484_comments.py b/test/completion/pep0484_comments.py index 181b698a..816cc736 100644 --- a/test/completion/pep0484_comments.py +++ b/test/completion/pep0484_comments.py @@ -157,11 +157,6 @@ 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 @@ -172,3 +167,14 @@ class Cat(object): cat = Cat(UNKNOWN_NAME4, UNKNOWN_NAME5, UNKNOWN_NAME6) #? str() cat.name + + +# Check potential errors +def x(a, b): + # type: ([) -> a + #? + a +def x(a, b): + # type: (1) -> a + #? + a