B042 has naive definition of exception
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 123
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
B042 (introduced in #421 / #512) has a naive way of determining whether a class is an exception:
https://github.com/PyCQA/flake8-bugbear/blob/915edea6f1c7ca98fbc15f893917d1da46ae79c6/bugbear.py#L1798-L1802
It is based solely on the name of the class, which means it returns True even if the class is not an exception.
For example, if I have a context manager class called FailOnException, it will trigger, even though that class is not an exception at all:
from typing import (ContextManager, TypeVar)
T = TypeVar("T")
class FailOnException(ContextManager[T]): pass
print(FailOnException.__mro__)
(<class '__main__.FailOnException'>, <class 'contextlib.AbstractContextManager'>, <class 'abc.ABC'>, <class 'typing.Generic'>, <class 'object'>)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in bugbear.py at the linked lines 1798-1802 and reproduce the FailOnException example from the issue. B042 should distinguish actual exception classes from classes whose names merely contain exception-related wording, while continuing to identify real exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100