Wemake-python-styleguide: Forbid local variables that are only used in `return` statements

Created on 31 Jan 2019  路  8Comments  路  Source: wemake-services/wemake-python-styleguide

Rule request

Thesis

Sometimes I see code like this:

def function():
     ...
     some_value = ...
     return some_value

What the point in creating this intermediate variable? Why do we need it?

Reasoning

This is done for consistency and more readable source code.

help wanted starter pr-available pr-merged rule request

Most helpful comment

@Chinmaygoyal I am on finish line to complete this issue

All 8 comments

Can I start working on this ? To clarify the fix would be to remove all these intermediate variables in all function returns?

@loucadufault you are welcome!

The fix would be to return a direct value.

Wrong:

def some_function():
     some_value = 1
     return some_value

Correct:

def some_function():
     return 1

Can I work on this issue?

@Chinmaygoyal I am on finish line to complete this issue

@Chinmaygoyal feel free to take #545

Hello @sobolevn
The immediate value is good in the next case:

def function(a):
     result = None
     if a:
         ...  # some actions
        result = 123

     return result

As for me, it is also understandable from the naming of value what we will return after calling of function.

@DmytroLitvinov yes, this code is valid.

What do you mean by:

As for me, it is also understandable from the naming of value what we will return after calling of function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobolevn picture sobolevn  路  4Comments

sobolevn picture sobolevn  路  4Comments

Dreamsorcerer picture Dreamsorcerer  路  3Comments

orsinium picture orsinium  路  5Comments

webknjaz picture webknjaz  路  3Comments