From 5ef96e5fac6f784d3c9336ed0215397e934bff4f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 11 Jul 2010 23:06:06 +0000 Subject: allow byte literals --- Lib/ast.py | 2 +- Lib/test/test_ast.py | 1 + Misc/NEWS | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/ast.py b/Lib/ast.py index 092f077..d595c05 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -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 diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index e050784..f00a415 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -286,6 +286,7 @@ class ASTHelpers_Test(unittest.TestCase): 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): diff --git a/Misc/NEWS b/Misc/NEWS index 1b0c3d1..86e8d16 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -473,6 +473,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. -- cgit v0.12