mirror of https://github.com/python/cpython
allow byte literals
This commit is contained in:
parent
c762242cca
commit
5ef96e5fac
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue