Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Thu Aug 26 11:09:28 EDT 2004


Anthony Baxter wrote:
> On Thu, 26 Aug 2004 14:40:18 GMT, Arthur <ajsiegel at optonline.com> wrote:
> 
>>>IMO, to change it inside of a function def should be (but isn't) as easy
>>>as...
>>>
>>>  >>> def foo():
>>>  ...     """ I am foo """
>>>  ...     __doc__ = __doc__ + 'indeed'
>>>
>>>Paul
>>
>>Yes.  Not only do I follow, but I think we came to exactly the same
>>place, from very different directions, and coming from what I sense is
>>very different backgrounds.
>>
>>Its just that I don't think many others seem to find that as
>>interesting as I happen to.
> 
> 
> Not so much that, as running out of ways to restate myself. The
> proposed syntax above still requires magic handling of double-under
> variables in a function, and a new namespace. I can't see how you can
> think that this is a _good_ thing.

The function does *not* get a new namespace!  Let me stress this point a 
little further.  We would simply be moving __xxx__ variables *out of* 
the function's local variable namespace to where they belong, the 
namespace of the function itself --- /the same namespace that __doc__ 
lives in./

As such, the function *body* would have no more access to __doc__ than 
it does now.  Consider the following

   def foo():
      """ foo's docstring """
      __author__ = 'Paul Morrow'
      __version__ = '0.1'
      __features__ = memoized, synchronized
      # Above this line is the function's declaration section.
      # Below this line is where the function's body starts.
      var1 = 10
      print __doc__          # error!  __doc__ is not in local namespace
      print var1             # ok.


Paul




More information about the Python-list mailing list