Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 902be13

Browse files
committed
Merged revisions 82828 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r82828 | benjamin.peterson | 2010-07-11 18:06:06 -0500 (Sun, 11 Jul 2010) | 1 line allow byte literals ........
1 parent 16d0376 commit 902be13

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def literal_eval(node_or_string):
5050
if isinstance(node_or_string, Expression):
5151
node_or_string = node_or_string.body
5252
def _convert(node):
53-
if isinstance(node, Str):
53+
if isinstance(node, (Str, Bytes)):
5454
return node.s
5555
elif isinstance(node, Num):
5656
return node.n

Lib/test/test_ast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def test_literal_eval(self):
271271
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
272272
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
273273
self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None))
274+
self.assertEqual(ast.literal_eval('b"hi"'), b"hi")
274275
self.assertRaises(ValueError, ast.literal_eval, 'foo()')
275276

276277
def test_literal_eval_issue4907(self):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ C-API
7878
Library
7979
-------
8080

81+
- ``ast.literal_eval()`` now allows byte literals.
82+
8183
- Issue #9137: Fix issue in MutableMapping.update, which incorrectly
8284
treated keyword arguments called 'self' or 'other' specially.
8385

0 commit comments

Comments
 (0)