import something from somewhere import AnotherError class FasterThanLightError(Exception): ... _some_error = Exception # OK def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. Raises: FasterThanLightError: If speed is greater than the speed of light. """ try: return distance / time except ZeroDivisionError as exc: raise FasterThanLightError from exc # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ try: return distance / time except ZeroDivisionError as exc: raise FasterThanLightError from exc # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ try: return distance / time except ZeroDivisionError as exc: raise FasterThanLightError from exc except: raise ValueError # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ try: return distance / time except ZeroDivisionError as exc: print('oops') raise exc # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ try: return distance / time except (ZeroDivisionError, ValueError) as exc: print('oops') raise exc # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ raise AnotherError # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ raise AnotherError() # DOC501 def foo(bar: int): """Foo. Args: bar: Bar. """ raise something.SomeError # DOC501, but can't resolve the error def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ raise _some_error # OK def calculate_speed(distance: float, time: float) -> float: try: return distance / time except ZeroDivisionError as exc: raise FasterThanLightError from exc # OK def calculate_speed(distance: float, time: float) -> float: raise NotImplementedError # OK def foo(bar: int): """Foo. Args: bar: Bar. Raises: SomeError: Wow. """ raise something.SomeError # OK def foo(bar: int): """Foo. Args: bar: Bar. Raises: something.SomeError: Wow. """ raise something.SomeError # DOC501 def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. Raises: TypeError: if you didn't pass a number for both parameters """ try: return distance / time except ZeroDivisionError: print("Oh no, why would you divide something by zero?") raise except TypeError: print("Not a number? Shame on you!") raise # This is fine def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. Args: distance: Distance traveled. time: Time spent traveling. Returns: Speed as distance divided by time. """ try: return distance / time except Exception as e: print(f"Oh no, we encountered {e}") raise def foo(): """Foo. Returns: 42: int. """ if True: raise TypeError # DOC501 else: raise TypeError # no DOC501 here because we already emitted a diagnostic for the earlier `raise TypeError` raise ValueError # DOC501 return 42