howto overload with a NOP (empty statement)

robert no-spam at no-spam-no-spam.invalid
Sat Jan 6 13:03:34 CET 2007


Stef Mientki wrote:
> How should I overload / disable a method ?
> In the example below I have defined the class "Power_Supply", derived 
> from baseclass "device".
> The baseclass has a method "execute", which will be implemented in most 
> derived classes, but not in all.
> Now apparently it's not allowed to overload a method with an empty 
> statement.
> I could write a nonsense dummy statement, like "A= 3", but isn't there 
> another way ?
> 
> thanks, Stef Mientki
> 
> class device:
>   def execute (self):
>     print 'execute not yet implemented for', self.Name
> 
> 
> class Power_Supply (device):
>   def execute (self): ;




class device:
   def execute (self):
       raise NotImplementedError('virtual: should do this and that')



This NotImplementedError virtual method scheme will also be detected by pychecker in order to warn correctly: that classes of actual instances have to override all open virtuals.


Robert



More information about the Python-list mailing list