From 91499565a987ff35b078960bdb966351ea976eab Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 25 Apr 2018 21:03:47 +0200 Subject: [PATCH] Specially crafted docstrings sometimes lead to errors, fixes #1103 --- jedi/evaluate/docstrings.py | 3 +++ jedi/evaluate/syntax_tree.py | 6 ++++-- test/completion/docstring.py | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index a927abd0..431de21f 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -214,6 +214,9 @@ def _evaluate_for_statement_string(module_context, string): except (AttributeError, IndexError): return [] + if stmt.type not in ('name', 'atom', 'atom_expr'): + return [] + from jedi.evaluate.context import FunctionContext function_context = FunctionContext( module_context.evaluator, diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 4efe845d..f3bfc55d 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -74,8 +74,10 @@ def eval_node(context, element): # For False/True/None if element.value in ('False', 'True', 'None'): return ContextSet(compiled.builtin_from_name(evaluator, element.value)) - # else: print e.g. could be evaluated like this in Python 2.7 - return NO_CONTEXTS + if element.value == 'print': + # print e.g. could be evaluated like this in Python 2.7 + return NO_CONTEXTS + assert False, 'Cannot evaluate the keyword %s' % element elif typ == 'lambdef': return ContextSet(FunctionContext(evaluator, context, element)) elif typ == 'expr_stmt': diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 88db52d1..2b9f3481 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -30,13 +30,17 @@ def sphinxy(a, b, c, d, x): sphinxy() # wrong declarations -def sphinxy2(a, b, x): +def sphinxy2(a, b, x, y, z): """ :param a: Forgot type declaration :type a: :param b: Just something :type b: `` :param x: Just something without type + :param y: A function + :type y: def l(): pass + :param z: A keyword + :type z: return :rtype: """ #? @@ -45,6 +49,10 @@ def sphinxy2(a, b, x): b #? x + #? + y + #? + z #? sphinxy2()