eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.BugBearVisitor

Module implementing a visitor to check for various potential issues.

Global Attributes

BugBearContext
BugbearImmutableCalls
BugbearMutableCalls
BugbearMutableComprehensions
BugbearMutableLiterals

Classes

BugBearVisitor Class implementing a node visitor to check for various topics.
ExceptBaseExceptionVisitor Class to determine, if a 'BaseException' is re-raised.
FunctionDefDefaultsVisitor Class used by M506, M508 and M539.
M520NameFinder Class to extract a name out of a tree of nodes ignoring names defined within the local scope of a comprehension.
M540CaughtException Class to hold the data for a caught exception.
M541UnhandledKeyType Class to hold a dictionary key of a type that we do not check for duplicates.
M541VariableKeyType Class to hold the name of a variable key type.
M569Checker Class traversing a 'for' loop body to check for modifications to a loop's mutable iterable.
NameFinder Class to extract a name out of a tree of nodes.
NamedExprFinder Class to extract names defined through an ast.NamedExpr.

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

CONTEXTFUL_NODES
FUNCTION_NODES
NodeWindowSize

Class Methods

None

Methods

BugBearVisitor Constructor
__checkForM505 Private method to check the use of *strip().
__checkForM506_M508 Private method to check the use of mutable literals, comprehensions and calls.
__checkForM507 Private method to check for unused loop variables.
__checkForM512 Private method to check for return/continue/break inside finally blocks.
__checkForM513_M514_M529_M530 Private method to check various exception handler situations.
__checkForM515 Private method to check for pointless comparisons.
__checkForM516 Private method to check for raising a literal instead of an exception.
__checkForM517 Private method to check for use of the evil syntax 'with assertRaises(Exception): or 'with pytest.raises(Exception):'.
__checkForM518 Private method to check for useless expressions.
__checkForM519 Private method to check for use of 'functools.lru_cache' or 'functools.cache'.
__checkForM520 Private method to check for a loop that modifies its iterable.
__checkForM521 Private method to check for use of an f-string as docstring.
__checkForM522 Private method to check for use of an f-string as docstring.
__checkForM523 Private method to check that functions (including lambdas) do not use loop variables.
__checkForM524_M527 Private method to check for inheritance from abstract classes in abc and lack of any methods decorated with abstract*.
__checkForM525 Private method to check for exceptions being handled multiple times.
__checkForM526 Private method to check for Star-arg unpacking after keyword argument.
__checkForM528 Private method to check for warn without stacklevel.
__checkForM531 Private method to check that 'itertools.groupby' isn't iterated over more than once.
__checkForM532 Private method to check for possible unintentional typing annotation.
__checkForM533 Private method to check a set for duplicate items.
__checkForM534 Private method to check that re.sub/subn/split arguments flags/count/maxsplit are passed as keyword arguments.
__checkForM535 Private method to check that a static key isn't used in a dict comprehension.
__checkForM539 Private method to check for correct ContextVar usage.
__checkForM540AddNote Private method to check add_note usage.
__checkForM540Usage Private method to check the usage of exceptions with added note.
__checkForM541 Private method to check for duplicate key value pairs in a dictionary literal.
__checkForM569 Private method to check for changes to a loop's mutable iterable.
__checkRedundantExcepthandlers Private method to check for redundant exception types in an exception handler.
__childrenInScope Private method to get all child nodes in the given scope.
__flattenExcepthandler Private method to flatten the list of exceptions handled by an except handler.
__getAssignedNames Private method to get the names of a for loop.
__getDictCompLoopAndNamedExprVarNames Private method to get the names of comprehension loop variables.
__getNamesFromTuple Private method to get the names from an ast.Tuple node.
__inClassInit Private method to check, if we are inside an '__init__' method.
__isIdentifier Private method to check if arg is a valid identifier.
__namesFromAssignments Private method to get names of an assignment.
__typesafeIssubclass Private method implementing a type safe issubclass() function.
__walkList Private method to walk a given list of nodes.
_loop
check
convertToValue Function to extract the value of a given item.
emptyBody
isAbcClass
isAbstractDecorator
isOverload
isStrOrEllipsis
nodeStack Public method to get a reference to the most recent node stack.
superwalk Function to walk an AST node or a list of AST nodes.
toNameStr Public method to turn Name and Attribute nodes to strings, handling any depth of attribute accesses.
visit Public method to traverse a given AST node.
visit_AnnAssign Public method to check annotated assign statements.
visit_Assert Public method to handle 'assert' statements.
visit_Assign Public method to handle assignments.
visit_AsyncFor Public method to handle 'for' statements.
visit_AsyncFunctionDef Public method to handle async function definitions.
visit_Call Public method to handle a function call.
visit_ClassDef Public method to handle class definitions.
visit_Compare Public method to handle comparison statements.
visit_Dict Public method to check a dictionary.
visit_DictComp Public method to handle dictionary comprehensions.
visit_ExceptHandler Public method to handle exception handlers.
visit_For Public method to handle 'for' statements.
visit_FunctionDef Public method to handle function definitions.
visit_GeneratorExp Public method to handle generator expressions.
visit_Import Public method to check imports.
visit_ImportFrom Public method to check from imports.
visit_JoinedStr Public method to handle f-string arguments.
visit_ListComp Public method to handle list comprehensions.
visit_Module Public method to handle a module node.
visit_Raise Public method to handle 'raise' statements.
visit_Return Public method to handle 'Return' nodes.
visit_Set Public method to check a set.
visit_SetComp Public method to handle set comprehensions.
visit_Try Public method to handle 'try' statements.
visit_TryStar Public method to handle 'except*' statements.
visit_UAdd Public method to handle unary additions.
visit_While Public method to handle 'while' statements.
visit_With Public method to handle 'with' statements.
visit_Yield Public method to handle 'Yield' nodes.
visit_YieldFrom Public method to handle 'YieldFrom' nodes.

Static Methods

None

BugBearVisitor (Constructor)

BugBearVisitor()

Constructor

BugBearVisitor.__checkForM505

__checkForM505(node)

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

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

BugBearVisitor.__checkForM506_M508

__checkForM506_M508(node)

Private method to check the use of mutable literals, comprehensions and calls.

node (ast.AsyncFunctionDef or ast.FunctionDef)
reference to the node to be processed

BugBearVisitor.__checkForM507

__checkForM507(node)

Private method to check for unused loop variables.

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

BugBearVisitor.__checkForM512

__checkForM512(node)

Private method to check for return/continue/break inside finally blocks.

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

BugBearVisitor.__checkForM513_M514_M529_M530

__checkForM513_M514_M529_M530(node)

Private method to check various exception handler situations.

node (ast.ExceptHandler)
reference to the node to be processed
Return:
list of exception handler names
Return Type:
list of str

BugBearVisitor.__checkForM515

__checkForM515(node)

Private method to check for pointless comparisons.

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

BugBearVisitor.__checkForM516

__checkForM516(node)

Private method to check for raising a literal instead of an exception.

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

BugBearVisitor.__checkForM517

__checkForM517(node)

Private method to check for use of the evil syntax 'with assertRaises(Exception): or 'with pytest.raises(Exception):'.

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

BugBearVisitor.__checkForM518

__checkForM518(node)

Private method to check for useless expressions.

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

BugBearVisitor.__checkForM519

__checkForM519(node)

Private method to check for use of 'functools.lru_cache' or 'functools.cache'.

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

BugBearVisitor.__checkForM520

__checkForM520(node)

Private method to check for a loop that modifies its iterable.

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

BugBearVisitor.__checkForM521

__checkForM521(node)

Private method to check for use of an f-string as docstring.

node (ast.FunctionDef or ast.ClassDef)
reference to the node to be processed

BugBearVisitor.__checkForM522

__checkForM522(node)

Private method to check for use of an f-string as docstring.

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

BugBearVisitor.__checkForM523

__checkForM523(loopNode)

Private method to check that functions (including lambdas) do not use loop variables.

loopNode (ast.For, ast.AsyncFor, ast.While, ast.ListComp, ast.SetComp,ast.DictComp,)
reference to the node to be processed or ast.GeneratorExp

BugBearVisitor.__checkForM524_M527

__checkForM524_M527(node)

Private method to check for inheritance from abstract classes in abc and lack of any methods decorated with abstract*.

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

BugBearVisitor.__checkForM525

__checkForM525(node)

Private method to check for exceptions being handled multiple times.

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

BugBearVisitor.__checkForM526

__checkForM526(node)

Private method to check for Star-arg unpacking after keyword argument.

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

BugBearVisitor.__checkForM528

__checkForM528(node)

Private method to check for warn without stacklevel.

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

BugBearVisitor.__checkForM531

__checkForM531(loopNode)

Private method to check that 'itertools.groupby' isn't iterated over more than once.

A warning is emitted when the generator returned by 'groupby()' is used more than once inside a loop body or when it's used in a nested loop.

loopNode (ast.For or ast.AsyncFor)
reference to the node to be processed

BugBearVisitor.__checkForM532

__checkForM532(node)

Private method to check for possible unintentional typing annotation.

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

BugBearVisitor.__checkForM533

__checkForM533(node)

Private method to check a set for duplicate items.

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

BugBearVisitor.__checkForM534

__checkForM534(node)

Private method to check that re.sub/subn/split arguments flags/count/maxsplit are passed as keyword arguments.

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

BugBearVisitor.__checkForM535

__checkForM535(node)

Private method to check that a static key isn't used in a dict comprehension.

Record a warning if a likely unchanging key is used - either a constant, or a variable that isn't coming from the generator expression.

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

BugBearVisitor.__checkForM539

__checkForM539(node)

Private method to check for correct ContextVar usage.

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

BugBearVisitor.__checkForM540AddNote

__checkForM540AddNote(node)

Private method to check add_note usage.

node (ast.Attribute)
reference to the node to be processed
Return:
flag
Return Type:
bool

BugBearVisitor.__checkForM540Usage

__checkForM540Usage(node)

Private method to check the usage of exceptions with added note.

node (ast.expr or None)
reference to the node to be processed

BugBearVisitor.__checkForM541

__checkForM541(node)

Private method to check for duplicate key value pairs in a dictionary literal.

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

BugBearVisitor.__checkForM569

__checkForM569(node)

Private method to check for changes to a loop's mutable iterable.

node (ast.For)
loop node to be checked

BugBearVisitor.__checkRedundantExcepthandlers

__checkRedundantExcepthandlers(names, node, inTryStar)

Private method to check for redundant exception types in an exception handler.

names (list of ast.Name)
list of exception types to be checked
node (ast.ExceptionHandler)
reference to the exception handler node
inTryStar (str)
character indicating an 'except*' handler
Return:
tuple containing the error data
Return Type:
tuple of (ast.Node, str, str, str, str)

BugBearVisitor.__childrenInScope

__childrenInScope(node)

Private method to get all child nodes in the given scope.

node (ast.Node)
reference to the node to be processed
Yield:
reference to a child node
Yield Type:
ast.Node

BugBearVisitor.__flattenExcepthandler

__flattenExcepthandler(node)

Private method to flatten the list of exceptions handled by an except handler.

node (ast.Node)
reference to the node to be processed
Yield:
reference to the exception type node
Yield Type:
ast.Node

BugBearVisitor.__getAssignedNames

__getAssignedNames(loopNode)

Private method to get the names of a for loop.

loopNode (ast.For)
reference to the node to be processed
Yield:
DESCRIPTION
Yield Type:
TYPE

BugBearVisitor.__getDictCompLoopAndNamedExprVarNames

__getDictCompLoopAndNamedExprVarNames(node)

Private method to get the names of comprehension loop variables.

node (ast.DictComp)
ast node to be processed
Yield:
loop variable names
Yield Type:
str

BugBearVisitor.__getNamesFromTuple

__getNamesFromTuple(node)

Private method to get the names from an ast.Tuple node.

node (ast.Tuple)
ast node to be processed
Yield:
names
Yield Type:
str

BugBearVisitor.__inClassInit

__inClassInit()

Private method to check, if we are inside an '__init__' method.

Return:
flag indicating being within the '__init__' method
Return Type:
bool

BugBearVisitor.__isIdentifier

__isIdentifier(arg)

Private method to check if arg is a valid identifier.

See https://docs.python.org/2/reference/lexical_analysis.html#identifiers

arg (ast.Node)
reference to an argument node
Return:
flag indicating a valid identifier
Return Type:
TYPE

BugBearVisitor.__namesFromAssignments

__namesFromAssignments(assignTarget)

Private method to get names of an assignment.

assignTarget (ast.Node)
reference to the node to be processed
Yield:
name of the assignment
Yield Type:
str

BugBearVisitor.__typesafeIssubclass

__typesafeIssubclass(obj, classOrTuple)

Private method implementing a type safe issubclass() function.

obj (Any)
reference to the object to be tested
classOrTuple (type)
type to check against
Return:
flag indicating a subclass
Return Type:
bool

BugBearVisitor.__walkList

__walkList(nodes)

Private method to walk a given list of nodes.

nodes (list of ast.Node)
list of nodes to walk
Yield:
node references as determined by the ast.walk() function
Yield Type:
ast.Node

BugBearVisitor._loop

_loop(badNodeTypes)

BugBearVisitor.check

check(paramName)

BugBearVisitor.convertToValue

convertToValue()

Function to extract the value of a given item.

item (ast.Ast)
node to extract value from
Return:
value of the node
Return Type:
Any

BugBearVisitor.emptyBody

emptyBody()

BugBearVisitor.isAbcClass

isAbcClass(name="ABC")

BugBearVisitor.isAbstractDecorator

isAbstractDecorator()

BugBearVisitor.isOverload

isOverload()

BugBearVisitor.isStrOrEllipsis

isStrOrEllipsis()

BugBearVisitor.nodeStack

nodeStack()

Public method to get a reference to the most recent node stack.

Return:
reference to the most recent node stack
Return Type:
list

BugBearVisitor.superwalk

superwalk()

Function to walk an AST node or a list of AST nodes.

node (ast.AST or list[ast.AST])
reference to the node or a list of nodes to be processed
Yield:
next node to be processed
Yield Type:
ast.AST

BugBearVisitor.toNameStr

toNameStr(node)

Public method to turn Name and Attribute nodes to strings, handling any depth of attribute accesses.

node (ast.Name or ast.Attribute)
reference to the node
Return:
string representation
Return Type:
str

BugBearVisitor.visit

visit(node)

Public method to traverse a given AST node.

node (ast.Node)
AST node to be traversed

BugBearVisitor.visit_AnnAssign

visit_AnnAssign(node)

Public method to check annotated assign statements.

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

BugBearVisitor.visit_Assert

visit_Assert(node)

Public method to handle 'assert' statements.

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

BugBearVisitor.visit_Assign

visit_Assign(node)

Public method to handle assignments.

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

BugBearVisitor.visit_AsyncFor

visit_AsyncFor(node)

Public method to handle 'for' statements.

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

BugBearVisitor.visit_AsyncFunctionDef

visit_AsyncFunctionDef(node)

Public method to handle async function definitions.

node (ast.AsyncFunctionDef)
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_ClassDef

visit_ClassDef(node)

Public method to handle class definitions.

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

BugBearVisitor.visit_Compare

visit_Compare(node)

Public method to handle comparison statements.

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

BugBearVisitor.visit_Dict

visit_Dict(node)

Public method to check a dictionary.

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

BugBearVisitor.visit_DictComp

visit_DictComp(node)

Public method to handle dictionary comprehensions.

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

BugBearVisitor.visit_ExceptHandler

visit_ExceptHandler(node)

Public method to handle exception handlers.

node (ast.ExceptHandler)
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_FunctionDef

visit_FunctionDef(node)

Public method to handle function definitions.

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

BugBearVisitor.visit_GeneratorExp

visit_GeneratorExp(node)

Public method to handle generator expressions.

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

BugBearVisitor.visit_Import

visit_Import(node)

Public method to check imports.

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

BugBearVisitor.visit_ImportFrom

visit_ImportFrom(node)

Public method to check from imports.

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

BugBearVisitor.visit_JoinedStr

visit_JoinedStr(node)

Public method to handle f-string arguments.

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

BugBearVisitor.visit_ListComp

visit_ListComp(node)

Public method to handle list comprehensions.

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

BugBearVisitor.visit_Module

visit_Module(node)

Public method to handle a module node.

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

BugBearVisitor.visit_Raise

visit_Raise(node)

Public method to handle 'raise' statements.

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

BugBearVisitor.visit_Return

visit_Return(node)

Public method to handle 'Return' nodes.

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

BugBearVisitor.visit_Set

visit_Set(node)

Public method to check a set.

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

BugBearVisitor.visit_SetComp

visit_SetComp(node)

Public method to handle set comprehensions.

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

BugBearVisitor.visit_Try

visit_Try(node)

Public method to handle 'try' statements.

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

BugBearVisitor.visit_TryStar

visit_TryStar(node)

Public method to handle 'except*' statements.

node (ast.TryStar)
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

BugBearVisitor.visit_While

visit_While(node)

Public method to handle 'while' statements.

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

BugBearVisitor.visit_With

visit_With(node)

Public method to handle 'with' statements.

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

BugBearVisitor.visit_Yield

visit_Yield(node)

Public method to handle 'Yield' nodes.

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

BugBearVisitor.visit_YieldFrom

visit_YieldFrom(node)

Public method to handle 'YieldFrom' nodes.

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


ExceptBaseExceptionVisitor

Class to determine, if a 'BaseException' is re-raised.

Derived from

ast.NodeVisitor

Class Attributes

None

Class Methods

None

Methods

ExceptBaseExceptionVisitor Constructor
reRaised Public method to check, if the exception is re-raised.
visit_ExceptHandler Public method to handle 'ExceptHandler' nodes.
visit_Raise Public method to handle 'Raise' nodes.

Static Methods

None

ExceptBaseExceptionVisitor (Constructor)

ExceptBaseExceptionVisitor(exceptNode)

Constructor

exceptNode (ast.ExceptHandler)
exception node to be inspected

ExceptBaseExceptionVisitor.reRaised

reRaised()

Public method to check, if the exception is re-raised.

Return:
flag indicating a re-raised exception
Return Type:
bool

ExceptBaseExceptionVisitor.visit_ExceptHandler

visit_ExceptHandler(node: ast.ExceptHandler)

Public method to handle 'ExceptHandler' nodes.

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

ExceptBaseExceptionVisitor.visit_Raise

visit_Raise(node)

Public method to handle 'Raise' nodes.

If we find a corresponding `raise` or `raise e` where e was from `except BaseException as e:` then we mark re_raised as True and can stop scanning.

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


FunctionDefDefaultsVisitor

Class used by M506, M508 and M539.

Derived from

ast.NodeVisitor

Class Attributes

None

Class Methods

None

Methods

FunctionDefDefaultsVisitor Constructor
__visitMutableLiteralOrComprehension Private method to flag mutable literals and comprehensions.
visit Public method to traverse an AST node or a list of AST nodes.
visit_Call Public method to process Call nodes.
visit_Lambda Public method to process Lambda nodes.

Static Methods

None

FunctionDefDefaultsVisitor (Constructor)

FunctionDefDefaultsVisitor(errorCodeCalls, errorCodeLiterals, )

Constructor

errorCodeCalls (str)
error code for ast.Call nodes
errorCodeLiterals (str)
error code for literal nodes

FunctionDefDefaultsVisitor.__visitMutableLiteralOrComprehension

__visitMutableLiteralOrComprehension(node)

Private method to flag mutable literals and comprehensions.

node (ast.Dict, ast.List, ast.Set, ast.ListComp, ast.DictComp or ast.SetComp)
AST node to be processed

FunctionDefDefaultsVisitor.visit

visit(node)

Public method to traverse an AST node or a list of AST nodes.

This is an extended method that can also handle a list of AST nodes.

node (ast.AST or list of ast.AST)
AST node or list of AST nodes to be processed

FunctionDefDefaultsVisitor.visit_Call

visit_Call(node)

Public method to process Call nodes.

node (ast.Call)
AST node to be processed

FunctionDefDefaultsVisitor.visit_Lambda

visit_Lambda(node)

Public method to process Lambda nodes.

node (ast.Lambda)
AST node to be processed
Up


M520NameFinder

Class to extract a name out of a tree of nodes ignoring names defined within the local scope of a comprehension.

Derived from

NameFinder

Class Attributes

None

Class Methods

None

Methods

visit_DictComp Public method to handle a dictionary comprehension.
visit_GeneratorExp Public method to handle a generator expressions.
visit_Lambda Public method to handle a Lambda function.
visit_ListComp Public method to handle a list comprehension.
visit_comprehension Public method to handle the 'for' of a comprehension.

Static Methods

None

M520NameFinder.visit_DictComp

visit_DictComp(node)

Public method to handle a dictionary comprehension.

node (TYPE)
reference to the node to be processed

M520NameFinder.visit_GeneratorExp

visit_GeneratorExp(node)

Public method to handle a generator expressions.

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

M520NameFinder.visit_Lambda

visit_Lambda(node)

Public method to handle a Lambda function.

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

M520NameFinder.visit_ListComp

visit_ListComp(node)

Public method to handle a list comprehension.

node (TYPE)
reference to the node to be processed

M520NameFinder.visit_comprehension

visit_comprehension(node)

Public method to handle the 'for' of a comprehension.

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


M540CaughtException

Class to hold the data for a caught exception.

Derived from

None

Class Attributes

hasNote
name

Class Methods

None

Methods

None

Static Methods

None
Up


M541UnhandledKeyType

Class to hold a dictionary key of a type that we do not check for duplicates.

Derived from

None

Class Attributes

None

Class Methods

None

Methods

None

Static Methods

None
Up


M541VariableKeyType

Class to hold the name of a variable key type.

Derived from

None

Class Attributes

None

Class Methods

None

Methods

M541VariableKeyType Constructor

Static Methods

None

M541VariableKeyType (Constructor)

M541VariableKeyType(name)

Constructor

name (str)
name of the variable key type
Up


M569Checker

Class traversing a 'for' loop body to check for modifications to a loop's mutable iterable.

Derived from

ast.NodeVisitor

Class Attributes

MUTATING_FUNCTIONS

Class Methods

None

Methods

M569Checker Constructor
visit Public method to inspect an ast node.
visit_Call Public method handling 'Call' nodes.
visit_Delete Public method handling 'Delete' nodes.

Static Methods

None

M569Checker (Constructor)

M569Checker(name, bugbear)

Constructor

name (str)
name of the iterator
bugbear (BugBearVisitor)
reference to the bugbear visitor

M569Checker.visit

visit(node)

Public method to inspect an ast node.

Like super-visit but supports iteration over lists.

node (TYPE)
AST node to be traversed
Return:
reference to the last processed node
Return Type:
ast.Node

M569Checker.visit_Call

visit_Call(node)

Public method handling 'Call' nodes.

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

M569Checker.visit_Delete

visit_Delete(node)

Public method handling 'Delete' nodes.

node (ast.Delete)
reference to the node to be processed
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.

Return:
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
Return:
reference to the last processed node
Return Type:
ast.Node

NameFinder.visit_Name

visit_Name(node)

Public method to handle 'Name' nodes.

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


NamedExprFinder

Class to extract names defined through an ast.NamedExpr.

Derived from

ast.NodeVisitor

Class Attributes

None

Class Methods

None

Methods

NamedExprFinder Constructor
getNames Public method to return the extracted names and Name nodes.
visit Public method to traverse a given AST node.
visit_NamedExpr Public method handling 'NamedExpr' nodes.

Static Methods

None

NamedExprFinder (Constructor)

NamedExprFinder()

Constructor

NamedExprFinder.getNames

getNames()

Public method to return the extracted names and Name nodes.

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

NamedExprFinder.visit

visit(node)

Public method to traverse a given AST node.

Like super-visit but supports iteration over lists.

node (TYPE)
AST node to be traversed
Return:
reference to the last processed node
Return Type:
ast.Node

NamedExprFinder.visit_NamedExpr

visit_NamedExpr(node: ast.NamedExpr)

Public method handling 'NamedExpr' nodes.

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


composeCallPath

composeCallPath(node)

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

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