Are decorators really that different from metaclasses...

Paul Morrow pm_mon at
Sat Aug 28 03:17:52 CEST 2004

Jess Austin wrote:

> Paul Morrow <pm_mon at> wrote in message news:<mailman.2478.1093564289.5135.python-list at>...
>>Nope, that was me alright.  I don't want a function to have access to 
>>it's metadata.  Nothing's changed about that.  I want to be able to 
>>specify a function's metadata inside the function def, where it seems to 
>>most appropriately belong.
> So you have:
> def foo(x):
>     __meta_variable__ = 42
>     variable = 5
>     return dir()
> And you're volunteering to explain to a newbie, or even a nearly
> intermediate programmer like myself, why the list that is returned
> from this function contains 'x' and 'variable' but not
> '__meta_variable__'?  

Sure.  Magic attributes defined at the top level of a function (e.g. 
your __meta_variable__) aren't intended to be local variables.  You'll 
see that as you start looking at more experienced programmer's code. 
Therfore, they shouldn't be treated as local variables.  For example, 
suppose we changed your function a little...

   def foo(x):
      __author__ = 'Jess Austin'
      __version__ = '1.0'
      variable = 5
      return dir()

See the difference?

>>Others seem to want to specify a function's metadata outside of the 
>>function def, which just doesn't seem pythonic (IMO).
> If you really understood Python's scoping rules, you would know that
> this opinion is the opposite of the truth.

A decorator is a kind of meta information.  So are docstrings.  The 
proposals I've been seeing (A1 and J2 in particular) declare decorators 
and docstrings outside of the function def (not inside of the function def).

> Of all the current
> incarnations of function "metadata", only one may be set within the
> function, and that one is not set using a standard binding statement:

True and True, provided that you believe that docstrings are the only 
kind of function metadata.  I believe though that attributes like 
__author__ and __version__ above are also function metadata.

> In broader commentary, as I've said, pep318
> isn't really about metadata.  One reason is that metadata isn't that
> important.  

By this you mean "in your opinion", right?


More information about the Python-list mailing list