File tree 1 file changed +17
-0
lines changed 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ def safe_eval(expr, namespace):
63
63
# * new docstring describing different functionality
64
64
# * looks up names from namespace
65
65
# * indexing syntax is allowed
66
+ # * evaluates tuple() and list()
66
67
def simple_eval (node_or_string , namespace = None ):
67
68
"""
68
69
Safely evaluate an expression node or a string containing a Python
@@ -111,6 +112,22 @@ def _convert(node):
111
112
):
112
113
return set ()
113
114
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
+
114
131
# this is a deviation from literal_eval: we allow non-literals
115
132
elif isinstance (node , _name_type_nodes ):
116
133
try :
You can’t perform that action at this time.
0 commit comments