From a95274d66f3edd5687d8969e93d8cd6567adc480 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 1 May 2018 23:40:52 +0200 Subject: [PATCH] None/False/True are atom non-terminals in the syntax tree, fixes #1103 --- jedi/evaluate/syntax_tree.py | 18 +++++++++--------- test/completion/basic.py | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index f3bfc55d..fb0fd261 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -68,16 +68,8 @@ def eval_node(context, element): debug.dbg('eval_node %s@%s', element, element.start_pos) evaluator = context.evaluator typ = element.type - if typ in ('name', 'number', 'string', 'atom', 'strings'): + if typ in ('name', 'number', 'string', 'atom', 'strings', 'keyword'): return eval_atom(context, element) - elif typ == 'keyword': - # For False/True/None - if element.value in ('False', 'True', 'None'): - return ContextSet(compiled.builtin_from_name(evaluator, element.value)) - 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': @@ -209,6 +201,14 @@ def eval_atom(context, atom): position=stmt.start_pos, search_global=True ) + elif atom.type == 'keyword': + # For False/True/None + if atom.value in ('False', 'True', 'None'): + return ContextSet(compiled.builtin_from_name(context.evaluator, atom.value)) + if atom.value == 'print': + # print e.g. could be evaluated like this in Python 2.7 + return NO_CONTEXTS + assert False, 'Cannot evaluate the keyword %s' % atom elif isinstance(atom, tree.Literal): string = context.evaluator.compiled_subprocess.safe_literal_eval(atom.value) diff --git a/test/completion/basic.py b/test/completion/basic.py index f3abe9a5..ae2e3128 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -22,6 +22,9 @@ a(0):. 0x0 #? ['and', 'or', 'if', 'is', 'in', 'not'] 1j +x = None() +#? +x # ----------------- # if/else/elif