diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-01-03 05:21:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-03 05:21:18 (GMT) |
commit | 4fcf5c12a37a8d3d8d6303c44c223dbc8d568cfd (patch) | |
tree | 5260051ef84fd7137a5ff12d90d4906cca9f5a32 /Lib | |
parent | 32f1443aa98db769d87db497b45bd0dcb732445b (diff) | |
download | cpython-4fcf5c12a37a8d3d8d6303c44c223dbc8d568cfd.zip cpython-4fcf5c12a37a8d3d8d6303c44c223dbc8d568cfd.tar.gz cpython-4fcf5c12a37a8d3d8d6303c44c223dbc8d568cfd.tar.bz2 |
bpo-39158: ast.literal_eval() doesn't support empty sets (GH-17742)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ast.py | 3 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 1 |
2 files changed, 4 insertions, 0 deletions
@@ -83,6 +83,9 @@ def literal_eval(node_or_string): return list(map(_convert, node.elts)) elif isinstance(node, Set): return set(map(_convert, node.elts)) + elif (isinstance(node, Call) and isinstance(node.func, Name) and + node.func.id == 'set' and node.args == node.keywords == []): + return set() elif isinstance(node, Dict): return dict(zip(map(_convert, node.keys), map(_convert, node.values))) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 51a7c1a..55b91cf 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -891,6 +891,7 @@ Module( self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) self.assertEqual(ast.literal_eval('{1, 2, 3}'), {1, 2, 3}) self.assertEqual(ast.literal_eval('b"hi"'), b"hi") + self.assertEqual(ast.literal_eval('set()'), set()) self.assertRaises(ValueError, ast.literal_eval, 'foo()') self.assertEqual(ast.literal_eval('6'), 6) self.assertEqual(ast.literal_eval('+6'), 6) |