[Interface-dev] Odd metaclasses in Python 3

Jim Fulton jim at zope.com
Sat Dec 5 06:56:12 EST 2009


On Sat, Dec 5, 2009 at 6:20 AM, Lennart Regebro <regebro at gmail.com> wrote:
> In zope.interface for Python 3, we use the implementer() method as an
> implements() declaration. The idea was that it would be used both for
> methods and for classes. Turns out zope.formlib is already using it
> for instances as well, so it needs to work for instances, methods,
> functions and classes. This is not a problem because all we need to do
> is to check if something is a class or not. If it is we call
> classImplements, otherwise we just set __implements__.
>
> Buuuuuut.....
>
> There are tests in zope.interfaces that are there to support
> ExtensionClasses. They test that you can implement things on a class
> who has a metaclass that doesn't subclass type. In Python 3, there
> seems to be no way to distinguish that kind of "odd" class from an
> instance. Simply, in Python 3, if you use a metaclass that is not a
> type, then you are not a class, but an instance. Hence, the above test
> fails, hence the Odd classes also fail.
>
> Possible solutions:
>
> 1. Dropping implementer() support for ExtensionClasses under Python 3.
> This means that if you want to use ExtensionClasses under Python 3
> (something which seems unlikely to happen anyway) you need to
> explicitly use classImplements(Foo, IFoo) instead of
> @implementer(IFoo). This seems reasonable to me.

+1

Jim

-- 
Jim Fulton


More information about the Interface-dev mailing list