[Zope3-dev] Proposal: Improving on __implements__
Steve Alexander
steve@cat-box.net
Sun, 19 Jan 2003 16:33:19 +0200
Phillip J. Eby wrote:
> At 11:15 AM 1/19/03 +0200, Steve Alexander wrote:
>
>> However, I still need the registry to make declarations for builtin
>> classes and other classes where the class object itself is immutable.
>
> Doesn't that registry (typeImplements) already exist?
It does. It isn't used everywhere it should be used. Part of the reason
for this is because __implements__ is exposed in application code. This
tempts people to consider the __implements__ attribute the only source
of information about interface implementations.
I suppose I could implement the 'implementAdditional(obj, IFoo, IBar)'
and 'removeImplements(obj, IFoo, IBar)' parts of my proposal with the
existing zope.interface package.
> Perhaps the "magic" one should be called 'instancesImplement()'.
I think that would be clearer, especially when people are working with
classes that themselves implement an interface.
However, for Zope 3, it is far more common to declare that a class'
instances will implement an interface. Actually, 'far more common' is an
understatement. This is everywhere. This is also the only kind of
interface implementation declaration that most application programmers
will need to use.
So, because it is shorter, I still prefer the bare word 'implements'
used for saying what instances of a class implement.
>> I'd like to remove all reference to an '__implements__' attribute from
>> regular code.
>
> I'm +1 on that *goal* - just not necessarily via the spelling I've seen
> so far.
Good. Please keep sending in the suggestions :-)
> Here's a crazy one:
>
> class Foo(Bar, implements(Baz, Spam, interfacesOf(Thingy))):
> ...
>
> It's of course crazy because it's going to mess with the MRO of the
> result. But it's closest to simulating a Java-style "implements"
> clause.
I don't want to simulate a Java-style 'implements' clause.
Although this isn't the issue in question, I really don't like the way
that interface implementation is so closely linked to class definition
and subclassing in Java.
I'd prefer to keep class statements as class statements. If Python had
an 'instances implement' statement that, for argument's sake is
'implements', it might look like this:
class Foo:
implements IFoo, IBar
So, I suppose I'm trying for something close to that, without needing to
change the language.
> I don't care for a bare 'implements' in the body of the class,
> but it just might work in the bases. But I don't think it's worth the
> cost of (up to) doubling the length of the MRO.
I agree. I don't like the extra braces either.
I'd really like to have a syntax that doesn't involve more than one set
of nested parentheses, and doesn't need to be split onto several lines
when you want to talk about implementing a number of interfaces, and
doesn't refer to the '__implements__' name.
--
Steve Alexander