STINNER Victor added the comment:

> All of the optimisations that assume globals haven't been shadowed
> or rebound are invalid in the general case.

My main idea is that the developer of the application should be able to 
annotate functions and constants to declare them as "optimizable" (constant). I 
chose to expect builtins as not being overrided, but if it breaks applications, 
it can be converted to an option disabled by default.

There is a known issue: test_math fails because pow() is an alias to matH.pow() 
in doctests. The problem is that "from math import *" is called and the result 
is stored in a namespace, and then "pow(2,4)" is called in the namespace. 
astoptimizer doesn't detect that pow=math.pow because locals are only set when 
the code is executed (and not at compilation) with something like: exec(code, 
namespace). It is a limitation of the optimizer. A workaround is to disable 
optimizations when running tests.

It is possible to detect that builtins are shadowed (ex: print=myprint). 
astoptimizer has an experimental support of assignments, but it only works on 
trivial examples yet (like "x=1; print(x)") and is disabled by default (because 
it is buggy). I also plan to disable some optimizations if globals(), vars() or 
dir() is called.

----------

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

Reply via email to