Skip to content
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

Add space after return when inlining number for RET504 #7116

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/ruff/resources/test/fixtures/flake8_return/RET504.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,9 @@ def foo():
def foo():
a = 1 # Comment
return a


# Regression test for: https://github.com/astral-sh/ruff/issues/7098
def mavko_debari(P_kbar):
D=0.4853881 + 3.6006116*P - 0.0117368*(P-1.3822)**2
return D
7 changes: 4 additions & 3 deletions crates/ruff/src/rules/flake8_return/rules/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ruff_python_ast::stmt_if::elif_else_range;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::whitespace::indentation;
use ruff_python_semantic::SemanticModel;
use ruff_python_trivia::is_python_whitespace;

use crate::autofix::edits;
use crate::checkers::ast::Checker;
Expand Down Expand Up @@ -549,11 +550,11 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack) {
if content[after_equals..]
.chars()
.next()
.is_some_and(char::is_alphabetic)
.is_some_and(is_python_whitespace)
{
"return ".to_string()
} else {
"return".to_string()
} else {
"return ".to_string()
},
// Replace from the start of the assignment statement to the end of the equals
// sign.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,25 @@ RET504.py:359:12: RET504 [*] Unnecessary assignment to `a` before `return` state
358 |- a = 1 # Comment
359 |- return a
358 |+ return 1 # Comment
360 359 |
361 360 |
362 361 | # Regression test for: https://github.com/astral-sh/ruff/issues/7098

RET504.py:365:12: RET504 [*] Unnecessary assignment to `D` before `return` statement
|
363 | def mavko_debari(P_kbar):
364 | D=0.4853881 + 3.6006116*P - 0.0117368*(P-1.3822)**2
365 | return D
| ^ RET504
|
= help: Remove unnecessary assignment

Suggested fix
361 361 |
362 362 | # Regression test for: https://github.com/astral-sh/ruff/issues/7098
363 363 | def mavko_debari(P_kbar):
364 |- D=0.4853881 + 3.6006116*P - 0.0117368*(P-1.3822)**2
365 |- return D
364 |+ return 0.4853881 + 3.6006116*P - 0.0117368*(P-1.3822)**2


Loading