self-promotion of the decorator module

Duncan Booth duncan.booth at invalid.invalid
Thu May 19 11:44:37 EDT 2005


Michele Simionato wrote:

> Duncan Booth:
>> Fortunately you have a list of
>> argument names readily available so it shouldn't be too
>> hard to generate unique names to use in their place.
> 
> It does not look too simple either. Whereas I can easily
> build valid Python identifiers which are extremely unlikely
> to clash with any identifier I can have in my program, it
> seems impossible to get an identifier which cannot be
> shadowed later . What about renaming
> name-> _name_, call -> _call_, func-> _func_, defarg->_defarg_ and
> checking that the argument list
> does not contain such reserved names by means of an assert statement?

I'm not sure I see the problem. You only have to pick names which are not 
the name of the current function not any of its arguments. These names get 
substituted into the string used to define the function which is exec'ed in 
its own private namespace. So long as they are unique within that namespace 
there shouldn't be a problem.



More information about the Python-list mailing list