Interface support?

Michael Spencer mahs at
Fri Mar 18 07:30:30 CET 2005

Steve wrote:
> Is it possible to design interfaces that classes must implement in 
> Python? 

There are some well-known 'independent' implementations of interfaces:
     Zope Interfaces :
		-  a separable component of the much larger app server
     Twisted Interfaces: see

     PyProtocols:, whose 
         author is one of the protagonists in the PEP246 saga

There are also several possible light-weight roll-your-own solutions
One common idiom is an abstract base class:

class SomeInterface(object):
    def someMethod(self, argspec):
         # Should never get here, because the implementation overrides this method
	raise NotImplmentedError

but the compiler doesn't pay any special attention to these classes so failure 
to implement the interface is detected at runtime

If it's not, is this functionality planned at all for the future?
Python Enhancement Proposals 245, and 246 discuss an 
interface syntax and the related topic of object adaptation.  These are both 
current discussions among the Python developers with no decision on whether/when 
  to introduce either as far as I know.  Observer the fray at:

Guido Van Rossum (Python creator and BDFL) recently blogged about "Optional 
Static Type Checking"
as part of long-range planning for a future Python 3000 (some years in the future)



More information about the Python-list mailing list