INADA Naoki added the comment: > 1. Changes to AST
I'm working on updating this part. There are some failing tests remains. But I doubt this stage is worth enough for now. > a) Merge Num, Str, Bytes and Ellipsis constructors into a single Lit > (literal) that can hold anything. For one thing, this removes a good deal of > copy-paste in the code, since these are always treated the same. (There were > a couple of places where Bytes ctor was missing for no apparent reason, I > think it was forgotten.) Otherwise, I would have to introduce at least 4 more > node types: None, Bool, TupleConst, SetConst. This seemed excessive. We have already Constant and NameConstant. So it seems there are no need for None, Bool, TupleConst, SetConst nodes. I think converting Num, Str, Bytes, Ellipsis into Constant in folding stage is easier than fixing all tests. > b) Docstring is now an attribute of Module, FunctionDef and ClassDef, rather > than a first statement. Docstring is a special syntactic construction, it's > not an executable code, so it makes sense to separate it. Otherwise, > optimizer would have to take extra care not to introduce, change or remove > docstring. Take docstring before constant folding isn't enough? (I'm sorry if I'm wrong. I haven't tried it yet.) > c) 'None', 'True' and 'False' are parsed as literals instead of names, even > without optimizations. Since they are not redefineable, I think it makes most > sense to treat them as literals. This isn't strictly needed for folding, and > I haven't removed all the artefacts, in case this turns out controversial. They are all NameConstant already. ---------- Added file: http://bugs.python.org/file46467/change-ast.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11549> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com