Are decorators really that different from metaclasses...

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

jess.austin at (Jess Austin) wrote in message news:<b8ad139e.0408251613.1f7faa51 at>...
> 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 ''>,), {'a':
> 1, 'moo': <function moo at 0x00879E70>, '__module__': '__main__'})

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

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

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


More information about the Python-list mailing list