Are decorators really that different from metaclasses...

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Wed Sep 1 00:23:13 CEST 2004


Paul Morrow wrote:
>Jeff Epler wrote:
>> In your proposed model, what does the following code do?
>>     def f():
>>         __var__ = 3
>>         return __var__
>>     f.__var__ += 1
>>     print f()
>> 
> 
> Only assignments to __xxx__ variables at the very start of a function 
> def would have this special semantics.  So your return statement would 
> be referencing a name (__var__) that doesn't exist in the function's 
> local variable namespace.

No, that would silently return a surprising result if __var__ existed in
the global namespace.  Better make it a syntax error or something.

-- 
Hallvard



More information about the Python-list mailing list