# eric7.Plugins.CheckerPlugins.CodeStyleChecker.PathLib.PathlibChecker

Module implementing the checker for functions that can be replaced by use of the pathlib module.

### Global Attributes

None

### Classes

NameResolver | Class to resolve a Name or Attribute node.
PathlibChecker | Class implementing a checker for functions that can be replaced by use of the pathlib module.
PathlibVisitor | Class to traverse the AST node tree and check for potential issues.

### Functions

None

## NameResolver

Class to resolve a Name or Attribute node.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

NameResolver | Constructor
name | Public method to resolve the name.
visit_Attribute | Public method to handle the Attribute AST node.
visit_Name | Public method to handle the Name AST node.

### Static Methods

None

#### NameResolver (Constructor)

NameResolver(importAlias)

Constructor

importAlias (dict)
  reference to the import aliases dictionary

#### NameResolver.name

name()

Public method to resolve the name.

Return:
  resolved name

Return Type:
  str

#### NameResolver.visit_Attribute

visit_Attribute(node)

Public method to handle the Attribute AST node.

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

#### NameResolver.visit_Name

visit_Name(node)

Public method to handle the Name AST node.

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

Up

## PathlibChecker

Class implementing a checker for functions that can be replaced by use of the pathlib module.

### Derived from

None

### Class Attributes

Codes
Function2Code

### Class Methods

None

### Methods

PathlibChecker | Constructor
__checkForReplacement | Private method to check the given node for the need for a replacement.
__error | Private method to record an issue.
__ignoreCode | Private method to check if the message code should be ignored.
run | Public method to check the given source against functions to be replaced by 'pathlib' equivalents.

### Static Methods

None

#### PathlibChecker (Constructor)

PathlibChecker(source, filename, tree, selected, ignored, expected, repeat)

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
selected (list of str)
  list of selected codes
ignored (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

#### PathlibChecker.__checkForReplacement

__checkForReplacement(node, name)

Private method to check the given node for the need for a replacement.

node (ast.AST)
  reference to the AST node to check
name (str)
  resolved name of the node

#### PathlibChecker.__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

#### PathlibChecker.__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

#### PathlibChecker.run

run()

Public method to check the given source against functions to be replaced by 'pathlib' equivalents.

Up

## PathlibVisitor

Class to traverse the AST node tree and check for potential issues.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

PathlibVisitor | Constructor
visit_Call | Public method to handle the Call AST node.
visit_Import | Public method to handle the Import AST node.
visit_ImportFrom | Public method handle the ImportFrom AST node.

### Static Methods

None

#### PathlibVisitor (Constructor)

PathlibVisitor(checkCallback)

Constructor

checkCallback (func)
  callback function taking a reference to the AST node and the resolved name

#### PathlibVisitor.visit_Call

visit_Call(node)

Public method to handle the Call AST node.

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

#### PathlibVisitor.visit_Import

visit_Import(node)

Public method to handle the Import AST node.

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

#### PathlibVisitor.visit_ImportFrom

visit_ImportFrom(node)

Public method handle the ImportFrom AST node.

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

Up