The "correct" way to define an exception in Python without PyLint complaining

Posted by Evgeny on Stack Overflow See other posts from Stack Overflow or by Evgeny
Published on 2010-05-24T23:17:46Z Indexed on 2010/05/24 23:21 UTC
Read the original article Hit count: 250

Filed under:
|

I'm trying to define my own (very simple) exception class in Python 2.6, but no matter how I do it I get some warning.

First, the simplest way:

class MyException(Exception):
    pass

This works, but prints out a warning at runtime: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 OK, so that's not the way. I then tried:

class MyException(Exception):
    def __init__(self, message):
        self.message = message

This also works, but PyLint reports a warning: W0231: MyException.__init__: __init__ method from base class 'Exception' is not called. So I tried calling it:

class MyException(Exception):
    def __init__(self, message):
        super(Exception, self).__init__(message)
        self.message = message

This works, too! But now PyLint reports an error: E1003: MyException.__init__: Bad first argument 'Exception' given to super class

How the hell do I do such a simple thing without any warnings?

© Stack Overflow or respective owner

Related posts about python

Related posts about exceptions