eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker

Module implementing a checker for miscellaneous checks.

Global Attributes

None

Classes

BugBearVisitor Class implementing a node visitor to check for various topics.
LoggingVisitor Class implementing a node visitor to check logging statements.
MiscellaneousChecker Class implementing a checker for miscellaneous checks.
NameFinder Class to extract a name out of a tree of nodes.
TextVisitor Class implementing a node visitor for bytes and str instances.

Functions

composeCallPath Generator function to assemble the call path of a given node.


BugBearVisitor

Class implementing a node visitor to check for various topics.

Derived from

ast.NodeVisitor

Class Attributes

NodeWindowSize

Class Methods

None

Methods

BugBearVisitor Constructor
__checkForM502 Private method to check the use of *strip().
__checkForM507 Private method to check for unused loop variables.
visit Public method to traverse a given AST node.
visit_Assign Public method to handle assignments.
visit_Attribute Public method to handle attributes.
visit_Call Public method to handle a function call.
visit_For Public method to handle 'for' statements.
visit_UAdd Public method to handle unary additions.

Static Methods

None

BugBearVisitor (Constructor)

BugBearVisitor()

Constructor

BugBearVisitor.__checkForM502

__checkForM502(node)

Private method to check the use of *strip().

node (ast.Call)
reference to the node to be processed

BugBearVisitor.__checkForM507

__checkForM507(node)

Private method to check for unused loop variables.

node (ast.For)
reference to the node to be processed

BugBearVisitor.visit

visit(node)

Public method to traverse a given AST node.

node (ast.Node)
AST node to be traversed

BugBearVisitor.visit_Assign

visit_Assign(node)

Public method to handle assignments.

node (ast.Assign)
reference to the node to be processed

BugBearVisitor.visit_Attribute

visit_Attribute(node)

Public method to handle attributes.

node (ast.Attribute)
reference to the node to be processed

BugBearVisitor.visit_Call

visit_Call(node)

Public method to handle a function call.

node (ast.Call)
reference to the node to be processed

BugBearVisitor.visit_For

visit_For(node)

Public method to handle 'for' statements.

node (ast.For)
reference to the node to be processed

BugBearVisitor.visit_UAdd

visit_UAdd(node)

Public method to handle unary additions.

node (ast.UAdd)
reference to the node to be processed
Up


LoggingVisitor

Class implementing a node visitor to check logging statements.

Derived from

ast.NodeVisitor

Class Attributes

LoggingLevels

Class Methods

None

Methods

LoggingVisitor Constructor
__detectLoggingLevel Private method to decide whether an AST Call is a logging call.
__isFormatCall Private method to check if a function call uses format.
__withinExtraKeyword Private method to check, if we are inside the extra keyword.
__withinLoggingArgument Private method to check, if we are inside a logging argument.
__withinLoggingStatement Private method to check, if we are inside a logging statement.
visit_BinOp Public method to handle binary operations while processing the first logging argument.
visit_Call Public method to handle a function call.
visit_JoinedStr Public method to handle f-string arguments.

Static Methods

None

LoggingVisitor (Constructor)

LoggingVisitor()

Constructor

LoggingVisitor.__detectLoggingLevel

__detectLoggingLevel(node)

Private method to decide whether an AST Call is a logging call.

node (ast.Call)
reference to the node to be processed
Returns:
logging level
Return Type:
str or None

LoggingVisitor.__isFormatCall

__isFormatCall(node)

Private method to check if a function call uses format.

node (ast.Call)
reference to the node to be processed
Returns:
flag indicating the function call uses format
Return Type:
bool

LoggingVisitor.__withinExtraKeyword

__withinExtraKeyword(node)

Private method to check, if we are inside the extra keyword.

node (ast.keyword)
reference to the node to be checked
Returns:
flag indicating we are inside the extra keyword
Return Type:
bool

LoggingVisitor.__withinLoggingArgument

__withinLoggingArgument()

Private method to check, if we are inside a logging argument.

Returns:
flag indicating we are inside a logging argument
Return Type:
bool

LoggingVisitor.__withinLoggingStatement

__withinLoggingStatement()

Private method to check, if we are inside a logging statement.

Returns:
flag indicating we are inside a logging statement
Return Type:
bool

LoggingVisitor.visit_BinOp

visit_BinOp(node)

Public method to handle binary operations while processing the first logging argument.

node (ast.BinOp)
reference to the node to be processed

LoggingVisitor.visit_Call

visit_Call(node)

Public method to handle a function call.

Every logging statement and string format is expected to be a function call.

node (ast.Call)
reference to the node to be processed

LoggingVisitor.visit_JoinedStr

visit_JoinedStr(node)

Public method to handle f-string arguments.

node (ast.JoinedStr)
reference to the node to be processed
Up


MiscellaneousChecker

Class implementing a checker for miscellaneous checks.

Derived from

object

Class Attributes

BuiltinsWhiteList
Codes
FormatFieldRegex
Formatter

Class Methods

None

Methods

MiscellaneousChecker Constructor
__checkBugBear Private method to bugbear checks.
__checkBuiltins Private method to check, if built-ins are shadowed.
__checkCoding Private method to check the presence of a coding line and valid encodings.
__checkComprehensions Private method to check some comprehension related things.
__checkCopyright Private method to check the presence of a copyright statement.
__checkDictWithSortedKeys Private method to check, if dictionary keys appear in sorted order.
__checkFormatString Private method to check string format strings.
__checkFuture Private method to check the __future__ imports.
__checkGettext Private method to check the 'gettext' import statement.
__checkLogging Private method to check logging statements.
__checkMutableDefault Private method to check for use of mutable types as default arguments.
__checkPep3101 Private method to check for old style string formatting.
__checkPrintStatements Private method to check for print statements.
__checkTuple Private method to check for one element tuples.
__dictShouldBeChecked Private function to test, if the node should be checked.
__error Private method to record an issue.
__getCoding Private method to get the defined coding of the source.
__getFields Private method to extract the format field information.
__ignoreCode Private method to check if the message code should be ignored.
__reportInvalidSyntax Private method to report a syntax error.
run Public method to check the given source against miscellaneous conditions.

Static Methods

None

MiscellaneousChecker (Constructor)

MiscellaneousChecker(source, filename, select, ignore, expected, repeat, args)

Constructor

source (list of str)
source code to be checked
filename (str)
name of the source file
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 miscellaneous checks

MiscellaneousChecker.__checkBugBear

__checkBugBear()

Private method to bugbear checks.

MiscellaneousChecker.__checkBuiltins

__checkBuiltins()

Private method to check, if built-ins are shadowed.

MiscellaneousChecker.__checkCoding

__checkCoding()

Private method to check the presence of a coding line and valid encodings.

MiscellaneousChecker.__checkComprehensions

__checkComprehensions()

Private method to check some comprehension related things.

MiscellaneousChecker.__checkCopyright

__checkCopyright()

Private method to check the presence of a copyright statement.

MiscellaneousChecker.__checkDictWithSortedKeys

__checkDictWithSortedKeys()

Private method to check, if dictionary keys appear in sorted order.

MiscellaneousChecker.__checkFormatString

__checkFormatString()

Private method to check string format strings.

MiscellaneousChecker.__checkFuture

__checkFuture()

Private method to check the __future__ imports.

MiscellaneousChecker.__checkGettext

__checkGettext()

Private method to check the 'gettext' import statement.

MiscellaneousChecker.__checkLogging

__checkLogging()

Private method to check logging statements.

MiscellaneousChecker.__checkMutableDefault

__checkMutableDefault()

Private method to check for use of mutable types as default arguments.

MiscellaneousChecker.__checkPep3101

__checkPep3101()

Private method to check for old style string formatting.

MiscellaneousChecker.__checkPrintStatements

__checkPrintStatements()

Private method to check for print statements.

MiscellaneousChecker.__checkTuple

__checkTuple()

Private method to check for one element tuples.

MiscellaneousChecker.__dictShouldBeChecked

__dictShouldBeChecked(node)

Private function to test, if the node should be checked.

node
reference to the AST node
Returns:
flag indicating to check the node
Return Type:
bool

MiscellaneousChecker.__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

MiscellaneousChecker.__getCoding

__getCoding()

Private method to get the defined coding of the source.

Returns:
tuple containing the line number and the coding
Return Type:
tuple of int and str

MiscellaneousChecker.__getFields

__getFields(string)

Private method to extract the format field information.

string (str)
format string to be parsed
Returns:
format field information as a tuple with fields, implicit field definitions present and explicit field definitions present
Return Type:
tuple of set of str, bool, bool

MiscellaneousChecker.__ignoreCode

__ignoreCode(code)

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

code (str)
message code to check for
Returns:
flag indicating to ignore the given code
Return Type:
bool

MiscellaneousChecker.__reportInvalidSyntax

__reportInvalidSyntax()

Private method to report a syntax error.

MiscellaneousChecker.run

run()

Public method to check the given source against miscellaneous conditions.

Up


NameFinder

Class to extract a name out of a tree of nodes.

Derived from

ast.NodeVisitor

Class Attributes

None

Class Methods

None

Methods

NameFinder Constructor
getNames Public method to return the extracted names and Name nodes.
visit Public method to traverse a given AST node.
visit_Name Public method to handle 'Name' nodes.

Static Methods

None

NameFinder (Constructor)

NameFinder()

Constructor

NameFinder.getNames

getNames()

Public method to return the extracted names and Name nodes.

Returns:
dictionary containing the names as keys and the list of nodes
Return Type:
dict

NameFinder.visit

visit(node)

Public method to traverse a given AST node.

node (ast.Node)
AST node to be traversed

NameFinder.visit_Name

visit_Name(node)

Public method to handle 'Name' nodes.

node (ast.Name)
reference to the node to be processed
Up


TextVisitor

Class implementing a node visitor for bytes and str instances.

It tries to detect docstrings as string of the first expression of each module, class or function.

Derived from

ast.NodeVisitor

Class Attributes

None

Class Methods

None

Methods

TextVisitor Constructor
__addNode Private method to add a node to our list of nodes.
__isBaseString Private method to determine, if a node is a base string node.
__visitBody Private method to traverse the body of the node manually.
__visitDefinition Private method handling class and function definitions.
visit_AsyncFunctionDef Public method to handle an asynchronous function definition.
visit_Bytes Public method to record a bytes node.
visit_Call Public method to handle a function call.
visit_ClassDef Public method to handle a class definition.
visit_FunctionDef Public method to handle a function definition.
visit_Module Public method to handle a module.
visit_Str Public method to record a string node.

Static Methods

None

TextVisitor (Constructor)

TextVisitor()

Constructor

TextVisitor.__addNode

__addNode(node)

Private method to add a node to our list of nodes.

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

TextVisitor.__isBaseString

__isBaseString(node)

Private method to determine, if a node is a base string node.

node (ast.AST)
reference to the node to check
Returns:
flag indicating a base string
Return Type:
bool

TextVisitor.__visitBody

__visitBody(node)

Private method to traverse the body of the node manually.

If the first node is an expression which contains a string or bytes it marks that as a docstring.

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

TextVisitor.__visitDefinition

__visitDefinition(node)

Private method handling class and function definitions.

node (ast.FunctionDef, ast.AsyncFunctionDef or ast.ClassDef)
reference to the node to handle

TextVisitor.visit_AsyncFunctionDef

visit_AsyncFunctionDef(node)

Public method to handle an asynchronous function definition.

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

TextVisitor.visit_Bytes

visit_Bytes(node)

Public method to record a bytes node.

node (ast.Bytes)
reference to the bytes node

TextVisitor.visit_Call

visit_Call(node)

Public method to handle a function call.

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

TextVisitor.visit_ClassDef

visit_ClassDef(node)

Public method to handle a class definition.

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

TextVisitor.visit_FunctionDef

visit_FunctionDef(node)

Public method to handle a function definition.

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

TextVisitor.visit_Module

visit_Module(node)

Public method to handle a module.

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

TextVisitor.visit_Str

visit_Str(node)

Public method to record a string node.

node (ast.Str)
reference to the string node
Up


composeCallPath

composeCallPath(node)

Generator function to assemble the call path of a given node.

node (ast.Node)
node to assemble call path for
Returns:
call path components
Return Type:
str
Up