[Python-ideas] 'Injecting' objects as function-local constants
Jim Jewett
jimjjewett at gmail.com
Sun Jun 19 21:28:52 CEST 2011
On Fri, Jun 17, 2011 at 4:58 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 6/17/2011 9:26 AM, Nick Coghlan wrote:
>> This is why the nonlocal and global directives exist: to tell the
>> compiler to change how it treats certain names. Arguments (including
>> the associated default values) are given additional special treatment
>> due to their placement in the function header. If we want to create a
>> new namespace that is given special treatment by the compiler,
> I do not really want a new namespace and for the purpose of the OP,
> named local constants (for speed or freezing the meaning of an
> expression or both), we do not need one. There is already a fourth
> 'namespace' for constants, a tuple f.__code__.co_consts, whose
> 'names' are indexes, just as with the locals array.
I really like this idea.
The only concerns I can see are losing the name for use in debugging
or embedded functions, and I assume that those can be dealt with.
-jJ
More information about the Python-ideas
mailing list