473,396 Members | 1,775 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,396 software developers and data experts.

Pychecker warns about Exception example from Python tutorial

Hi there,

why does pychecker v0.8.14 gives this warning:

koe2.py:2: Base class (exceptions.Exception) __init__() not called

when run against this example from Python Tutorial:

------------- code starts -------
class MyError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

try:
raise MyError(2*2)
except MyError, e:
print 'My exception occurred, value:', e.value

------------- code starts -------

What does this warning mean and how can I disable it?

-pekka-
Jul 18 '05 #1
2 2077
>>>>> "Pekka" == Pekka Niiranen <pe************@wlanmail.com> writes:

Pekka> Hi there,
Pekka> why does pychecker v0.8.14 gives this warning:

Pekka> koe2.py:2: Base class (exceptions.Exception) __init__() not called


Pekka> What does this warning mean and how can I disable it?

You had __init__, and you didn't call the init of the superclass. This
might leave the superclass in uninitialized stage. Your own exception
class is over-engineered, this works the way you want:

--------------------------
In [11]: class MyEx(Exception): pass
....:

In [12]: raise MyEx("blah")
---------------------------------------------------------------------------
MyEx Traceback (most recent call last)

/home/ville/<console>

MyEx: blah
---------------------------------

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #2

You can fix your pychecker error by adding the non-quoted line below...

------------- code starts -------
class MyError(Exception):
def __init__(self, value): Exception.__init__(self) self.value = value
def __str__(self):
return repr(self.value)

try:
raise MyError(2*2)
except MyError, e:
print 'My exception occurred, value:', e.value


Jul 18 '05 #3

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

Similar topics

0
by: Pedro Werneck | last post by:
Hi, I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me. I am trying to run pychecker on the current buffer on python-mode using the...
1
by: Neal Norwitz | last post by:
A new version of PyChecker is (finally) available for your hacking pleasure. It's been quite a while since the last release--11 months. I wish there was more progress, but such is life. Many bug...
3
by: Zachary | last post by:
Hello, I'm relatively new at Python, and am slightly confused about how the try...except mechanism is supposed to work. I am just not sure how it would be used, as it just seems that it is...
12
by: Stephen Ferg | last post by:
I've just spent several very frustrating hours tracking down a bug in one of my programs. The problem was that I was writing text to a file, and when I was done I coded f.close when I should...
6
by: Olaf Meding | last post by:
Is there a way to tell PyChecker to "skip" a line of source code? Or any other workarounds would also greatly appreciated. This line: s = sys.stdin.read(4) Causes this PyChecker error:...
4
by: beliavsky | last post by:
If I run PyChecker on the following program, stored in xtry.py, m = 10000000 k = 0 for i in xrange(m): k = k + i print k x = range(3) print x
5
by: Istvan Albert | last post by:
Hello all, if I have this code: import sets class Foo: x = sets.Set() then pychecker says:
21
by: Philippe Fremy | last post by:
Hi, I would like to develop a tool that goes one step further than pychecker to ensure python program validity. The idea would be to get close to what people get on ocaml: a static verification...
1
by: Neal Norwitz | last post by:
Special thanks to Ken Pronovici. He did a lot of work for this release and helped ensure it occurred. Version 0.8.15 of PyChecker is available. It's been over a year since the last release. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.