B042 (introduced in #421 / #512) has a naive way of determining whether a class is an exception:
|
def is_exception(s: str): |
|
for ending in "Exception", "Error", "Warning", "ExceptionGroup": |
|
if s.endswith(ending): |
|
return True |
|
return False |
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'>)
B042 (introduced in #421 / #512) has a naive way of determining whether a class is an exception:
flake8-bugbear/bugbear.py
Lines 1798 to 1802 in 915edea
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: