--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.ReturnVisitor.html Thu Feb 27 14:42:39 2025 +0100 @@ -0,0 +1,646 @@ +<!DOCTYPE html> +<html><head> +<title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.ReturnVisitor</title> +<meta charset="UTF-8"> +<link rel="stylesheet" href="styles.css"> +</head> +<body> +<a NAME="top" ID="top"></a> +<h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.ReturnVisitor</h1> +<p> +Module implementing a node visitor to check return statements. +</p> + +<h3>Global Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> + +<h3>Classes</h3> +<table> +<tr> +<td><a href="#ReturnVisitor">ReturnVisitor</a></td> +<td>Class implementing a node visitor to check return statements.</td> +</tr> +</table> + +<h3>Functions</h3> +<table> +<tr><td>None</td></tr> +</table> + +<hr /> +<hr /> +<a NAME="ReturnVisitor" ID="ReturnVisitor"></a> +<h2>ReturnVisitor</h2> +<p> + Class implementing a node visitor to check return statements. +</p> +<p> + Note 1: This class is modeled after flake8-return v1.2.0 checker without + checking for superfluous return. + Note 2: This class is a combination of the main visitor class and the various + mixin classes of of the above checker. +</p> + +<h3>Derived from</h3> +ast.NodeVisitor +<h3>Class Attributes</h3> +<table> +<tr><td>Assigns</td></tr> +<tr><td>Loops</td></tr> +<tr><td>Refs</td></tr> +<tr><td>Returns</td></tr> +<tr><td>Tries</td></tr> +</table> + +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> + +<h3>Methods</h3> +<table> +<tr> +<td><a href="#ReturnVisitor.__init__">ReturnVisitor</a></td> +<td>Constructor</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__checkFunction">__checkFunction</a></td> +<td>Private method to check a function definition node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__checkImplicitReturn">__checkImplicitReturn</a></td> +<td>Private method to check for an implicit return statement.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__checkImplicitReturnValue">__checkImplicitReturnValue</a></td> +<td>Private method to check for implicit return values.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__checkUnnecessaryAssign">__checkUnnecessaryAssign</a></td> +<td>Private method to check for an unnecessary assign statement.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__checkUnnecessaryReturnNone">__checkUnnecessaryReturnNone</a></td> +<td>Private method to check for an unnecessary 'return None' statement.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__hasRefsBeforeNextAssign">__hasRefsBeforeNextAssign</a></td> +<td>Private method to check for references before a following assign statement.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__hasRefsOrAssignsWithinTryOrLoop">__hasRefsOrAssignsWithinTryOrLoop</a></td> +<td>Private method to check for references or assignments in exception handlers or loops.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__isFalse">__isFalse</a></td> +<td>Private method to check, if a node value is False.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__isNone">__isNone</a></td> +<td>Private method to check, if a node value is None.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__resultExists">__resultExists</a></td> +<td>Private method to check the existance of a return result.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__visitAssignTarget">__visitAssignTarget</a></td> +<td>Private method to handle an assign target node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__visitLoop">__visitLoop</a></td> +<td>Private method to handle loop nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.__visitWithStack">__visitWithStack</a></td> +<td>Private method to traverse a given function node using a stack.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.assigns">assigns</a></td> +<td>Public method to get the Assign nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.loops">loops</a></td> +<td>Public method to get the Loop nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.refs">refs</a></td> +<td>Public method to get the References nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.returns">returns</a></td> +<td>Public method to get the Return nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.tries">tries</a></td> +<td>Public method to get the Try nodes.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_Assign">visit_Assign</a></td> +<td>Public method to handle an assign node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_AsyncFor">visit_AsyncFor</a></td> +<td>Public method to handle an async for loop.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> +<td>Public method to handle a function definition.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_For">visit_For</a></td> +<td>Public method to handle a for loop.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_FunctionDef">visit_FunctionDef</a></td> +<td>Public method to handle a function definition.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_Name">visit_Name</a></td> +<td>Public method to handle a name node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_Return">visit_Return</a></td> +<td>Public method to handle a return node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_Try">visit_Try</a></td> +<td>Public method to handle a try/except node.</td> +</tr> +<tr> +<td><a href="#ReturnVisitor.visit_While">visit_While</a></td> +<td>Public method to handle a while loop.</td> +</tr> +</table> + +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> + + +<a NAME="ReturnVisitor.__init__" ID="ReturnVisitor.__init__"></a> +<h4>ReturnVisitor (Constructor)</h4> +<b>ReturnVisitor</b>(<i></i>) +<p> + Constructor +</p> + +<a NAME="ReturnVisitor.__checkFunction" ID="ReturnVisitor.__checkFunction"></a> +<h4>ReturnVisitor.__checkFunction</h4> +<b>__checkFunction</b>(<i>node</i>) +<p> + Private method to check a function definition node. +</p> + +<dl> + +<dt><i>node</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> +<dd> +reference to the node to check +</dd> +</dl> +<a NAME="ReturnVisitor.__checkImplicitReturn" ID="ReturnVisitor.__checkImplicitReturn"></a> +<h4>ReturnVisitor.__checkImplicitReturn</h4> +<b>__checkImplicitReturn</b>(<i>node</i>) +<p> + Private method to check for an implicit return statement. +</p> + +<dl> + +<dt><i>node</i> (ast.AST)</dt> +<dd> +reference to the node to check +</dd> +</dl> +<a NAME="ReturnVisitor.__checkImplicitReturnValue" ID="ReturnVisitor.__checkImplicitReturnValue"></a> +<h4>ReturnVisitor.__checkImplicitReturnValue</h4> +<b>__checkImplicitReturnValue</b>(<i></i>) +<p> + Private method to check for implicit return values. +</p> + +<a NAME="ReturnVisitor.__checkUnnecessaryAssign" ID="ReturnVisitor.__checkUnnecessaryAssign"></a> +<h4>ReturnVisitor.__checkUnnecessaryAssign</h4> +<b>__checkUnnecessaryAssign</b>(<i>node</i>) +<p> + Private method to check for an unnecessary assign statement. +</p> + +<dl> + +<dt><i>node</i> (ast.AST)</dt> +<dd> +reference to the node to check +</dd> +</dl> +<a NAME="ReturnVisitor.__checkUnnecessaryReturnNone" ID="ReturnVisitor.__checkUnnecessaryReturnNone"></a> +<h4>ReturnVisitor.__checkUnnecessaryReturnNone</h4> +<b>__checkUnnecessaryReturnNone</b>(<i></i>) +<p> + Private method to check for an unnecessary 'return None' statement. +</p> + +<a NAME="ReturnVisitor.__hasRefsBeforeNextAssign" ID="ReturnVisitor.__hasRefsBeforeNextAssign"></a> +<h4>ReturnVisitor.__hasRefsBeforeNextAssign</h4> +<b>__hasRefsBeforeNextAssign</b>(<i>varname, returnLineno</i>) +<p> + Private method to check for references before a following assign + statement. +</p> + +<dl> + +<dt><i>varname</i> (str)</dt> +<dd> +variable name to check for +</dd> +<dt><i>returnLineno</i> (int)</dt> +<dd> +line number of the return statement +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +flag indicating the existence of references +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl> +<a NAME="ReturnVisitor.__hasRefsOrAssignsWithinTryOrLoop" ID="ReturnVisitor.__hasRefsOrAssignsWithinTryOrLoop"></a> +<h4>ReturnVisitor.__hasRefsOrAssignsWithinTryOrLoop</h4> +<b>__hasRefsOrAssignsWithinTryOrLoop</b>(<i>varname: str</i>) +<p> + Private method to check for references or assignments in exception handlers + or loops. +</p> + +<dl> + +<dt><i>varname</i> (str)</dt> +<dd> +name of the variable to check for +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +flag indicating a reference or assignment +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl> +<a NAME="ReturnVisitor.__isFalse" ID="ReturnVisitor.__isFalse"></a> +<h4>ReturnVisitor.__isFalse</h4> +<b>__isFalse</b>(<i>node</i>) +<p> + Private method to check, if a node value is False. +</p> + +<dl> + +<dt><i>node</i> (ast.AST)</dt> +<dd> +reference to the node to check +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +flag indicating the node contains a False value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl> +<a NAME="ReturnVisitor.__isNone" ID="ReturnVisitor.__isNone"></a> +<h4>ReturnVisitor.__isNone</h4> +<b>__isNone</b>(<i>node</i>) +<p> + Private method to check, if a node value is None. +</p> + +<dl> + +<dt><i>node</i> (ast.AST)</dt> +<dd> +reference to the node to check +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +flag indicating the node contains a None value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl> +<a NAME="ReturnVisitor.__resultExists" ID="ReturnVisitor.__resultExists"></a> +<h4>ReturnVisitor.__resultExists</h4> +<b>__resultExists</b>(<i></i>) +<p> + Private method to check the existance of a return result. +</p> + +<dl> +<dt>Return:</dt> +<dd> +flag indicating the existence of a return result +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool +</dd> +</dl> +<a NAME="ReturnVisitor.__visitAssignTarget" ID="ReturnVisitor.__visitAssignTarget"></a> +<h4>ReturnVisitor.__visitAssignTarget</h4> +<b>__visitAssignTarget</b>(<i>node</i>) +<p> + Private method to handle an assign target node. +</p> + +<dl> + +<dt><i>node</i> (ast.AST)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.__visitLoop" ID="ReturnVisitor.__visitLoop"></a> +<h4>ReturnVisitor.__visitLoop</h4> +<b>__visitLoop</b>(<i>node</i>) +<p> + Private method to handle loop nodes. +</p> + +<dl> + +<dt><i>node</i> (ast.For, ast.AsyncFor or ast.While)</dt> +<dd> +reference to the loop node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.__visitWithStack" ID="ReturnVisitor.__visitWithStack"></a> +<h4>ReturnVisitor.__visitWithStack</h4> +<b>__visitWithStack</b>(<i>node</i>) +<p> + Private method to traverse a given function node using a stack. +</p> + +<dl> + +<dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt> +<dd> +AST node to be traversed +</dd> +</dl> +<a NAME="ReturnVisitor.assigns" ID="ReturnVisitor.assigns"></a> +<h4>ReturnVisitor.assigns</h4> +<b>assigns</b>(<i></i>) +<p> + Public method to get the Assign nodes. +</p> + +<dl> +<dt>Return:</dt> +<dd> +dictionary containing the node name as key and line number + as value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +dict +</dd> +</dl> +<a NAME="ReturnVisitor.loops" ID="ReturnVisitor.loops"></a> +<h4>ReturnVisitor.loops</h4> +<b>loops</b>(<i></i>) +<p> + Public method to get the Loop nodes. +</p> + +<dl> +<dt>Return:</dt> +<dd> +dictionary containing the node name as key and line number + as value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +dict +</dd> +</dl> +<a NAME="ReturnVisitor.refs" ID="ReturnVisitor.refs"></a> +<h4>ReturnVisitor.refs</h4> +<b>refs</b>(<i></i>) +<p> + Public method to get the References nodes. +</p> + +<dl> +<dt>Return:</dt> +<dd> +dictionary containing the node name as key and line number + as value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +dict +</dd> +</dl> +<a NAME="ReturnVisitor.returns" ID="ReturnVisitor.returns"></a> +<h4>ReturnVisitor.returns</h4> +<b>returns</b>(<i></i>) +<p> + Public method to get the Return nodes. +</p> + +<dl> +<dt>Return:</dt> +<dd> +dictionary containing the node name as key and line number + as value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +dict +</dd> +</dl> +<a NAME="ReturnVisitor.tries" ID="ReturnVisitor.tries"></a> +<h4>ReturnVisitor.tries</h4> +<b>tries</b>(<i></i>) +<p> + Public method to get the Try nodes. +</p> + +<dl> +<dt>Return:</dt> +<dd> +dictionary containing the node name as key and line number + as value +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +dict +</dd> +</dl> +<a NAME="ReturnVisitor.visit_Assign" ID="ReturnVisitor.visit_Assign"></a> +<h4>ReturnVisitor.visit_Assign</h4> +<b>visit_Assign</b>(<i>node</i>) +<p> + Public method to handle an assign node. +</p> + +<dl> + +<dt><i>node</i> (ast.Assign)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_AsyncFor" ID="ReturnVisitor.visit_AsyncFor"></a> +<h4>ReturnVisitor.visit_AsyncFor</h4> +<b>visit_AsyncFor</b>(<i>node</i>) +<p> + Public method to handle an async for loop. +</p> + +<dl> + +<dt><i>node</i> (ast.AsyncFor)</dt> +<dd> +reference to the async for node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_AsyncFunctionDef" ID="ReturnVisitor.visit_AsyncFunctionDef"></a> +<h4>ReturnVisitor.visit_AsyncFunctionDef</h4> +<b>visit_AsyncFunctionDef</b>(<i>node</i>) +<p> + Public method to handle a function definition. +</p> + +<dl> + +<dt><i>node</i> (ast.AsyncFunctionDef)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_For" ID="ReturnVisitor.visit_For"></a> +<h4>ReturnVisitor.visit_For</h4> +<b>visit_For</b>(<i>node</i>) +<p> + Public method to handle a for loop. +</p> + +<dl> + +<dt><i>node</i> (ast.For)</dt> +<dd> +reference to the for node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_FunctionDef" ID="ReturnVisitor.visit_FunctionDef"></a> +<h4>ReturnVisitor.visit_FunctionDef</h4> +<b>visit_FunctionDef</b>(<i>node</i>) +<p> + Public method to handle a function definition. +</p> + +<dl> + +<dt><i>node</i> (ast.FunctionDef)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_Name" ID="ReturnVisitor.visit_Name"></a> +<h4>ReturnVisitor.visit_Name</h4> +<b>visit_Name</b>(<i>node</i>) +<p> + Public method to handle a name node. +</p> + +<dl> + +<dt><i>node</i> (ast.Name)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_Return" ID="ReturnVisitor.visit_Return"></a> +<h4>ReturnVisitor.visit_Return</h4> +<b>visit_Return</b>(<i>node</i>) +<p> + Public method to handle a return node. +</p> + +<dl> + +<dt><i>node</i> (ast.Return)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_Try" ID="ReturnVisitor.visit_Try"></a> +<h4>ReturnVisitor.visit_Try</h4> +<b>visit_Try</b>(<i>node</i>) +<p> + Public method to handle a try/except node. +</p> + +<dl> + +<dt><i>node</i> (ast.Try)</dt> +<dd> +reference to the node to handle +</dd> +</dl> +<a NAME="ReturnVisitor.visit_While" ID="ReturnVisitor.visit_While"></a> +<h4>ReturnVisitor.visit_While</h4> +<b>visit_While</b>(<i>node</i>) +<p> + Public method to handle a while loop. +</p> + +<dl> + +<dt><i>node</i> (ast.While)</dt> +<dd> +reference to the while node to handle +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +</body></html>