Skip to content

overgeneral-exceptions doesn't work for exceptions outside builtins #7495

Closed
@Jackenmen

Description

@Jackenmen

Bug description

# pylint: disable=missing-docstring

class GeneralException(Exception):
    pass


try:
    raise GeneralException('...')
except GeneralException:
    ...
# for comparison, pylint triggers on this
except Exception:
    ...

Configuration

No response

Command used

pylint repro.py --overgeneral-exceptions BaseException,Exception,GeneralException

Pylint output

************* Module repro
repro.py:12:7: W0703: Catching too general exception Exception (broad-except)

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

Expected behavior

I expected to get broad-except message for line 9 (which is not happening regardless of whether except Exception is there or not).

This is also reproducible when making a whole package and referring to the exception class using package.GeneralException name (which I personally think would be the best way of specifying non-builtin exceptions).

This seems to vastly limit the usefulness of --overgeneral-exceptions.

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]

OS / Environment

Kubuntu 22.04.1 LTS

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲ConfigurationRelated to configurationEnhancement ✨Improvement to a componentGood first issueFriendly and approachable by new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions