Are decorators really that different from metaclasses...

Jess Austin jess.austin at gmail.com
Thu Aug 26 17:55:52 EDT 2004


jess.austin at gmail.com (Jess Austin) wrote in message news:<b8ad139e.0408251613.1f7faa51 at posting.google.com>...
> This is a difference between classes and functions.  But maybe it
> could be "swept under the rug" in the following way.  Code like this:
> 
> using:
>     metaclass_decorator(baz)
> class foo(bar):
>     a = 1
>     def moo(self):
>         pass
> 
> could cause something similar to the following:
> 
> foo = metaclass_decorator(baz)('foo', (<class '__main__.bar'>,), {'a':
> 1, 'moo': <function moo at 0x00879E70>, '__module__': '__main__'})

So I thought a bit about this, and I think a better equivalent would
be:

foo = metaclass_decorator(baz)(type('foo', (<class '__main__.bar'>,), 
                                    {'a': 1, 
                                     'moo': <function moo at
0x00879E70>,
                                     '__module__': '__main__'}))

Smart pythonistas have probably already thought of this.  It just took
me a day or two.

later,
Jess



More information about the Python-list mailing list