[Zope3-dev] Re: Interface support in Python? (was Re: [Zope3-dev] Proposal: Improving on __implements__)

Steve Alexander steve@cat-box.net
Thu, 23 Jan 2003 11:17:06 +0200


>   You can't use the class dictionary's 
> '__implements__' entry to hold the value, because that entry needs to be 
> saved for the descriptor to say what the class provides to *its* 
> instances.  So you have to come up with another name for the entry to 
> hold the value.  Only, you can't use the same name for both instances 
> and classes, because there might be another meta-level that needs to 
> store an assertion for *its* instances...

getattr seems to be a bit over-overloaded in this example.

If I have an instance, its class, its metaclass, and its meta-metaclass, 
is the following true?

   getattr(instance, 'foo')
    gets me the foo of the instance
    or if there is none, the foo of the class
    or if there is none, the foo of the metaclass,
    or if there is none, the foo of the meta-metaclass,
    or if there is none, a KeyError

   getattr(cls, 'foo')
    gets me the foo of the class
    or if there is none, the foo of the metaclass,
    or if there is none, the foo of the meta-metaclass,
    or if there is none, a KeyError

   getattr(metacls, 'foo')
    gets me the foo of the metaclass,
    or if there is none, the foo of the meta-metaclass,
    or if there is none, a KeyError

   getattr(metacls, 'foo')
    gets me the foo of the meta-metaclass,
    or if there is none, a KeyError


Maybe a change in the way getattr and metaclasses work could accompany a 
proposal to get interfaces into Python?

--
Steve Alexander