473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

howto overload with a NOP (empty statement)

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): ;
Jan 6 '07 #1
5 4270
class Power_Supply (device):
def execute (self):
pass

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): ;
Jan 6 '07 #2
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 ?
pass

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jan 6 '07 #3
Stef Mientki a écrit :
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
<off>
Naming conventions are to use CamelCase for class names. So it would be
better to name your classes 'PowerSupply' (no '_') and 'Device'. You're
of course free to use whatever naming convention you want, including no
convention at all, but Python relies *a lot* on naming conventions...
</off>
The baseclass has a method "execute",
<off>
Do you know that Python let you define your own 'callable' objects ?

class SomeCallable(object):
def __init__(self, name):
self.name = name
def __call__(self):
print "wow, %s has been called" % self.name

foo = SomeCallable('foo')
foo()

This may or not make sens in the context of your application, but
whenever you find yourself naming a method 'execute', it might be worth
asking yourself if the object should in fact be a callable...
</off>
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 ?
the 'pass' statement

def noop():
pass
thanks, Stef Mientki

class device:
def execute (self):
print 'execute not yet implemented for', self.Name
The usual idiom for 'pure virtual methods' is to raise a
NotImplementedError. Now if it's ok for a subclass to implement the
method as a no-op, why not just implement it as a no-op in the base
class itself ?
Jan 6 '07 #4
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
Jan 6 '07 #5
Bruno Desthuilliers kirjoitti:
Stef Mientki a écrit :
>How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".

<off>
Naming conventions are to use CamelCase for class names. So it would be
better to name your classes 'PowerSupply' (no '_') and 'Device'. You're
of course free to use whatever naming convention you want, including no
convention at all, but Python relies *a lot* on naming conventions...
</off>
Continuing with the style and idioms issues...

1. Don't leave a space between a function/method/class name and the
opening parenthesis, i.e. instead of:
def execute (self):
use:
def execute(self):

2. It seems to me that you indent your code with 2 spaces. If I'm wrong,
please ignore me. Otherwise: always use 4 spaces when indenting with spaces.

Following these and the numerous other guidelines (see
htpp://www.python.org/dev/peps/pep-0008/ for example) on Python style
you'll be making yourself and others a favor. When these coding
guidelines become your habit, it will be easier for you to read the code
of other Pythoners. This is important because a large part of learning
consists of reading the code of others.

And also vice versa: when you show your code to others, it will be
easier for them to concentrate on your problem when the idiosyncrasy of
your code is not there to hinder.

Cheers,
Jussi
Jan 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael T. Peterson | last post by:
I am unable to figure out how to overload the '==' operator. The code below( cc'd it from an example on the net) doesn't compile: bool operator== ( const GivenName &lhs, const GivenName &rhs ) {...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
10
by: Benny Raymond | last post by:
I'm trying to change the way a treeview works just a bit, i'm pretty new to C# and now i'm running into overloading. I tried the following code and it's yelling at me saying that no overload...
2
by: sparks | last post by:
I had the bright idea of using if/else to call different constructors based on a web form and what the user entered. ======================================= IF I DECLARE this here everything...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
4
by: davearkley | last post by:
I've recently 'discover' the wonders of custom attributes and reflection. There's one aspect that has stumping me and I've been unable to find samples in the docs or on the web. I have fields in...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString In ASP, Request.Form and Request.QueryString return objects that do not support "toString", or any JavaScript string...
5
by: phiefer3 | last post by:
I'm currently a student, but this problem isn't directly related to what I have to do on an assignment. It's just a problem I've had with some supporting features. First of all, I'm using MSVS...
11
by: EricGoogle | last post by:
Hello All, I am trying to figure out a how to get a variable's name from code. Ex: var MYVAR = 3; alert( ????? ); OUTPUT: "MYVAR"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.