wemake-python-styleguide: Early return should not take `return None` form when it is not required
Rule request
Thesis
Right now this code:
def _check_parent(self, node: ast.If) -> None:
parent = get_parent(node)
if parent is None:
return None
if isinstance(parent, _ELSE_NODES):
body = parent.body + parent.orelse
else:
body = getattr(parent, 'body', [node])
next_index_in_parent = body.index(node) + 1
if keywords.next_node_returns_bool(body, next_index_in_parent):
self.add_violation(SimplifiableReturningIfViolation(node))
passes our style check. Note return None part there. It is the only return. And it means that None part is not required.
Moreover, it should not be allowed. Simple early returns must be just return`.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (20 by maintainers)
We allow:
We don’t allow:
Are you running pythno3.9?
Ok, we also need to take a closer look at:
I would re-formulate the rule as: if all function
returnnodes arereturn None-> than we must use plainreturn.@DhirajChauhan40 Something like (untested):
You can put it here: https://github.com/wemake-services/wemake-python-styleguide/blob/d41d4b9d70dcad0ece5e7ed7320560de58999fcf/wemake_python_styleguide/visitors/ast/keywords.py#L123
You would still have to:
violationtype inviolations/consistency.py