Skip to content

Warn or autofix "return <Exception>" #22201

@andrewwillowen

Description

@andrewwillowen

Summary

I spent an hour today debugging a test with pytest because I didn't realize that I had used return TypeError('blah') when I should have used raise TypeError('blah').

I'm not sure (but willing to be corrected) if there is a case where one would want to return the Exception instead of raise -ing the exception. If there is, then would be good to throw a warning.
If not, then would be better to autofix so that return becomes raise instead.

Closest existing issue I found was #21571 .

Looks like I'm using ruff 0.14.10. Happy to provide more info if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions