-
Notifications
You must be signed in to change notification settings - Fork 116
Open
Description
B042 (introduced in #421 / #512) has a naive way of determining whether a class is an exception:
Lines 1798 to 1802 in 915edea
| 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'>)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels