New submission from Tal Ben-Nun <tben...@gmail.com>:

In Python 3.8, the "kind" field was introduced into the Constant AST class. 
This brings about a problem when unparsing the AST for various packages. First, 
it breaks backward compatibility for older code that creates ast.Num without 
specifying kind (which is optional anyway and does not exist in its fields). 
Second, since bytes are parsed as a Constant without a kind, one can create the 
following (valid as of now) AST and unparse it:

ast.unparse(ast.Constant(value=b"bad", kind="u"))

Getting "ub'bad'", which is invalid Python syntax AFAIU.

Could something be done with the classes that extend ast.Constant and with 
bytes being a Constant with a "kind" of "b"?

----------
components: Library (Lib)
messages: 360754
nosy: Tal Ben-Nun
priority: normal
severity: normal
status: open
title: ast.Constant, bytes, and ast.unparse
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39463>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to