A flake8 plugin that finds improvements for raise statements.
Install using pip:
$ pip install flake8-raiseWhen installed, the plugin will automatically be used by flake8. To check
it is installed correctly, run flake8 --version and look in the list of
installed plugins:
$ flake8 --version
3.7.9 (flake8-raise: 0.0.5, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.8.1 on Linux| Code | Rule |
|---|---|
| R100 | raise in except handler without from |
| R101 | use bare raise in except handler |
| R102 | unnecessary parentheses on raised exception |
try:
foo["bar"]
except KeyError:
raise MyExceptionWill result in the error:
R100 raise in except handler without from.
To fix, change to:
try:
foo['bar']
except KeyError as e:
raise MyException from etry:
foo["bar"]
except KeyError as e:
raise eWill result in the error:
R101 Use bare raise in except handler.
To fix, change to:
try:
foo['bar']
except KeyError:
raiseraise TypeError()Will result in the error:
R102 unnecessary parentheses on raised exception
To fix, change to:
raise TypeError