New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-return] Only add return None at end of function (RET503) #11074
base: main
Are you sure you want to change the base?
[flake8-return] Only add return None at end of function (RET503) #11074
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RET503 | 762 | 362 | 400 | 0 | 0 |
RUF100 | 2 | 2 | 0 | 0 | 0 |
if checker.settings.preview.is_enabled() { | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return if in preview mode because we only need to know if the function has at least one implicit return to add a single return None
at the end of the function.
The stable version can add multiple return so it cannot return early.
The code should be simplified once the preview version become stable.
A comment should be added that when the preview version becomes stable the code can be simplified with early return everywhere. |
Summary
In
RET503
documentation, it is said that it only addsreturn None
at the end of functions.The current behavior can add
return None
in multiple place in the function, but not at the end of the function.This behavior does not match the documentation and goes against other
flake8-return
rules likeRET505
and caused people to open #5765.The new behavior only adds
return None
at the end of functions like in the documentation and results in more readable code.The new behavior is only available in preview mode.
The range of
RET503
is changed to be the entire function, as it will be more clear it concerns the entire function.Before
After
Test Plan
I added a preview snapshot for
RET503
.I compared the diff between the
RET503
stable and preview snapshot.I checked the ecosystem reports and fixed one regression.