bpo-32893: ast.literal_eval() no longer accepts booleans as numbers in AST. by serhiy-storchaka · Pull Request #5798 · python/cpython
| left = _convert_signed_num(node.left) | ||
| right = _convert_num(node.right) | ||
| if isinstance(left, (int, float)) and isinstance(right, complex): | ||
| if type(left) in (int, float) and type(right) is complex: |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it affects much but looks better to me
| if type(left) in (int, float) and type(right) is complex: | |
| if type(left) in {int, float} and type(right) is complex: |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is faster to create a tuple than a set.
| @@ -0,0 +1,2 @@ | |||
| ast.literal_eval() no longer accepts booleans as numbers when pass AST | |||
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for when pass AST argument. part? You can give argument as string (like ast.literal_eval("True+6j") and still get ValueError.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get ValueError in ast.literal_eval("True+6j"). This PR only changes the behavior of ast.literal_eval() when pass AST argument.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.