[Python-checkins] r82828 - in python/branches/py3k: Lib/ast.py Lib/test/test_ast.py Misc/NEWS

benjamin.peterson python-checkins at python.org
Mon Jul 12 01:06:06 CEST 2010


Author: benjamin.peterson
Date: Mon Jul 12 01:06:06 2010
New Revision: 82828

Log:
allow byte literals

Modified:
   python/branches/py3k/Lib/ast.py
   python/branches/py3k/Lib/test/test_ast.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/ast.py
==============================================================================
--- python/branches/py3k/Lib/ast.py	(original)
+++ python/branches/py3k/Lib/ast.py	Mon Jul 12 01:06:06 2010
@@ -50,7 +50,7 @@
     if isinstance(node_or_string, Expression):
         node_or_string = node_or_string.body
     def _convert(node):
-        if isinstance(node, Str):
+        if isinstance(node, (Str, Bytes)):
             return node.s
         elif isinstance(node, Num):
             return node.n

Modified: python/branches/py3k/Lib/test/test_ast.py
==============================================================================
--- python/branches/py3k/Lib/test/test_ast.py	(original)
+++ python/branches/py3k/Lib/test/test_ast.py	Mon Jul 12 01:06:06 2010
@@ -286,6 +286,7 @@
         self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
         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.assertRaises(ValueError, ast.literal_eval, 'foo()')
 
     def test_literal_eval_issue4907(self):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Mon Jul 12 01:06:06 2010
@@ -473,6 +473,8 @@
 Library
 -------
 
+- ``ast.literal_eval()`` now allows byte literals.
+
 - Issue #9137: Fix issue in MutableMapping.update, which incorrectly
   treated keyword arguments called 'self' or 'other' specially.
 


More information about the Python-checkins mailing list