[Interface-dev] Re: [Fwd: Re: Interfaces status and coordination]

Philipp von Weitershausen philipp at weitershausen.de
Thu Jun 3 04:54:45 EDT 2004


Glyph Lefkowitz wrote:
> That reminds me.  I certainly wouldn't propose this as standard
> interface object behavior, but is there going to be a non-horrible way
> to do what nevow.formless does?  e.g.
> 
> class X(TypedInterface):
>     def y(z=String()):
>         return Integer()
> 
> and then be able to introspect X['y'] to determine the implied
> signature?  I understand the args are in X['y'].optional, but I can't
> figure out a way to get to the actual function 'y'.  I think it should
> be available for other introspection reasons as well; it would be nice
> to find the source line where an interface method was defined, for
> example.

There are no actual methods or functions on interfaces because 
interfaces are no classes. The 'def' statement is literally abused to 
create zope.interface.interface.Method objects.

Consider the following example:

 >>> from zope.interface import Interface
 >>> from zope.schema import TextLine
 >>> class IFoo(Interface):
...   def foo(bar=TextLine()):
...     pass
...
 >>> IFoo['foo']
<zope.interface.interface.Method object at 0x300cf850>
 >>> IFoo['foo'].optional
{'bar': <zope.schema._bootstrapfields.TextLine object at 0x300cf7b0>}

Note that it might be tempting to use schema fields as a type constraint 
on parameters. Yet, the above notation loses argument order since all 
parameters would be treated as *optional* keyword arguments.

Philipp




More information about the Interface-dev mailing list