Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raising-non-exception False Positive #2431

Closed
dmtucker opened this issue Aug 21, 2018 · 2 comments
Closed

raising-non-exception False Positive #2431

dmtucker opened this issue Aug 21, 2018 · 2 comments

Comments

@dmtucker
Copy link

Steps to reproduce

"""example.py"""


class Error(Exception):
    """some error"""


def _foobar():
    exceptions = tuple([ValueError, TypeError])
    try:
        raise ValueError
    except exceptions as exc:  # pylint: disable=catching-non-exception
        # https://github.com/PyCQA/pylint/issues/1756
        exc = Error(exc)
        if exc:
            raise exc

Current behavior

$ pylint example.py
No config file found, using default configuration
************* Module example
E: 16,12: Raising a new style class which doesn't inherit from BaseException (raising-non-exception)

------------------------------------------------------------------
Your code has been rated at 4.44/10 (previous run: 4.44/10, +0.00)

Expected behavior

$ pylint example.py
No config file found, using default configuration

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

The if seems to be crucial to the repro. For example, this does NOT repro:

"""example.py"""


class Error(Exception):
    """some error"""


def _foobar():
    exceptions = tuple([ValueError, TypeError])
    try:
        raise ValueError
    except exceptions as exc:  # pylint: disable=catching-non-exception
        # https://github.com/PyCQA/pylint/issues/1756
        exc = Error(exc)
        raise exc

This also isn't an issue if #1756 isn't present:

"""example.py"""


class Error(Exception):
    """some error"""


def _foobar():
    try:
        raise ValueError
    except (ValueError, TypeError) as exc:
        exc = Error(exc)
        if exc:
            raise exc

pylint --version output

No config file found, using default configuration
pylint 1.9.3,
astroid 1.6.5
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
@dmtucker
Copy link
Author

This repro is even simpler:

"""example.py"""


def _foobar():
    exceptions = tuple([ValueError, TypeError])
    try:
        raise ValueError
    except exceptions as exc:
        raise exc
$ pylint example.py
No config file found, using default configuration
************* Module example
E:  8,11: Catching an exception which doesn't inherit from Exception: exceptions (catching-non-exception)
E:  9, 8: Raising a new style class which doesn't inherit from BaseException (raising-non-exception)

--------------------------------------------------------------------
Your code has been rated at -6.67/10 (previous run: -6.67/10, +0.00)

@dmtucker
Copy link
Author

I am able to reproduce on 2.1.1 also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant