PK!zU@ flake8_return/__init__.pyimport ast from typing import List, Optional from flake8_plugin_utils import Error, Plugin, Visitor __version__ = '0.2.0' class UnnecessaryReturnNone(Error): code = 'R501' message = ( 'you shouldn`t add None at any return ' 'if function havn`t return value except None' ) class ImplicitReturnValue(Error): code = 'R502' message = ( 'you should add explicit value at every return ' 'if function have return value except None' ) class ImplicitReturn(Error): code = 'R503' message = ( 'you should add explicit return at end of the function ' 'if function have return value except None' ) class ReturnVisitor(Visitor): def __init__(self) -> None: super().__init__() self._returns_stack: List[List[ast.Return]] = [] def visit_FunctionDef(self, node: ast.FunctionDef) -> None: self._returns_stack.append([]) self.generic_visit(node) return_nodes = self._returns_stack.pop() if not return_nodes: return if self._result_exists(return_nodes): self._check_implicit_return_value(return_nodes) self._check_implicit_return(node.body[-1]) else: self._check_unnecessary_return_none(return_nodes) def visit_Return(self, node: ast.Return) -> None: self._returns_stack[-1].append(node) def _result_exists(self, nodes: List[ast.Return]) -> bool: for node in nodes: value = node.value if value and not _is_none(value): return True return False def _check_implicit_return_value(self, nodes: List[ast.Return]) -> None: for node in nodes: if not node.value: self.error_from_node(ImplicitReturnValue, node) def _check_unnecessary_return_none(self, nodes: List[ast.Return]) -> None: for node in nodes: if _is_none(node.value): self.error_from_node(UnnecessaryReturnNone, node) def _check_implicit_return(self, last_node: ast.AST) -> None: if isinstance(last_node, ast.If): if not last_node.body or not last_node.orelse: self.error_from_node(ImplicitReturn, last_node) return self._check_implicit_return(last_node.body[-1]) self._check_implicit_return(last_node.orelse[-1]) return if isinstance(last_node, ast.For) and last_node.orelse: self._check_implicit_return(last_node.orelse[-1]) return if not isinstance( last_node, (ast.Return, ast.Raise, ast.While, ast.Try) ): self.error_from_node(ImplicitReturn, last_node) def _is_none(node: Optional[ast.AST]) -> bool: return isinstance(node, ast.NameConstant) and node.value is None class ReturnPlugin(Plugin): name = 'flake8-return' version = __version__ visitors = [ReturnVisitor] PK!HIk-3.flake8_return-0.2.0.dist-info/entry_points.txtNINK(I+ϋ 25Y<..PK!611%flake8_return-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 Afonasev Evgeniy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU#flake8_return-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hx,g&flake8_return-0.2.0.dist-info/METADATAUs4b3e'<׃Ci U-"KFgIZCƖ߾o%G/rE;Z'Nag샨0+69OMSU¶)ԡVM!5RxJV@X ՠc? ZD\z_4붖"3WjG/nݘִƗƦp4Z8\ûuZÇ+!U (?agbO#-%0䘿A(ufI}eBƋ+,t0#\"W(D0OfdإC?z[8ȱtQgm)e6`+wYv(mH%>M)ܚl5$13enbg{U̒maXBC'AK-PK!Hhh1$flake8_return-0.2.0.dist-info/RECORDvCP}AXtaxKb!D6