]> granicus.if.org Git - python/commitdiff
Allow set literals in literal_eval().
authorGeorg Brandl <georg@python.org>
Sun, 11 Jul 2010 09:41:21 +0000 (09:41 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 11 Jul 2010 09:41:21 +0000 (09:41 +0000)
Doc/library/ast.rst
Lib/ast.py
Misc/NEWS

index 9bf374f4256a025abf66c38cd686b49c17773eee..43c9add1428998f72067ab3aa984a410e11c8984 100644 (file)
@@ -119,12 +119,15 @@ and classes for traversing abstract syntax trees:
 
    Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
-   Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
-   and ``None``.
+   Python literal structures: strings, numbers, tuples, lists, dicts, sets,
+   booleans, and ``None``.
 
    This can be used for safely evaluating strings containing Python expressions
    from untrusted sources without the need to parse the values oneself.
 
+   .. versionchanged:: 3.2
+      Now allows set literals.
+
 
 .. function:: get_docstring(node, clean=True)
 
index 0b8baf752e04e763e9d05394cbfaad8a0a3403f1..092f07790fef90e5f716044726d05a3e21902b4d 100644 (file)
@@ -58,6 +58,8 @@ def literal_eval(node_or_string):
             return tuple(map(_convert, node.elts))
         elif isinstance(node, List):
             return list(map(_convert, node.elts))
+        elif isinstance(node, Set):
+            return set(map(_convert, node.elts))
         elif isinstance(node, Dict):
             return dict((_convert(k), _convert(v)) for k, v
                         in zip(node.keys, node.values))
index b72e78a07e2838de43c0a9c4923233d88d8a67ff..dbfc4c5d68f5484cf227523055cbbb30be2bf119 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -470,7 +470,9 @@ C-API
 Library
 -------
 
-- Issue #9164: Ensure that sysconfig handles duplicate -arch flags in CFLAGS
+- ``ast.literal_eval()`` now allows set literals.
+
+- Issue #9164: Ensure that sysconfig handles duplicate -arch flags in CFLAGS.
 
 - Issue #7646: The fnmatch pattern cache no longer grows without bound.