Nick Coghlan added the comment:

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

E.g. print(1.5) and print("1.5") are valid for *our* print function, but we 
technically have no idea if they're equivalent in user code.

In short, if it involves a name lookup and that name isn't reserved to the 
compiler (e.g. __debug__) then no, you're not allowed to optimise it at compile 
time if you wish to remain compliant with the language spec. Method calls on 
literals are always fair game, though (e.g. you could optimise "a b c".split())

Any stdlib AST optimiser would need to be substantially more conservative by 
default.

----------

_______________________________________
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