flake8-blind-except
===================
A flake8 extension that checks for blind, catch-all ``except:`` and ``except Exception:`` statements.
As of `pycodestyle 2.1.0 <https://github.com/PyCQA/pycodestyle/commit/543f12b06592c53e2e60edc4846ee02ab9550e8b/>`_, "E722 do not use bare except, specify exception instead" is built-in. However, bare ``Exception`` and ``BaseException`` are still allowed. This extension flags them as `B902`.
Using ``except`` without explicitly specifying which exceptions to catch is generally considered bad practice, since it catches system signals like ``SIGINT``. You probably want to handle system interrupts differently than exceptions occurring in your code.
It's also usually better style to have many small ``try``-``except`` blocks catching specific exceptions instead of a giant ``try:`` block with a catch-all ``except:`` at the bottom. It's also nicer to your fellow programmers to be a bit more specific about what exceptions they can expect in specific parts of the code, and what the proper course of action is when they occur.
An example of code that will fail this check is:
.. code-block:: python
try:
something_scary()
except:
everybody_panic()
However, the following code is valid:
.. code-block:: python
try:
something_terrifying()
except TerrifyingException:
dont_panic()
Installation
------------
If you don't already have it, install ``flake8``::
$ pip install flake8
Then, install the extension::
$ pip install flake8-blind-except
Usage
-----
Run the following to verify that the plugin has been installed correctly::
$ flake8 --version
2.0 (pep8: 1.4.6, flake8-blind-except: 0.1.0, pyflakes: 0.7.3)
Now, when you run ``flake8``, the plugin will automatically be used.
When a blind except is found, ``flake8`` will output::
B901 blind except: statement
or::
B902 blind except Exception: statement
Contributing
------------
I'm not working on Python these days, so probably won't be making updates anytime soon. PRs are welcome though!
Testing
-------
Tests can be run with ``pytest --doctest-modules flake8_blind_except.py``.
Changes
-------
0.2.1 - 2022-03-08
``````````````````
* Remove setuptools from install_requires (#8)
0.2.0 - 2021-01-07
``````````````````
* B902 error added for cases where a blind ``Exception`` is caught.
0.1.1 - 2016-06-27
``````````````````
* ``pep8`` was renamed to ``pycodestyle`` in its 2.0 release. Compatibility update for this change.
0.1.0 - 2014-02-07
``````````````````
* Initial release
Notes
-----
I've tested this package with flake8 2.6.2 + Python 2.7.3 and flake8 3.7.9 + Python 3.7.5.
Raw data
{
"_id": null,
"home_page": "https://github.com/elijahandrews/flake8-blind-except",
"name": "flake8-blind-except",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "flake8 except exception",
"author": "Elijah Andrews",
"author_email": "elijahcandrews@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/be/f8/cb5e0b8c948cb347b8942cb7ce73292a77ec8f9eafb8d5db999c5c1ac62f/flake8-blind-except-0.2.1.tar.gz",
"platform": null,
"description": "flake8-blind-except\n===================\n\nA flake8 extension that checks for blind, catch-all ``except:`` and ``except Exception:`` statements.\n\nAs of `pycodestyle 2.1.0 <https://github.com/PyCQA/pycodestyle/commit/543f12b06592c53e2e60edc4846ee02ab9550e8b/>`_, \"E722 do not use bare except, specify exception instead\" is built-in. However, bare ``Exception`` and ``BaseException`` are still allowed. This extension flags them as `B902`.\n\nUsing ``except`` without explicitly specifying which exceptions to catch is generally considered bad practice, since it catches system signals like ``SIGINT``. You probably want to handle system interrupts differently than exceptions occurring in your code.\n\nIt's also usually better style to have many small ``try``-``except`` blocks catching specific exceptions instead of a giant ``try:`` block with a catch-all ``except:`` at the bottom. It's also nicer to your fellow programmers to be a bit more specific about what exceptions they can expect in specific parts of the code, and what the proper course of action is when they occur.\n\nAn example of code that will fail this check is:\n\n.. code-block:: python\n\n try:\n something_scary()\n except:\n everybody_panic()\n\nHowever, the following code is valid:\n\n.. code-block:: python\n\n try:\n something_terrifying()\n except TerrifyingException:\n dont_panic()\n\nInstallation\n------------\n\nIf you don't already have it, install ``flake8``::\n\n $ pip install flake8\n\nThen, install the extension::\n\n $ pip install flake8-blind-except\n\nUsage\n-----\n\nRun the following to verify that the plugin has been installed correctly::\n\n $ flake8 --version\n 2.0 (pep8: 1.4.6, flake8-blind-except: 0.1.0, pyflakes: 0.7.3)\n\nNow, when you run ``flake8``, the plugin will automatically be used.\n\nWhen a blind except is found, ``flake8`` will output::\n\n B901 blind except: statement\n\nor::\n\n B902 blind except Exception: statement\n\nContributing\n------------\n\nI'm not working on Python these days, so probably won't be making updates anytime soon. PRs are welcome though!\n\nTesting\n-------\n\nTests can be run with ``pytest --doctest-modules flake8_blind_except.py``.\n\nChanges\n-------\n\n0.2.1 - 2022-03-08\n``````````````````\n* Remove setuptools from install_requires (#8)\n\n0.2.0 - 2021-01-07\n``````````````````\n* B902 error added for cases where a blind ``Exception`` is caught.\n\n0.1.1 - 2016-06-27\n``````````````````\n* ``pep8`` was renamed to ``pycodestyle`` in its 2.0 release. Compatibility update for this change.\n\n0.1.0 - 2014-02-07\n``````````````````\n* Initial release\n\nNotes\n-----\n\nI've tested this package with flake8 2.6.2 + Python 2.7.3 and flake8 3.7.9 + Python 3.7.5.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A flake8 extension that checks for blind except: statements",
"version": "0.2.1",
"split_keywords": [
"flake8",
"except",
"exception"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "8bef9ece23e009de0d34ebde7b6769c5",
"sha256": "f25a575a9dcb3eeb3c760bf9c22db60b8b5a23120224ed1faa9a43f75dd7dd16"
},
"downloads": -1,
"filename": "flake8-blind-except-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "8bef9ece23e009de0d34ebde7b6769c5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3729,
"upload_time": "2022-03-18T16:49:13",
"upload_time_iso_8601": "2022-03-18T16:49:13.002213Z",
"url": "https://files.pythonhosted.org/packages/be/f8/cb5e0b8c948cb347b8942cb7ce73292a77ec8f9eafb8d5db999c5c1ac62f/flake8-blind-except-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-03-18 16:49:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "elijahandrews",
"github_project": "flake8-blind-except",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "flake8-blind-except"
}