Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Fri Aug 27 09:58:10 EDT 2004


Colin J. Williams wrote:
> 
> 
> Paul Morrow wrote:
> [snip]
> 
>>
>>
>> Yes, it doesn't seem all that complex, although I'm not sure that 
>> everyone reading this understands them and their subtleties.  The 
>> following is an excerpt from 
>> http://docs.python.org/tut/node11.html#SECTION0011200000000000000000
>>
>> "A namespace is a mapping from names to objects. Most namespaces are 
>> currently implemented as Python dictionaries, but that's normally not 
>> noticeable in any way (except for performance), and it may change in 
>> the future. Examples of namespaces are: the set of built-in names 
>> (functions such as abs(), and built-in exception names); the global 
>> names in a module; and the local names in a function invocation. In a 
>> sense the set of attributes of an object also form a namespace."
>>
>> When I talk about namespaces, I include all of the above, including 
>> the sense mentioned in the last line.  So an object's attributes 
>> constitute a namespace too.  Therefore __doc__, being an attribute of 
>> the function object, is in the function object's /namespace/.  And 
>> note that this is *not* a new namespace; it's been there all along.
>>
> Could you elaborate on the last sentence please?  Is the namespace not 
> created when the def ... line(s) is/are executed?
> 

If Python waits until then, where does it put the docstring in the 
meantime?  I haven't actually looked at the code [*], but it would make 
sense for the function's namespace to be created at the beginning of the 
def execution (so that it had a place for the __doc__ attribute when the 
docstring was encountered).


* Oh Anthony will want to jump on that one :-)




More information about the Python-list mailing list