Raise From Previous Error
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: raise-from-previous-error
Section titled “Sourcery refactoring id: raise-from-previous-error”Description:
Section titled “Description:”Suggests raising from a previously-raised exception.
Before:
Section titled “Before:”x = int(input())
try: print(1 / x)except ZeroDivisionError: raise ValueError("Can't divide by zero")After:
Section titled “After:”x = int(input())
try: print(1 / x)except ZeroDivisionError as e: raise ValueError("Can't divide by zero") from eExplanation:
Section titled “Explanation:”Exception chaining was introduced in Python 3
PEP 3134, and is an implicit part
of exception handling. This suggestion converts the implicit exception chain
into an explicit one, as suggested by Pylint’s raise-missing-from error.