raising-bad-type / E0702ΒΆ
Message emitted:
Raising %s while only classes or instances are allowed
Description:
Used when something which is neither a class nor an instance is raised (i.e. a `TypeError` will be raised).
Problematic code:
class FasterThanTheSpeedOfLightError(ZeroDivisionError):
def __init__(self):
super().__init__("You can't go faster than the speed of light !")
def calculate_speed(distance: float, time: float) -> float:
try:
return distance / time
except ZeroDivisionError as e:
raise None # [raising-bad-type]
Correct code:
class FasterThanTheSpeedOfLightError(ZeroDivisionError):
def __init__(self):
super().__init__("You can't go faster than the speed of light !")
def calculate_speed(distance: float, time: float) -> float:
try:
return distance / time
except ZeroDivisionError as e:
raise FasterThanTheSpeedOfLightError() from e
Created by the exceptions checker.