# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Unused.UnusedChecker

Module implementing a checker for unused arguments, variables, ... .

### Global Attributes

GlobalVariableStoreInfo

### Classes

FunctionFinder | Class to find all defined functions and methods.
GlobalVariableLoadCounter | Class to find all defined global variables and count their usages.
NameFinder | Class to find the used argument names.
UnusedChecker | Class implementing a checker for unused arguments, variables, ...

### Functions

None

## FunctionFinder

Class to find all defined functions and methods.

### Derived from

ast.NodeVisitor

### Class Attributes

visit_AsyncFunctionDef

### Class Methods

None

### Methods

FunctionFinder | Constructor
__visitFunctionTypes | Private method to handle an AST node defining a function or lambda.
functionNodes | Public method to get the list of detected functions and lambdas.

### Static Methods

None

#### FunctionFinder (Constructor)

FunctionFinder(onlyTopLevel=False)

Constructor

onlyTopLevel (bool (optional))
  flag indicating to search for top level functions only (defaults to False)

#### FunctionFinder.__visitFunctionTypes

__visitFunctionTypes(functionNode)

Private method to handle an AST node defining a function or lambda.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining a function or lambda

#### FunctionFinder.functionNodes

functionNodes()

Public method to get the list of detected functions and lambdas.

Return:
  list of detected functions and lambdas

Return Type:
  list of ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda

Up

## GlobalVariableLoadCounter

Class to find all defined global variables and count their usages.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

GlobalVariableLoadCounter | Constructor
getLoads | Public method to get an iterator of the detected variable loads.
getStoreInfo | Public method to get the store info data of a given variable ID.
visit_Name | Public method to record the definition and use of a global variable.

### Static Methods

None

#### GlobalVariableLoadCounter (Constructor)

GlobalVariableLoadCounter()

Constructor

#### GlobalVariableLoadCounter.getLoads

getLoads()

Public method to get an iterator of the detected variable loads.

Return:
  DESCRIPTION

Return Type:
  TYPE

#### GlobalVariableLoadCounter.getStoreInfo

getStoreInfo(variableId)

Public method to get the store info data of a given variable ID.

variableId (str)
  variable ID to retrieve the store info for

Return:
  named tuple containing the line number and column offset

Return Type:
  GlobalVariableStoreInfo

#### GlobalVariableLoadCounter.visit_Name

visit_Name(nameNode)

Public method to record the definition and use of a global variable.

nameNode (ast.Name)
  reference to the name node to be processed

Up

## NameFinder

Class to find the used argument names.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

visit_Name | Public method to check a Name node.

### Static Methods

None

#### NameFinder.visit_Name

visit_Name(name)

Public method to check a Name node.

name (ast.Name)
  reference to the name node to be checked

Up

## UnusedChecker

Class implementing a checker for unused arguments, variables, ... .

### Derived from

None

### Class Attributes

Codes

### Class Methods

None

### Methods

UnusedChecker | Constructor
__checkUnusedArguments | Private method to check function and method definitions for unused arguments.
__checkUnusedGlobals | Private method to check for unused global variables.
__error | Private method to record an issue.
__extractGlobalVariables | Private method to get the names of all global variables.
__getArguments | Private method to get all argument names of the given function.
__getDecoratorNames | Private method to yield the decorator names of the function.
__getUnusedArguments | Private method to get a list of unused arguments of the given function.
__ignoreCode | Private method to check if the message code should be ignored.
__isDunderMethod | Private method to check, if the function node defines a special function.
__isEventHandlerMethod | Private method to check, if the function node defines a Qt event handler.
__isStubFunction | Private method to check, if the given function node defines a stub function.
run | Public method to check the given source against miscellaneous conditions.

### Static Methods

None

#### UnusedChecker (Constructor)

UnusedChecker(source, filename, tree, select, ignore, expected, repeat, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
tree (ast.Module)
  AST tree of the source code
select (list of str)
  list of selected codes
ignore (list of str)
  list of codes to be ignored
expected (list of str)
  list of expected codes
repeat (bool)
  flag indicating to report each occurrence of a code
args (dict)
  dictionary of arguments for the various checks

#### UnusedChecker.__checkUnusedArguments

__checkUnusedArguments()

Private method to check function and method definitions for unused arguments.

#### UnusedChecker.__checkUnusedGlobals

__checkUnusedGlobals()

Private method to check for unused global variables.

#### UnusedChecker.__error

__error(lineNumber, offset, code, *args)

Private method to record an issue.

lineNumber (int)
  line number of the issue
offset (int)
  position within line of the issue
code (str)
  message code
args (list)
  arguments for the message

#### UnusedChecker.__extractGlobalVariables

__extractGlobalVariables()

Private method to get the names of all global variables.

Return:
  set containing the defined global variable names

Return Type:
  set of str

#### UnusedChecker.__getArguments

__getArguments(functionNode)

Private method to get all argument names of the given function.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Return:
  list of argument names

Return Type:
  list of ast.arg

#### UnusedChecker.__getDecoratorNames

__getDecoratorNames(functionNode)

Private method to yield the decorator names of the function.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Yield:
  decorator name

Yield Type:
  str

#### UnusedChecker.__getUnusedArguments

__getUnusedArguments(functionNode)

Private method to get a list of unused arguments of the given function.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Return:
  list of tuples of the argument position and the argument

Return Type:
  list of tuples of (int, ast.arg)

#### UnusedChecker.__ignoreCode

__ignoreCode(code)

Private method to check if the message code should be ignored.

code (str)
  message code to check for

Return:
  flag indicating to ignore the given code

Return Type:
  bool

#### UnusedChecker.__isDunderMethod

__isDunderMethod(functionNode)

Private method to check, if the function node defines a special function.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Return:
  flag indicating a special function

Return Type:
  bool

#### UnusedChecker.__isEventHandlerMethod

__isEventHandlerMethod(functionNode)

Private method to check, if the function node defines a Qt event handler.

Qt event handler methods are assumed to end with 'Event' or have the name 'event' or 'eventFilter'. Only standard methodes (i.e. ast.FunctionDef) are assumed to be potential event handlers.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Return:
  flag indicating a Qt event handler method

Return Type:
  bool

#### UnusedChecker.__isStubFunction

__isStubFunction(functionNode)

Private method to check, if the given function node defines a stub function.

functionNode (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)
  reference to the node defining the function or lambda

Return:
  flag indicating a stub function

Return Type:
  bool

#### UnusedChecker.run

run()

Public method to check the given source against miscellaneous conditions.

Up