Module implementing a visitor to check for various potential issues.
BugBearContext |
BugbearImmutableCalls |
BugbearMutableCalls |
BugbearMutableComprehensions |
BugbearMutableLiterals |
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. |
composeCallPath | Generator function to assemble the call path of a given node. |
Class implementing a node visitor to check for various topics.
CONTEXTFUL_NODES |
FUNCTION_NODES |
NodeWindowSize |
None |
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. |
None |
Constructor
Private method to check the use of *strip().
Private method to check the use of mutable literals, comprehensions and calls.
Private method to check for unused loop variables.
Private method to check for return/continue/break inside finally blocks.
Private method to check various exception handler situations.
Private method to check for pointless comparisons.
Private method to check for raising a literal instead of an exception.
Private method to check for use of the evil syntax 'with assertRaises(Exception): or 'with pytest.raises(Exception):'.
Private method to check for useless expressions.
Private method to check for use of 'functools.lru_cache' or 'functools.cache'.
Private method to check for a loop that modifies its iterable.
Private method to check for use of an f-string as docstring.
Private method to check for use of an f-string as docstring.
Private method to check that functions (including lambdas) do not use loop variables.
Private method to check for inheritance from abstract classes in abc and lack of any methods decorated with abstract*.
Private method to check for exceptions being handled multiple times.
Private method to check for Star-arg unpacking after keyword argument.
Private method to check for warn without stacklevel.
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.
Private method to check for possible unintentional typing annotation.
Private method to check a set for duplicate items.
Private method to check that re.sub/subn/split arguments flags/count/maxsplit are passed as keyword arguments.
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.
Private method to check for correct ContextVar usage.
Private method to check add_note usage.
Private method to check the usage of exceptions with added note.
Private method to check for duplicate key value pairs in a dictionary literal.
Private method to check for changes to a loop's mutable iterable.
Private method to check for redundant exception types in an exception handler.
Private method to get all child nodes in the given scope.
Private method to flatten the list of exceptions handled by an except handler.
Private method to get the names of a for loop.
Private method to get the names of comprehension loop variables.
Private method to get the names from an ast.Tuple node.
Private method to check, if we are inside an '__init__' method.
Private method to check if arg is a valid identifier.
See https://docs.python.org/2/reference/lexical_analysis.html#identifiers
Private method to get names of an assignment.
Private method implementing a type safe issubclass() function.
Private method to walk a given list of nodes.
Function to extract the value of a given item.
Public method to get a reference to the most recent node stack.
Function to walk an AST node or a list of AST nodes.
Public method to turn Name and Attribute nodes to strings, handling any depth of attribute accesses.
Public method to traverse a given AST node.
Public method to check annotated assign statements.
Public method to handle 'assert' statements.
Public method to handle assignments.
Public method to handle 'for' statements.
Public method to handle async function definitions.
Public method to handle a function call.
Public method to handle class definitions.
Public method to handle comparison statements.
Public method to check a dictionary.
Public method to handle dictionary comprehensions.
Public method to handle exception handlers.
Public method to handle 'for' statements.
Public method to handle function definitions.
Public method to handle generator expressions.
Public method to check imports.
Public method to check from imports.
Public method to handle f-string arguments.
Public method to handle list comprehensions.
Public method to handle a module node.
Public method to handle 'raise' statements.
Public method to handle 'Return' nodes.
Public method to check a set.
Public method to handle set comprehensions.
Public method to handle 'try' statements.
Public method to handle 'except*' statements.
Public method to handle unary additions.
Public method to handle 'while' statements.
Public method to handle 'with' statements.
Public method to handle 'Yield' nodes.
Public method to handle 'YieldFrom' nodes.
Class to determine, if a 'BaseException' is re-raised.
None |
None |
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. |
None |
Constructor
Public method to check, if the exception is re-raised.
Public method to handle 'ExceptHandler' nodes.
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.
Class used by M506, M508 and M539.
None |
None |
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. |
None |
Constructor
Private method to flag mutable literals and comprehensions.
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.
Public method to process Call nodes.
Public method to process Lambda nodes.
Class to extract a name out of a tree of nodes ignoring names defined within the local scope of a comprehension.
None |
None |
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. |
None |
Public method to handle a dictionary comprehension.
Public method to handle a generator expressions.
Public method to handle a Lambda function.
Public method to handle a list comprehension.
Public method to handle the 'for' of a comprehension.
Class to hold the data for a caught exception.
hasNote |
name |
None |
None |
None |
Class to hold a dictionary key of a type that we do not check for duplicates.
None |
None |
None |
None |
Class to hold the name of a variable key type.
None |
None |
M541VariableKeyType | Constructor |
None |
Constructor
Class traversing a 'for' loop body to check for modifications to a loop's mutable iterable.
MUTATING_FUNCTIONS |
None |
M569Checker | Constructor |
visit | Public method to inspect an ast node. |
visit_Call | Public method handling 'Call' nodes. |
visit_Delete | Public method handling 'Delete' nodes. |
None |
Constructor
Public method to inspect an ast node.
Like super-visit but supports iteration over lists.
Public method handling 'Call' nodes.
Public method handling 'Delete' nodes.
Class to extract a name out of a tree of nodes.
None |
None |
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. |
None |
Constructor
Public method to return the extracted names and Name nodes.
Public method to traverse a given AST node.
Public method to handle 'Name' nodes.
Class to extract names defined through an ast.NamedExpr.
None |
None |
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. |
None |
Constructor
Public method to return the extracted names and Name nodes.
Public method to traverse a given AST node.
Like super-visit but supports iteration over lists.
Public method handling 'NamedExpr' nodes.
Generator function to assemble the call path of a given node.