bpo-41887: omit leading spaces/tabs on ast.literal_eval (#22469)

Also document that eval() does this (the same way).
This commit is contained in:
Batuhan Taskaya 2020-10-04 03:46:44 +03:00 committed by GitHub
parent 7f54e563dc
commit e799aa8b92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View file

@ -1005,6 +1005,12 @@ Module(
malformed = ast.Dict(keys=[ast.Constant(1)], values=[ast.Constant(2), ast.Constant(3)])
self.assertRaises(ValueError, ast.literal_eval, malformed)
def test_literal_eval_trailing_ws(self):
self.assertEqual(ast.literal_eval(" -1"), -1)
self.assertEqual(ast.literal_eval("\t\t-1"), -1)
self.assertEqual(ast.literal_eval(" \t -1"), -1)
self.assertRaises(IndentationError, ast.literal_eval, "\n -1")
def test_bad_integer(self):
# issue13436: Bad error message with invalid numeric values
body = [ast.ImportFrom(module='time',