bpo-32893: ast.literal_eval() no longer accepts booleans as numbers in AST.#5798
Closed
serhiy-storchaka wants to merge 4 commits intopython:masterfrom
Closed
bpo-32893: ast.literal_eval() no longer accepts booleans as numbers in AST.#5798serhiy-storchaka wants to merge 4 commits intopython:masterfrom
serhiy-storchaka wants to merge 4 commits intopython:masterfrom
Conversation
auvipy
approved these changes
May 31, 2019
isidentical
reviewed
Mar 7, 2020
| 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: |
Member
There was a problem hiding this comment.
I don't think it affects much but looks better to me
Suggested change
| if type(left) in (int, float) and type(right) is complex: | |
| if type(left) in {int, float} and type(right) is complex: |
Member
Author
There was a problem hiding this comment.
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 | |||
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
You get ValueError in ast.literal_eval("True+6j"). This PR only changes the behavior of ast.literal_eval() when pass AST argument.
isidentical
approved these changes
Mar 7, 2020
Member
|
@serhiy-storchaka does this PR still relevant to master (and 3.8)? I couldn't reproduce the examples you gave on tracker or the tests here. They all raise error as intended. |
Member
Author
|
Indeed, it is no longer reproduced. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://bugs.python.org/issue32893