Remove Redundant Exception¶
Sourcery refactoring id:
Remove redundant exceptions from an except clause.
except(ValueError, Exception): logger.log("error")
except Exception: logger.log("error")
except clause handles all instances of the defined exception, incl. its
subclasses. If an exception is a subclass of another exception, it's redundant
to mention both explicitly in the except clause.
- All built-in, non-system-exiting exceptions are derived from the
- All user-defined exceptions should also be derived from the
- It's a good practice to have a base exception class for your application
Exception) and have your more specific custom exceptions derive from it.
- merge-except-handler to merge except handlers with the same content
to remove unreachable
instead of empty
to always specify which errors an
exceptblock is handling