[Tutor] empty class methods

Brian van den Broek broek at cc.umanitoba.ca
Wed Dec 14 20:37:17 CET 2005


david said unto the world upon 2005-12-14 05:39:
> 
> class foo:
>     def sayhi(self):
>         print 'hello world'
>     def saybye(self): ##is there any reason for this to be here?
>         pass
> 
> class bar(foo):
>     def saybye(self):
>         print 'bye now'
> 
> class baz(foo):
>     def saybye(self):
>         print 'later tater'
> 

Hi David,

as Kent pointed out, a baseclass hook method is a common use case. 
When I do that I write it as follows:

class foo:
     def saybye(self):
         '''Hook method for subclasses to override'''
         pass

which makes it abundantly clear :-)

The other reason I sometime use pass is if I've had a Big Design[1] 
idea and want to put in stub methods before I lose the overall 
picture. Then the pass is there just to make the code legal while the 
existence of the method name reminds me I wanted to make an actual 
method.

     def a_method(self):
         pass # FIXME stub

[1] Whether I ought give in to Big Design Ideas is, of course, a 
separate question :-)

HTH,

Brian vdB



More information about the Tutor mailing list