GitXplorerGitXplorer
j

flake8-raise

public
31 stars
2 forks
1 issues

Commits

List of commits on branch main.
Unverified
22415a4ae85a9dbb859cc92252ad5f7252b8fc98

Prepare for new release 0.0.5

jjdufresne committed 5 years ago
Unverified
985e5ba8848aa363228dd35a9214e1f03afbf408

Install package during flake8 to dogfood itself

jjdufresne committed 5 years ago
Unverified
0e9ed6105706332e28572c4e2418f229004d16a1

Add "R102 unnecessary parentheses on raised exception" rule

jjdufresne committed 5 years ago
Unverified
a826d329a50937c96b8be0924497ec162cd8b3d0

Add minimum supported version of dependencies

jjdufresne committed 5 years ago
Unverified
9e5b957d1e63fff3a41d6cb7310597e62704dd71

Separate lint commands to their own tox/gha targets

jjdufresne committed 5 years ago
Unverified
03618e653abad9fd28f59a6d722b5b0f02797592

Use importlib.metadata.version to get the package version

jjdufresne committed 5 years ago

README

The README file for this repository.

============ flake8-raise

A flake8 <https://flake8.readthedocs.io/>_ plugin that finds improvements for raise statements.

Installation

Install using pip:

.. code-block:: sh

$ pip install flake8-raise

When 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:

.. code-block:: sh

$ 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

Rules

==== ==== Code Rule ==== ==== R100 raise in except handler without from R101 use bare raise in except handler R102 unnecessary parentheses on raised exception ==== ====

Examples

R100 raise in except handler without from


.. code-block:: py

    try:
        foo["bar"]
    except KeyError:
        raise MyException

Will result in the error:

.. code-block:: text

    R100 raise in except handler without from.

To fix, change to:

.. code-block:: py

    try:
        foo['bar']
    except KeyError as e:
        raise MyException from e

R101 use bare ``raise`` in ``except`` handler
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: py

    try:
        foo["bar"]
    except KeyError as e:
        raise e

Will result in the error:

.. code-block:: text

    R101 Use bare raise in except handler.

To fix, change to:

.. code-block:: py

    try:
        foo['bar']
    except KeyError:
        raise

R102 unnecessary parentheses on raised exception
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: py

    raise TypeError()

Will result in the error:

.. code-block:: text

    R102 unnecessary parentheses on raised exception

To fix, change to:

.. code-block:: py

    raise TypeError