[Types-sig] Interfaces API
Paul Prescod
paulp@ActiveState.com
Wed, 14 Mar 2001 23:59:35 -0800
We'll need to agree on an API for interfaces. My API is very simple:
interface Interface:
"""The shared behavior of interface objects"""
def __check__(self, obj)
Michel's is a little more "feature rich":
interface InterfaceInterface(InterfaceBaseInterface):
"""
This is the interface to interface objects that
are described in this document.
"""
def getBases():
"""
Returns a sequence of base interfaces
this interface extends.
"""
def extends(other): # convenience function?
"""
Does this interface extend the 'other' interface?
"""
def isImplementedBy(object): # convenience function?
"""
Does the given object implement the interface?
"""
# convenience function?
def isImplementedByInstancesOf(klass):
"""
Do instances of the given class implement
this interface?
"""
# do you differentiate between required
# and optional names? I ask because it seems like it
# would make sense to have docstrings and other
# metadata for optional methods etc.
def names():
"""
Return the attribute names defined by the interface
"""
def namesAndDescriptions():
"""
Return the attribute names and description
objects defined by the interface
"""
# convenience function?
def getDescriptionFor(name, default=None):
"""
Return the attribute description
object for the given name
"""
# I think deferred classes were taken out of the PEP
def deferred():
"""
Return a deferred class corresponding to
the interface.
"""
I'm surprised that you don't have the equivalent of my __check__. Given
an object don't we want a way to ensure that it really does have the
right names, methods with the right parameters and so forth? In my mind,
__check__ is the major feature required for runtime checks. The other
stuff is of lesser interest ot me.
Also, I wonder if an API could get into the core language with
CamelCaseMethodNames. Guido Isn't A CamelCaseGuyAfterAll. I really
prefer camel case myself but what's the point in fighting the BDFL on
religious issues? (I'll point out, however that camel case names would
have a consistent syntax for hasAttr and hasKey, which Python does NOT!)
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.activestate.com/pythoncookbook