mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
None/False/True are atom non-terminals in the syntax tree, fixes #1103
This commit is contained in:
@@ -68,16 +68,8 @@ def eval_node(context, element):
|
|||||||
debug.dbg('eval_node %s@%s', element, element.start_pos)
|
debug.dbg('eval_node %s@%s', element, element.start_pos)
|
||||||
evaluator = context.evaluator
|
evaluator = context.evaluator
|
||||||
typ = element.type
|
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)
|
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':
|
elif typ == 'lambdef':
|
||||||
return ContextSet(FunctionContext(evaluator, context, element))
|
return ContextSet(FunctionContext(evaluator, context, element))
|
||||||
elif typ == 'expr_stmt':
|
elif typ == 'expr_stmt':
|
||||||
@@ -209,6 +201,14 @@ def eval_atom(context, atom):
|
|||||||
position=stmt.start_pos,
|
position=stmt.start_pos,
|
||||||
search_global=True
|
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):
|
elif isinstance(atom, tree.Literal):
|
||||||
string = context.evaluator.compiled_subprocess.safe_literal_eval(atom.value)
|
string = context.evaluator.compiled_subprocess.safe_literal_eval(atom.value)
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ a(0):.
|
|||||||
0x0
|
0x0
|
||||||
#? ['and', 'or', 'if', 'is', 'in', 'not']
|
#? ['and', 'or', 'if', 'is', 'in', 'not']
|
||||||
1j
|
1j
|
||||||
|
x = None()
|
||||||
|
#?
|
||||||
|
x
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# if/else/elif
|
# if/else/elif
|
||||||
|
|||||||
Reference in New Issue
Block a user