New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31778: Make ast.literal_eval() more strict. #4035
bpo-31778: Make ast.literal_eval() more strict. #4035
Conversation
Addition and subtraction of arbitrary numbers no longer allowed.
This looks good to me. Two test suggestions inline.
I'm the one who filed https://bugs.python.org/issue31778, but I'm not a Python contributor, so presumably someone else needs to review this too.
right = _convert(node.right) | ||
if isinstance(left, _NUM_TYPES) and isinstance(right, _NUM_TYPES): | ||
left = _convert_signed_num(node.left) | ||
right = _convert_num(node.right) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be useful to add to the test assertRaises(ValueError, ast.literal_eval, '3 + (0 + 2j)')
to catch unintended behavior changes to _convert_num in future edits.
self.assertEqual(ast.literal_eval('-6'), -6) | ||
self.assertEqual(ast.literal_eval('-6j+3'), 3-6j) | ||
self.assertEqual(ast.literal_eval('3.25'), 3.25) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would also be useful to assertRaises(ValueError
for an expression such as 1j+2j
or 1+2j+3j
.
Addition and subtraction of arbitrary numbers no longer allowed.
https://bugs.python.org/issue31778