I've just been playing around with metaclasses, and
I think I've stumbled across a reason for having
class decorators as an alternative to metaclasses
for some purposes.

The metaclass I wrote was for the purpose of
adding a class to a registry, the reason for which
isn't important here. It worked, but I was surprised
to find that it not only registered the classes that
I made it the metaclass of, but all subclasses of
those classes as well.

I'm not sure whether that's really the behaviour I
want, and I can imagine some cases in which it's
definitely not what I'd want.

The general principle brought out here is that when
you use a metaclass, it gets inherited by subclasses,
but if we had class decorators, they would only affect
to the classes that you explicitly applied them to.
I think there are uses for both behaviours.

Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to