[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-26 Thread Kodiologist
Kodiologist added the comment: And yes, while this behavior will look strange, the only code that will parse to AST nodes that require it will be code that uses exactly the same trick. -- ___ Python tracker ___

[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-26 Thread Kodiologist
Kodiologist added the comment: I've done very little work on CPython, but I do a lot of AST construction and call `ast.unparse` a lot in my work on Hylang, and I think this is a wart worth fixing. The real mistake was letting the user say `𝕕𝕖𝕗 = 1`, but that's been legal Python syntax for a l

[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-26 Thread Batuhan Taskaya
Batuhan Taskaya added the comment: Technically, this is a bug on the fact that it breaks the only guarantee of ast.unparse: > Unparse an ast.AST object and generate a string with code that would produce > an equivalent ast.AST object if parsed back with ast.parse(). But I am not really sure

[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-25 Thread Nikita Sobolev
Nikita Sobolev added the comment: I can confirm that it happens on all versions from 3.9 to 3.11 (main). ``` Python 3.9.9 (main, Dec 21 2021, 11:35:28) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import ast >>> ast.un

[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-25 Thread Jelle Zijlstra
Change by Jelle Zijlstra : -- nosy: +BTaskaya, Jelle Zijlstra, benjamin.peterson, pablogsal ___ Python tracker ___ ___ Python-bugs-l

[issue46520] `ast.unparse` produces syntactically illegal code for identifiers that look like reserved words

2022-01-25 Thread Kodiologist
New submission from Kodiologist : This works: 𝕕𝕖𝕗 = 1 This raises SyntaxError: import ast exec(ast.unparse(ast.parse("𝕕𝕖𝕗 = 1"))) It looks like `ast.parse` creates a `Name` node with `id='def'`, which is correct per PEP 3131, but `ast.unparse` doesn't know it needs to mangle the