Skip to content

Commit feae0f1

Browse files
committed
Evaluate tuple() and list()
1 parent a7609fd commit feae0f1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bpython/simpleeval.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def safe_eval(expr, namespace):
6363
# * new docstring describing different functionality
6464
# * looks up names from namespace
6565
# * indexing syntax is allowed
66+
# * evaluates tuple() and list()
6667
def simple_eval(node_or_string, namespace=None):
6768
"""
6869
Safely evaluate an expression node or a string containing a Python
@@ -111,6 +112,22 @@ def _convert(node):
111112
):
112113
return set()
113114

115+
# this is a deviation from literal_eval: we evaluate tuple() and list()
116+
elif (
117+
isinstance(node, ast.Call)
118+
and isinstance(node.func, ast.Name)
119+
and node.func.id == "tuple"
120+
and node.args == node.keywords == []
121+
):
122+
return tuple()
123+
elif (
124+
isinstance(node, ast.Call)
125+
and isinstance(node.func, ast.Name)
126+
and node.func.id == "list"
127+
and node.args == node.keywords == []
128+
):
129+
return list()
130+
114131
# this is a deviation from literal_eval: we allow non-literals
115132
elif isinstance(node, _name_type_nodes):
116133
try:

0 commit comments

Comments
 (0)