Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix: W602 deprecated form of raising exception

If I use pylint (via sublimerlinter) I get following warning message:

W602 deprecated form of raising exception

This I how I use exceptions in my code:

if CONDITION == True:     raise ValueError, HELPING_EXPLANATION 
like image 822
Framester Avatar asked Aug 16 '12 16:08

Framester


1 Answers

Raise your exception like this:

if CONDITION == True:     raise ValueError(HELPING_EXPLANATION) 

From PEP 8 -- Style Guide for Python Code - Programming Recommendations:

When raising an exception, use raise ValueError('message') instead of the older form raise ValueError, 'message'.

The paren-using form is preferred because when the exception arguments are long or include string formatting, you don't need to use line continuation characters thanks to the containing parentheses. The older form will be removed in Python 3.

like image 120
Framester Avatar answered Sep 28 '22 16:09

Framester