Skip to content

Fix function returns #9286

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

Closed
wants to merge 1 commit into from
Closed

Fix function returns #9286

wants to merge 1 commit into from

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Mar 15, 2024

Description

Improve the readability and performance of function return statements.

% ruff check --select=RET --statistics

    1	RET501	[*] Do not explicitly `return None` in function if it is the only possible return value
   10	RET502 	[*] Do not implicitly `return None` in function able to return non-`None` value
    9	RET503 	[*] Missing explicit `return` at the end of function able to return non-`None` value
    8	RET504 	[*] Unnecessary assignment to `cls` before `return` statement

% ruff check --select=RET --fix --unsafe-fixes

Found 64 errors (28 fixed, 36 remaining).

% ruff rule RET502

implicit-return-value (RET502)

Derived from the flake8-return linter.

Fix is always available.

What it does

Checks for the presence of a return statement with no explicit value,
for functions that return non-None values elsewhere.

Why is this bad?

Including a return statement with no explicit value can cause confusion
when other return statements in the function return non-None values.
Python implicitly assumes return None if no other return value is present.
Adding an explicit return None can make the code more readable by clarifying
intent.

Example

def foo(bar):
    if not bar:
        return
    return 1

Use instead:

def foo(bar):
    if not bar:
        return None
    return 1

@tomchristie
Copy link
Member

Thanks, no.

Furthermore, we need to update our contribution policy so that we're able to decline any and all changes that are not essential to the project. #9270 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants