[Zope3-dev] Re: Interface support in Python? (was Re: [Zope3-dev]
Proposal: Improving on __implements__)
Jim Fulton
jim@zope.com
Wed, 22 Jan 2003 18:29:19 -0500
Phillip J. Eby wrote:
...
> I think for me, another issue would most definitely be proper support
> for metaclasses, i.e. spelling the difference between what classes and
> instances implement. While it may be true that "most people" will not
> implement metaclasses, it is still quite possible for them to be bitten
> by the difference when using metaclasses provided by someone else.
> (Currently, __class_implements__ works reasonably well, but it can get
> really hairy when you have metametaclasses in play.)
I agree. I'll note that you don't need meta classes to have classes
that implement interesting interfaces. Classes do have some methods
of their own, most notably __call__, and can habve more with class
and static methods.
> If we were writing the interface package today -- assuming Python 2.2
> and up -- I'd suggest always asking an object's class for what it
> implements, passing in either the instance or the class. That seems to
> be the only way to be completely unambiguous as to whose interfaces
> you're asking for, when the object in question might itself be a class
> or type. An __implements__ descriptor can only be unambiguous if it's
> defined on the meta-most metaclass of the system. So to do it cleanly
> it'd have to be part of type 'type', which implies a language change.
I'm not sure what you just said. ;)
I'll note that it is possible to design a descriptor for __implements__
that will give different answers depending on whether you access it
through a class or an instance. You don't need __class_implements__.
And you can get an object's implementation specification unambiguously.
No meta-class is necessary. To make this work, you don't want people
setting __implements__ directly.
> Offhand, this sounds like something with no chance of getting in 2.3,
> and therefore unable to significantly affect Zope 3, but maybe I'm
> missing something here.
It's hard to say. It won't get into Python 2.3 if it involves syntax
changes. Even if it doesn't get into Python 2.3, I think we'd be in a
much better position to reason about near-term changes if we knew what
it would look like in some future version.
Jim
--
Jim Fulton mailto:jim@zope.com Python Powered!
CTO (888) 344-4332 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org