# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Naming.NamingStyleChecker

Module implementing a checker for naming conventions.

### Global Attributes

None

### Classes

NamingStyleChecker | Class implementing a checker for naming conventions.

### Functions

None

## NamingStyleChecker

Class implementing a checker for naming conventions.

### Derived from

None

### Class Attributes

Codes

### Class Methods

None

### Methods

NamingStyleChecker | Constructor (according to 'extended' pycodestyle.py API)
__checkClassName | Private class to check the given node for class name conventions (N801, N818).
__checkFunctionArgumentNames | Private class to check the argument names of functions (N803, N804, N805, N806).
__checkFunctionName | Private class to check the given node for function name conventions (N802, N809).
__checkImportAs | Private method to check that imports don't change the naming convention (N811, N812, N813, N814, N815).
__checkModule | Private method to check module naming conventions (N807, N808).
__checkNameToBeAvoided | Private class to check the given node for a name to be avoided (N831).
__checkVariableNames | Private method to check variable names in function, class and global scope (N821, N822, N823).
__classVariableCheck | Private method to determine the error code for a variable in class scope.
__error | Private method to build the error information.
__extractNames | Private method to extract the names from the target node.
__findGlobalDefs | Private method amend a node with global definitions information.
__findVariableNameErrors | Private method to check, if there is a variable name error.
__functionVariableCheck | Private method to determine the error code for a variable in class scope.
__getArgNames | Private method to get the argument names of a function node.
__getClassdef | Private method to extract the class definition.
__globalVariableCheck | Private method to determine the error code for a variable in global scope.
__isMixedCase | Private method to check, if the given name is mixed case.
__isNameToBeAvoided | Private method to check, if the given name should be avoided.
__isNamedTupel | Private method to check, if a node is a named tuple.
__superClassNames | Private method to extract the names of all super classes.
__tagClassFunctions | Private method to tag functions if they are methods, class methods or static methods.
__visitNode | Private method to inspect the given AST node.
__visitTree | Private method to scan the given AST tree.
run | Public method run by the pycodestyle.py checker.

### Static Methods

None

#### NamingStyleChecker (Constructor)

NamingStyleChecker(tree, filename, options)

Constructor (according to 'extended' pycodestyle.py API)

tree (ast.AST)
  AST tree of the source file
filename (str)
  name of the source file
options (optparse.Option)
  options as parsed by pycodestyle.StyleGuide

#### NamingStyleChecker.__checkClassName

__checkClassName(node, parents)

Private class to check the given node for class name conventions (N801, N818).

Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition.

node (ast.ClassDef)
  AST note to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkFunctionArgumentNames

__checkFunctionArgumentNames(node, parents)

Private class to check the argument names of functions (N803, N804, N805, N806).

The argument names of a function should be lowercase, with words separated by underscores. A class method should have 'cls' as the first argument. A method should have 'self' as the first argument.

node (ast.FunctionDef or ast.AsynFunctionDef)
  AST note to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkFunctionName

__checkFunctionName(node, parents)

Private class to check the given node for function name conventions (N802, N809).

Function names should be lowercase, with words separated by underscores as necessary to improve readability. Functions not being methods '__' in front and back are not allowed. Mixed case is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

node (ast.FunctionDef or ast.AsynFunctionDef)
  AST note to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkImportAs

__checkImportAs(node, parents)

Private method to check that imports don't change the naming convention (N811, N812, N813, N814, N815).

node (ast.Import)
  AST node to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkModule

__checkModule(node, parents)

Private method to check module naming conventions (N807, N808).

Module and package names should be lowercase.

node (ast.AST)
  AST node to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkNameToBeAvoided

__checkNameToBeAvoided(node, parents)

Private class to check the given node for a name to be avoided (N831).

node (ast.Ast)
  AST note to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__checkVariableNames

__checkVariableNames(node, parents)

Private method to check variable names in function, class and global scope (N821, N822, N823).

Local variables in functions should be lowercase.

node (ast.AST)
  AST note to check
parents (list of ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__classVariableCheck

__classVariableCheck(name)

Private method to determine the error code for a variable in class scope.

name (str)
  variable name to be checked

Return:
  error code or None

Return Type:
  str or None

#### NamingStyleChecker.__error

__error(node, code)

Private method to build the error information.

node (ast.AST)
  AST node to report an error for
code (str)
  error code to report

Return:
  tuple giving line number, offset within line and error code

Return Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__extractNames

__extractNames(assignmentTarget)

Private method to extract the names from the target node.

assignmentTarget (ast.Name, ast.Tuple, ast.List or ast.ExceptHandler)
  target node of the assignment

Yield:
  name of the variable

Yield Type:
  str

#### NamingStyleChecker.__findGlobalDefs

__findGlobalDefs(functionNode)

Private method amend a node with global definitions information.

functionNode (ast.FunctionDef or ast.AsyncFunctionDef)
  AST tree node to amend

#### NamingStyleChecker.__findVariableNameErrors

__findVariableNameErrors(assignmentTarget, parents)

Private method to check, if there is a variable name error.

assignmentTarget (ast.Name, ast.Tuple, ast.List or ast.ExceptHandler)
  target node of the assignment
parents (ast.AST)
  list of parent nodes

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__functionVariableCheck

__functionVariableCheck(func, varName)

Private method to determine the error code for a variable in class scope.

func (ast.FunctionDef or ast.AsyncFunctionDef)
  reference to the function definition node
varName (str)
  variable name to be checked

Return:
  error code or None

Return Type:
  str or None

#### NamingStyleChecker.__getArgNames

__getArgNames(node)

Private method to get the argument names of a function node.

node (ast.FunctionDef or ast.AsyncFunctionDef)
  AST node to extract arguments names from

Return:
  list of argument names

Return Type:
  list of str

#### NamingStyleChecker.__getClassdef

__getClassdef(name, parents)

Private method to extract the class definition.

name (str)
  name of the class
parents (list of ast.AST)
  list of parent nodes

Return:
  node containing the class definition

Return Type:
  ast.ClassDef

#### NamingStyleChecker.__globalVariableCheck

__globalVariableCheck(name)

Private method to determine the error code for a variable in global scope.

name (str)
  variable name to be checked

Return:
  error code or None

Return Type:
  str or None

#### NamingStyleChecker.__isMixedCase

__isMixedCase(name)

Private method to check, if the given name is mixed case.

name (str)
  variable name to be checked

Return:
  flag indicating mixed case

Return Type:
  bool

#### NamingStyleChecker.__isNameToBeAvoided

__isNameToBeAvoided(name)

Private method to check, if the given name should be avoided.

name (str)
  name to be checked

Return:
  flag indicating to avoid it

Return Type:
  bool

#### NamingStyleChecker.__isNamedTupel

__isNamedTupel(nodeValue)

Private method to check, if a node is a named tuple.

nodeValue (ast.AST)
  node to be checked

Return:
  flag indicating a nemd tuple

Return Type:
  bool

#### NamingStyleChecker.__superClassNames

__superClassNames(name, parents, names=None)

Private method to extract the names of all super classes.

name (str)
  name of the class
parents (list of ast.AST)
  list of parent nodes
names (set of str (optional))
  set of collected class names (defaults to None)

Return:
  set of class names

Return Type:
  set of str

#### NamingStyleChecker.__tagClassFunctions

__tagClassFunctions(classNode)

Private method to tag functions if they are methods, class methods or static methods.

classNode (ast.ClassDef)
  AST tree node to tag

#### NamingStyleChecker.__visitNode

__visitNode(node)

Private method to inspect the given AST node.

node (ast.AST)
  AST tree node to inspect

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.__visitTree

__visitTree(node)

Private method to scan the given AST tree.

node (ast.AST)
  AST tree node to scan

Yield:
  tuple giving line number, offset within line and error code

Yield Type:
  tuple of (int, int, str)

#### NamingStyleChecker.run

run()

Public method run by the pycodestyle.py checker.

Return:
  tuple giving line number, offset within line, code and checker function

Return Type:
  tuple of (int, int, str, function)

Up