eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.ReturnVisitor

Module implementing a node visitor to check return statements.

Global Attributes

None

Classes

ReturnVisitor Class implementing a node visitor to check return statements.

Functions

None


ReturnVisitor

Class implementing a node visitor to check return statements.

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.

Derived from

ast.NodeVisitor

Class Attributes

Assigns
Loops
Refs
Returns
Tries

Class Methods

None

Methods

ReturnVisitor Constructor
__checkFunction Private method to check a function definition node.
__checkImplicitReturn Private method to check for an implicit return statement.
__checkImplicitReturnValue Private method to check for implicit return values.
__checkUnnecessaryAssign Private method to check for an unnecessary assign statement.
__checkUnnecessaryReturnNone Private method to check for an unnecessary 'return None' statement.
__hasRefsBeforeNextAssign Private method to check for references before a following assign statement.
__hasRefsOrAssignsWithinTryOrLoop Private method to check for references or assignments in exception handlers or loops.
__isFalse Private method to check, if a node value is False.
__isNone Private method to check, if a node value is None.
__resultExists Private method to check the existance of a return result.
__visitAssignTarget Private method to handle an assign target node.
__visitLoop Private method to handle loop nodes.
__visitWithStack Private method to traverse a given function node using a stack.
assigns Public method to get the Assign nodes.
loops Public method to get the Loop nodes.
refs Public method to get the References nodes.
returns Public method to get the Return nodes.
tries Public method to get the Try nodes.
visit_Assign Public method to handle an assign node.
visit_AsyncFor Public method to handle an async for loop.
visit_AsyncFunctionDef Public method to handle a function definition.
visit_For Public method to handle a for loop.
visit_FunctionDef Public method to handle a function definition.
visit_Name Public method to handle a name node.
visit_Return Public method to handle a return node.
visit_Try Public method to handle a try/except node.
visit_While Public method to handle a while loop.

Static Methods

None

ReturnVisitor (Constructor)

ReturnVisitor()

Constructor

ReturnVisitor.__checkFunction

__checkFunction(node)

Private method to check a function definition node.

node (ast.AsyncFunctionDef or ast.FunctionDef)
reference to the node to check

ReturnVisitor.__checkImplicitReturn

__checkImplicitReturn(node)

Private method to check for an implicit return statement.

node (ast.AST)
reference to the node to check

ReturnVisitor.__checkImplicitReturnValue

__checkImplicitReturnValue()

Private method to check for implicit return values.

ReturnVisitor.__checkUnnecessaryAssign

__checkUnnecessaryAssign(node)

Private method to check for an unnecessary assign statement.

node (ast.AST)
reference to the node to check

ReturnVisitor.__checkUnnecessaryReturnNone

__checkUnnecessaryReturnNone()

Private method to check for an unnecessary 'return None' statement.

ReturnVisitor.__hasRefsBeforeNextAssign

__hasRefsBeforeNextAssign(varname, returnLineno)

Private method to check for references before a following assign statement.

varname (str)
variable name to check for
returnLineno (int)
line number of the return statement
Return:
flag indicating the existence of references
Return Type:
bool

ReturnVisitor.__hasRefsOrAssignsWithinTryOrLoop

__hasRefsOrAssignsWithinTryOrLoop(varname: str)

Private method to check for references or assignments in exception handlers or loops.

varname (str)
name of the variable to check for
Return:
flag indicating a reference or assignment
Return Type:
bool

ReturnVisitor.__isFalse

__isFalse(node)

Private method to check, if a node value is False.

node (ast.AST)
reference to the node to check
Return:
flag indicating the node contains a False value
Return Type:
bool

ReturnVisitor.__isNone

__isNone(node)

Private method to check, if a node value is None.

node (ast.AST)
reference to the node to check
Return:
flag indicating the node contains a None value
Return Type:
bool

ReturnVisitor.__resultExists

__resultExists()

Private method to check the existance of a return result.

Return:
flag indicating the existence of a return result
Return Type:
bool

ReturnVisitor.__visitAssignTarget

__visitAssignTarget(node)

Private method to handle an assign target node.

node (ast.AST)
reference to the node to handle

ReturnVisitor.__visitLoop

__visitLoop(node)

Private method to handle loop nodes.

node (ast.For, ast.AsyncFor or ast.While)
reference to the loop node to handle

ReturnVisitor.__visitWithStack

__visitWithStack(node)

Private method to traverse a given function node using a stack.

node (ast.FunctionDef or ast.AsyncFunctionDef)
AST node to be traversed

ReturnVisitor.assigns

assigns()

Public method to get the Assign nodes.

Return:
dictionary containing the node name as key and line number as value
Return Type:
dict

ReturnVisitor.loops

loops()

Public method to get the Loop nodes.

Return:
dictionary containing the node name as key and line number as value
Return Type:
dict

ReturnVisitor.refs

refs()

Public method to get the References nodes.

Return:
dictionary containing the node name as key and line number as value
Return Type:
dict

ReturnVisitor.returns

returns()

Public method to get the Return nodes.

Return:
dictionary containing the node name as key and line number as value
Return Type:
dict

ReturnVisitor.tries

tries()

Public method to get the Try nodes.

Return:
dictionary containing the node name as key and line number as value
Return Type:
dict

ReturnVisitor.visit_Assign

visit_Assign(node)

Public method to handle an assign node.

node (ast.Assign)
reference to the node to handle

ReturnVisitor.visit_AsyncFor

visit_AsyncFor(node)

Public method to handle an async for loop.

node (ast.AsyncFor)
reference to the async for node to handle

ReturnVisitor.visit_AsyncFunctionDef

visit_AsyncFunctionDef(node)

Public method to handle a function definition.

node (ast.AsyncFunctionDef)
reference to the node to handle

ReturnVisitor.visit_For

visit_For(node)

Public method to handle a for loop.

node (ast.For)
reference to the for node to handle

ReturnVisitor.visit_FunctionDef

visit_FunctionDef(node)

Public method to handle a function definition.

node (ast.FunctionDef)
reference to the node to handle

ReturnVisitor.visit_Name

visit_Name(node)

Public method to handle a name node.

node (ast.Name)
reference to the node to handle

ReturnVisitor.visit_Return

visit_Return(node)

Public method to handle a return node.

node (ast.Return)
reference to the node to handle

ReturnVisitor.visit_Try

visit_Try(node)

Public method to handle a try/except node.

node (ast.Try)
reference to the node to handle

ReturnVisitor.visit_While

visit_While(node)

Public method to handle a while loop.

node (ast.While)
reference to the while node to handle
Up