]> granicus.if.org Git - python/commitdiff
Merged revisions 82828 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sun, 11 Jul 2010 23:10:08 +0000 (23:10 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sun, 11 Jul 2010 23:10:08 +0000 (23:10 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r82828 | benjamin.peterson | 2010-07-11 18:06:06 -0500 (Sun, 11 Jul 2010) | 1 line

  allow byte literals
........

Lib/ast.py
Lib/test/test_ast.py
Misc/NEWS

index 0b8baf752e04e763e9d05394cbfaad8a0a3403f1..027302fefcb0943bd25290fd584acb0c4ab167fe 100644 (file)
@@ -50,7 +50,7 @@ def literal_eval(node_or_string):
     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
index 7ee16bf5bd601b951472108f14ea9a0c398e4236..e18888739e0dc290f9bb810a4992fbe89a012f1b 100644 (file)
@@ -271,6 +271,7 @@ class ASTHelpers_Test(unittest.TestCase):
         self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
         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('b"hi"'), b"hi")
         self.assertRaises(ValueError, ast.literal_eval, 'foo()')
 
     def test_literal_eval_issue4907(self):
index 601943faf834bf84f64f58ab0dbaf36ab246ef84..7c264735c56374fc77513fdeed8605ae333f8dce 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,8 @@ C-API
 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.