Derived from the Perflint linter.
What it does#
Checks for uses of except handling via
Why is this bad?#
Exception handling via
except blocks incurs some performance
overhead, regardless of whether an exception is raised.
When possible, refactor your code to put the entire loop into the
except block, rather than wrapping each iteration in a separate
This rule is only enforced for Python versions prior to 3.11, which introduced "zero cost" exception handling.
Note that, as with all
perflint rules, this is only intended as a
micro-optimization, and will have a negligible impact on performance in