summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-06 22:41:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-12-06 22:41:04 (GMT)
commit442f20996dcd994d1024e5cad7f66a4595352eb2 (patch)
tree641746efd4247acd2b5e13f5de7f65c026242a05 /Lib/ast.py
parent4b237e3b1112304f834ac78fe05abdecbf3d87b4 (diff)
downloadcpython-442f20996dcd994d1024e5cad7f66a4595352eb2.zip
cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.gz
cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.bz2
create NameConstant AST class for None, True, and False literals (closes #16619)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 13f59f9..02c3b28 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -42,7 +42,6 @@ def literal_eval(node_or_string):
Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
sets, booleans, and None.
"""
- _safe_names = {'None': None, 'True': True, 'False': False}
if isinstance(node_or_string, str):
node_or_string = parse(node_or_string, mode='eval')
if isinstance(node_or_string, Expression):
@@ -61,9 +60,8 @@ def literal_eval(node_or_string):
elif isinstance(node, Dict):
return dict((_convert(k), _convert(v)) for k, v
in zip(node.keys, node.values))
- elif isinstance(node, Name):
- if node.id in _safe_names:
- return _safe_names[node.id]
+ elif isinstance(node, NameConstant):
+ return node.value
elif isinstance(node, UnaryOp) and \
isinstance(node.op, (UAdd, USub)) and \
isinstance(node.operand, (Num, UnaryOp, BinOp)):