[Types-sig] Interface PEP
Sverker Nilsson
sverker.is@home.se
Thu, 15 Mar 2001 03:41:33 +0100
Marcin 'Qrczak' Kowalczyk wrote:
>
> Wed, 14 Mar 2001 14:20:22 +0100, Sverker Nilsson <sverker.is@home.se> pisze:
>
> > The type() builtin would return, as usual, InstanceType if the
> > __type__ special attribute was not defined. Otherwise it would return
> > what __type__ returned. - which would be a user defined type (aka
> > interface) or even a builtin type, if the class wants to claim it
> > emulates a built-in type.
>
> Warning, warning! This is a wrong way.
>
> There is no concept of asking an object which interface it implements.
> There is no "the" interface it implements.
That's something that seems to be suggested in the PEP that this
thread concerns.
http://www.zope.org/Members/michel/InterfacesPEP/PEP.txt
Quoting from that:
"""
Interface Assertion
The next step is to put classes and interfaces together by
creating a concrete Python class the asserts that it implements an
interface. Here is an example "FishMarket" component that might
do this:
[...]
class FishMarket implements FishMarketInterface:
[...]
The interface assertion provided in a 'class' statement like this
is stored in the class's '__implements__' class attribute. After
interpreting the above example, you would have a class statement
that can be examined like this:
>>> FishMarket
<class FishMarket at 8140f50>
>>> FishMarket.__implements__
(<Interface FishMarketInterface at 81006f0>,)
"""
So for the record, it was not my idea with having explicitly specified
interfaces, though I may agree with it. I was just considering calling
the 'interface' 'type'.
If it was any misunderstanding of that, I'll leave it to Michel
Pelletier or some other to respond to the rest of your mail, for now.
Regards,
Sverker Nilsson