Author xxm
Recipients gvanrossum, xxm
Date 2021-01-12.03:18:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Sorry, my description is a little confusing. My points lie on function 'compile' and 'exec'. Yes, I agree. AST can be modified and don't correspond to valid programs.  But I don't think this invaild program can be compiled and exec without any check. It's dangerous.  

See the following program: For "compile" and "exec", no error is reported on Python 3.5-3.8 while error messages are reported on Python 3.9 and 3.10

import ast
class RewriteName(ast.NodeTransformer):
    def visit_Name(self, node):
        if != "print":
   = str(False)
        return node

code = "a = 2;print(a)"

myast = ast.parse(code)
transformer = RewriteName()
newast = transformer.visit(myast)

c = compile(newast,'','exec')
Error message on Python 3.9  and 3.10.
<class 'str'>
<class 'str'>
Traceback (most recent call last):
  File "/home/xxm/Desktop/nameChanging/report/", line 574, in <module>
    c = compile(newast,'','exec')
ValueError: Name node can't be used with 'False' constant

In fact, in class RewriteName, when "" is assigned, the parser will check whether the identifier is a "str". If not,"TypeError: AST identifier must be of type str" will be reported. However, it's not enough. In Python, identifier names have their own naming rules.  "str" could be "+","1","False", but these are not legally id. So the above error could be reported.
Date User Action Args
2021-01-12 03:18:07xxmsetrecipients: + xxm, gvanrossum
2021-01-12 03:18:07xxmsetmessageid: <>
2021-01-12 03:18:07xxmlinkissue42889 messages
2021-01-12 03:18:05xxmcreate