Ikkei Shimomura wrote:
Hi, I also had interested in the topic, that optimize python script on source/ast/bytecode layer.
As a part of meta-programming.
Recentlly, I've posted a recipe, which similar concept. (I found pyc already does it and more) upper-letters name variables as constants at compile time. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435694
Good idea.
What we basically need is a dictionary 'D' available at optimizer.visitName, where we will say: if node.name in D: make_const (...)
The question is how do get this dictionary.
One way, like in the recipe, is to use an external file for this, and invoke pyc:
pyc --consts-file=define_constants.py test_constants.py
In this case i think it's better to use the "__all__ convention" instead of "upper-letters", so that the code will still work without pyc by writing:
from define_constants import *
The only disadvantage is that we will have dependancies: if define_constants is modified, test_constants should be recompiled. But that should be ok for people that use pyc.
define_constants should be: #------------------- import math __all__ = ['PI', 'DEBUG'] PI=math.atan (1)*4.0 DEBUG=1 #--------------------
if anybody's using None as an argument,
they are looking for trouble anyway and the sooner they find it, the better?
Can you show any situations has the problem ? is it foo(None) ?
Or ssign value into 'None' is SyntaxError, now. is not that such thing ?
wrong comment:) that was for the case:
def foo(None, x): print None
which should be forbidden anyway.
Stelios