Skip to content

Commit 99c601a

Browse files
committed
Support set nodes in simple_eval
Merges changes from Python 3.9's ast.literal_eval.
1 parent f51c5e6 commit 99c601a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bpython/simpleeval.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def simple_eval(node_or_string, namespace=None):
8181
8282
The string or node provided may only consist of:
8383
* the following Python literal structures: strings, numbers, tuples,
84-
lists, and dicts
84+
lists, dicts, sets (Python 3.9+)
8585
* variable names causing lookups in the passed in namespace or builtins
8686
* getitem calls using the [] syntax on objects of the types above
8787
@@ -113,6 +113,8 @@ def _convert(node):
113113
(_convert(k), _convert(v))
114114
for k, v in zip(node.keys, node.values)
115115
)
116+
elif sys.version_info[:2] >= (3, 9) and isinstance(node, ast.Set):
117+
return set(map(_convert, node.elts))
116118

117119
# this is a deviation from literal_eval: we allow non-literals
118120
elif isinstance(node, _name_type_nodes):

0 commit comments

Comments
 (0)