[Python-projects] What is preferred way to indicate stub methods?

Alexandre Fayolle alexandre.fayolle at logilab.fr
Wed Jan 23 11:40:53 CET 2008


On Tue, Jan 22, 2008 at 09:34:48PM +0100, Benjamin Niemann wrote:
> On Tuesday 22 January 2008, Emin.shopper Martinian.shopper wrote:
> > Dear Experts,
> >
> > How do you indicate stub methods so pylint doesn't complain?
> >
> > For example, I often define classes as shown below but get various pylint
> > warnings such as R0201 (method could be a function). I could disable the
> > appropriate warnings, but I'm wondering if there is a better way to define
> > such stub-methods.
> >
> > class BaseClass:
> >   def __init__(self,member):
> >      self.member = member
> >
> >  def double(self):
> >      "Sub-classes should override this to return a doubled version of
> > member."
> >      return NotImplemented
> 
> IIRC methods with a body 'raise NotImplementedError' are treated as 'abstract' 
> methods.

Correct. 

You may want to refer to 
http://docs.python.org/ref/types.html#l2h-30 
http://docs.python.org/ref/customization.html
for the correct semantics of the NotImplemented object in Python (which
has a precise meaning) 

-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Informatique scientifique:               http://www.logilab.fr/science
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: Digital signature
Url : http://lists.logilab.org/pipermail/python-projects/attachments/20080123/926bdbe4/attachment.pgp 


More information about the Python-Projects mailing list