Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Wed Aug 25 19:47:35 EDT 2004


Jess Austin wrote:
> 
> Here I think you're making an unwarranted assumption.  There is
> currently nothing stopping an object from using information about
> itself to do its job.  And this is sometimes a useful freedom.  As an
> example, you might have subclasses whose only real purpose is to keep
> track of their class and metadata, and have all functionality provided
> by their superclass:
> 
> class supe(object):
>     """this docstring is rarely frobnosticated"""
>     def do_something_based_on_metadata():
>         frobnosticate(self.__doc__)
> 
> class sub1(supe):
>     """I am sub1"""
> 
> class sub2(supe):
>     """I am sub2"""
> 

What you're trying to illustrate (I believe) is a superclass doing 
something based on the docstring of a subclass.  Yes this certainly does 
happen.  But the superclass and subclass are separate objects.  I was 
talking about the situation where a function does something based on 
/its own/ metadata.  That is what I'm saying virtually never happens, 
and therefore it's ok to make all assignments to __xxx__ attributes 
inside of a function def create /function attributes/ rather than /local 
variables/.


Paul




More information about the Python-list mailing list