class RefactoringChecker(checkers.BaseTokenChecker): (source)
Looks for code which can be refactored. This checker also mixes the astroid and the token approaches in order to create knowledge about whether an "else if" node is a true "else if" node, or an "elif" node.
Method | __init__ |
Checker instances should have the linter as argument. |
Method | leave |
Undocumented |
Method | leave |
Undocumented |
Method | leave |
Undocumented |
Method | open |
Called before visiting project (i.e. set of modules). |
Method | process |
Should be overridden by subclasses. |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Class Variable | msgs |
Undocumented |
Class Variable | name |
Name of the provider. |
Class Variable | options |
Options provided by this provider. |
Static Method | _and |
Undocumented |
Static Method | _apply |
Removes irrelevant values or returns short-circuiting values. |
Static Method | _check |
Return True if the exception node in argument inherit from StopIteration. |
Static Method | _dict |
Return a suggestion of reasonable length. |
Static Method | _duplicated |
Get the duplicated types from the underlying isinstance calls. |
Static Method | _has |
Undocumented |
Static Method | _has |
Returns True if there is at least one return in the node's siblings. |
Static Method | _is |
Returns true if node is 'condition and true_value or false_value' form. |
Static Method | _is |
Undocumented |
Static Method | _is |
Undocumented |
Static Method | _name |
Try to extract the name used in a concatenation loop. |
Static Method | _type |
Undocumented |
Method | _append |
Undocumented |
Method | _check |
Check if there is any chained comparison in the expression. |
Method | _check |
Undocumented |
Method | _check |
Check isinstance calls which can be merged together. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
We start with the augmented assignment and work our way upwards. |
Method | _check |
Check if the given if node can be refactored as a min/max python builtin. |
Method | _check |
Undocumented |
Method | _check |
Check that all return statements inside a function are consistent. |
Method | _check |
Update and check the number of nested blocks. |
Method | _check |
Undocumented |
Method | _check |
Check if a StopIteration exception is raised by the call to next function. |
Method | _check |
Undocumented |
Method | _check |
Check for presence of a *single* return statement at the end of a function. |
Method | _check |
Check if a boolean condition can be simplified. |
Method | _check |
Check if the given if node can be simplified. |
Method | _check |
Undocumented |
Method | _check |
Check if an exception of type StopIteration is raised inside a generator. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Add message when accessing dict values by index lookup. |
Method | _check |
Undocumented |
Method | _check |
Check if dict is created by using the literal {}. |
Method | _check |
Check if empty list is created by using the literal []. |
Method | _emit |
Undocumented |
Method | _emit |
Undocumented |
Method | _enumerate |
Check presence of `start` kwarg or second argument to enumerate. |
Method | _get |
Undocumented |
Method | _init |
Undocumented |
Method | _is |
Check if the given node is an actual elif. |
Method | _is |
Undocumented |
Method | _is |
Return True if the function never returns, False otherwise. |
Method | _is |
Check if the If node ends with an explicit return statement. |
Method | _is |
Check if the node ends with an explicit return statement. |
Method | _is |
Check if the Raise node ends with an explicit return statement. |
Method | _simplify |
Attempts to simplify a boolean operation. |
Instance Variable | _can |
Undocumented |
Instance Variable | _consider |
Undocumented |
Instance Variable | _elifs |
Undocumented |
Instance Variable | _nested |
Undocumented |
Instance Variable | _never |
Undocumented |
Instance Variable | _reported |
Undocumented |
Instance Variable | _return |
Undocumented |
Property | _dummy |
Undocumented |
Inherited from BaseChecker
(via BaseTokenChecker
):
Method | __eq__ |
Permit to assert Checkers are equal. |
Method | __gt__ |
Sorting of checkers. |
Method | __hash__ |
Make Checker hashable. |
Method | __repr__ |
Undocumented |
Method | __str__ |
This might be incomplete because multiple classes inheriting BaseChecker can have the same name. |
Method | add |
Undocumented |
Method | check |
Check the consistency of msgid. |
Method | close |
Called after visiting project (i.e set of modules). |
Method | create |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | reduce |
Undocumented |
Class Variable | enabled |
Undocumented |
Class Variable | reports |
Undocumented |
Instance Variable | linter |
Undocumented |
Property | messages |
Undocumented |
Inherited from _ArgumentsProvider
(via BaseTokenChecker
, BaseChecker
):
Method | get |
DEPRECATED: Return the dictionary defining an option given its name. |
Method | level |
Undocumented |
Method | load |
DEPRECATED: Initialize the provider using default values. |
Method | option |
DEPRECATED: Get the config attribute corresponding to opt. |
Method | option |
DEPRECATED: Get the current value for the given option. |
Method | options |
DEPRECATED. |
Method | options |
DEPRECATED: Return an iterator on options grouped by section. |
Method | set |
DEPRECATED: Method called to set an option (registered in the options list). |
Class Variable | option |
Option groups of this provider and their descriptions. |
Property | config |
Undocumented |
Property | level |
Undocumented |
Instance Variable | _arguments |
The manager that will parse and register any options provided. |
Instance Variable | _level |
Undocumented |
pylint.checkers.BaseChecker.__init__
Checker instances should have the linter as argument.
def leave_classdef(self, _:
nodes.ClassDef
):
(source)
¶
Undocumented
def leave_functiondef(self, node:
nodes.FunctionDef
):
(source)
¶
Undocumented
def leave_module(self, _:
nodes.Module
):
(source)
¶
Undocumented
def visit_assign(self, node:
nodes.Assign
):
(source)
¶
Undocumented
def visit_augassign(self, node:
nodes.AugAssign
):
(source)
¶
Undocumented
def visit_boolop(self, node:
nodes.BoolOp
):
(source)
¶
Undocumented
def visit_call(self, node:
nodes.Call
):
(source)
¶
Undocumented
def visit_comprehension(self, node:
nodes.Comprehension
):
(source)
¶
Undocumented
def visit_excepthandler(self, node:
nodes.ExceptHandler
):
(source)
¶
Undocumented
def visit_for(self, node:
nodes.For
):
(source)
¶
Undocumented
def visit_if(self, node:
nodes.If
):
(source)
¶
Undocumented
def visit_ifexp(self, node:
nodes.IfExp
):
(source)
¶
Undocumented
def visit_raise(self, node:
nodes.Raise
):
(source)
¶
Undocumented
def visit_return(self, node:
nodes.Return|nodes.Assign
):
(source)
¶
Undocumented
def visit_tryexcept(self, node:
nodes.TryExcept|nodes.TryFinally
):
(source)
¶
Undocumented
def visit_with(self, node:
nodes.With
):
(source)
¶
Undocumented
def _and_or_ternary_arguments(node:
nodes.BoolOp
) -> tuple[ nodes.NodeNG, nodes.NodeNG, nodes.NodeNG]
:
(source)
¶
Undocumented
def _apply_boolean_simplification_rules(operator:
str
, values: list[ nodes.NodeNG]
) -> list[ nodes.NodeNG]
:
(source)
¶
Removes irrelevant values or returns short-circuiting values. This function applies the following two rules: 1) an OR expression with True in it will always be true, and the reverse for AND 2) False values in OR expressions are only relevant if all values are false, and the reverse for AND
def _check_exception_inherit_from_stopiteration(exc:
nodes.ClassDef|bases.Instance
) -> bool
:
(source)
¶
Return True if the exception node in argument inherit from StopIteration.
def _duplicated_isinstance_types(node:
nodes.BoolOp
) -> dict[ str, set[ str]]
:
(source)
¶
Get the duplicated types from the underlying isinstance calls. :param nodes.BoolOp node: Node which should contain a bunch of isinstance calls. :returns: Dictionary of the comparison objects from the isinstance calls, to duplicate values from consecutive calls. :rtype: dict
Returns true if node is 'condition and true_value or false_value' form. All of: condition, true_value and false_value should not be a complex boolean expression
Check if there is any chained comparison in the expression. Add a refactoring message if a boolOp contains comparison like a < b and b < c, which can be chained as a < b < c. Care is taken to avoid simplifying a < b < c and b < d.
We start with the augmented assignment and work our way upwards. Names of variables for nodes if match successful: result = '' # assign for number in ['1', '2', '3'] # for_loop result += number # aug_assign
Check that all return statements inside a function are consistent. Return statements are consistent if: - all returns are explicit and if there is no implicit return; - all returns are empty and if there is, possibly, an implicit return. Args: node (nodes.FunctionDef): the function holding the return statements.
Check if a StopIteration exception is raised by the call to next function. If the next value has a default value, then do not add message. :param node: Check to see if this Call node is a next function :type node: :class:`nodes.Call`
Check for presence of a *single* return statement at the end of a function. "return" or "return None" are useless because None is the default return type if they are missing. NOTE: produces a message only if there is a single return statement in the function body. Otherwise _check_consistent_returns() is called! Per its implementation and PEP8 we can have a "return None" at the end of the function body if there are other return statements before that!
Check if a boolean condition can be simplified. Variables will not be simplified, even if the value can be inferred, and expressions like '3 + 4' will remain expanded.
Check if the given if node can be simplified. The if statement can be reduced to a boolean expression in some cases. For instance, if there are two branches and both of them return a boolean value that depends on the result of the statement's test, then this can be reduced to `bool(test)` without losing any functionality.
nodes.If|nodes.TryExcept
, msg_id: str
, returning_node_class: nodes.NodeNG
):
(source)
¶
Undocumented
list[ NodesWithNestedBlocks]
):
(source)
¶
Undocumented
nodes.For|nodes.Comprehension
) -> tuple[ bool, Confidence]
:
(source)
¶
Check presence of `start` kwarg or second argument to enumerate. For example: `enumerate([1,2,3], start=1)` `enumerate([1,2,3], 1)` If `start` is assigned to `0`, the default value, this is equivalent to not calling `enumerate` with start.
Check if the given node is an actual elif. This is a problem we're having with the builtin ast module, which splits `elif` branches into a separate if statement. Unfortunately we need to know the exact type in certain cases.
Return True if the function never returns, False otherwise. Args: node (nodes.FunctionDef): function definition node to be analyzed. Returns: bool: True if the function never returns, False otherwise.
Check if the If node ends with an explicit return statement. Args: node (nodes.If): If node to be checked. Returns: bool: True if the node ends with an explicit statement, False otherwise.
Check if the node ends with an explicit return statement. Args: node (nodes.NodeNG): node to be checked. Returns: bool: True if the node ends with an explicit statement, False otherwise.
Check if the Raise node ends with an explicit return statement. Args: node (nodes.Raise): Raise node to be checked. Returns: bool: True if the node ends with an explicit statement, False otherwise.