STINNER Victor added the comment: If you would like to implement constant folding at the AST level, I suggest you to look at my fatoptimizer project: https://github.com/haypo/fatoptimizer/blob/master/fatoptimizer/const_fold.py
The tricky part is to avoid operations when we know that it will raise an exception or create an object too big according to our constraints. I would prefer to implement an AST optimizer in Python, but converting C structures to Python objects and then back to C structures has a cost. I'm not sure that my optimizer implemented in Python is fast enough. By the way, an idea would be to skip all optimizations in some cases like for script.py when running python3 script.py. ---------- _______________________________________ 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