class VariablesChecker(BaseChecker): (source)
BaseChecker for variables. Checks for * unused variables / imports * undefined variables * redefinition of variable from builtins or from an outer scope or except handler * use of variable before assignment * __all__ consistency * self/cls assignment
Method | __init__ |
Checker instances should have the linter as argument. |
Method | leave |
Undocumented |
Method | leave |
Leave class: update consumption analysis variable. |
Method | leave |
Leave dictcomp: update consumption analysis variable. |
Method | leave |
Undocumented |
Method | leave |
Undocumented |
Method | leave |
Leave function: check function's locals are consumed. |
Method | leave |
Leave genexpr: update consumption analysis variable. |
Method | leave |
Leave lambda: update consumption analysis variable. |
Method | leave |
Leave listcomp: update consumption analysis variable. |
Method | leave |
Leave module: check globals. |
Method | leave |
Leave setcomp: update consumption analysis variable. |
Method | leave |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Check unbalanced tuple unpacking for assignments and unpacking non-sequences as well as in case self/cls get assigned. |
Method | visit |
Undocumented |
Method | visit |
Visit class: update consumption analysis variable. |
Method | visit |
Take note of names that appear inside string literal type annotations unless the string is a parameter to `typing.Literal` or `typing.Annotation`. |
Method | visit |
Undocumented |
Method | visit |
Visit dictcomp: update consumption analysis variable. |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Visit function: update consumption analysis variable and check locals. |
Method | visit |
Visit genexpr: update consumption analysis variable. |
Method | visit |
Check names imported exists in the global scope. |
Method | visit |
Check modules attribute accesses. |
Method | visit |
Check modules attribute accesses. |
Method | visit |
Visit lambda: update consumption analysis variable. |
Method | visit |
Visit listcomp: update consumption analysis variable. |
Method | visit |
Visit module : update consumption analysis variable checks globals doesn't overrides builtins. |
Method | visit |
Don't add the 'utils.only_required_for_messages' decorator here! |
Method | visit |
Visit setcomp: update consumption analysis variable. |
Method | visit |
Undocumented |
Class Variable | name |
Name of the provider. |
Class Variable | options |
Options provided by this provider. |
Static Method | _comprehension |
Return True if a ComprehensionScope intervenes between `node` and its frame. |
Static Method | _defined |
Undocumented |
Static Method | _in |
Return True if node within a lambda/comprehension body (or similar) and thus should not have access to class attributes in frame. |
Static Method | _is |
Check if a first level method's annotation or default values refers to its own class, and return a consumer action. |
Static Method | _is |
Check if a NamedExpr is inside a side of if ... else that never gets evaluated. |
Static Method | _is |
Undocumented |
Static Method | _maybe |
Check if `defstmt` has the potential to use and assign a name in the same statement. |
Static Method | _nodes |
Return the list of values of the `Assign` node. |
Method | _allowed |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Checks a consumer for conditions that should trigger messages. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Check whether node is a cell var that is assigned within a containing loop. |
Method | _check |
Update consumption analysis for metaclasses. |
Method | _check |
Check that module_names (list of string) are accessible through the given module, if the latest access name corresponds to a module, return it. |
Method | _check |
Check for the potential-index-error message. |
Method | _check |
Check that self/cls don't get assigned. |
Method | _check |
Check for unbalanced tuple unpacking and unpacking non sequences. |
Method | _check |
Undocumented |
Method | _ignore |
Return True if the node is in a local class scope, as an assignment. |
Method | _is |
Undocumented |
Method | _is |
Check if variable only gets assigned a type and never a value. |
Method | _loopvar |
Undocumented |
Method | _report |
Undocumented |
Method | _report |
Undocumented |
Method | _should |
Undocumented |
Method | _should |
Tests a consumer and node for various conditions in which the node shouldn't be checked for the undefined-variable and used-before-assignment checks. |
Method | _store |
Undocumented |
Method | _store |
Given a type annotation, store all the name nodes it refers to. |
Method | _undefined |
Undocumented |
Instance Variable | _except |
This is a queue, last in first out. |
Instance Variable | _postponed |
Undocumented |
Instance Variable | _to |
Undocumented |
Instance Variable | _type |
Undocumented |
Property | _allow |
Undocumented |
Property | _analyse |
Undocumented |
Property | _ignored |
Undocumented |
Inherited from BaseChecker
:
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 | open |
Called before visiting project (i.e. set of modules). |
Method | reduce |
Undocumented |
Class Variable | enabled |
Undocumented |
Class Variable | msgs |
Undocumented |
Class Variable | reports |
Undocumented |
Instance Variable | linter |
Undocumented |
Property | messages |
Undocumented |
Inherited from _ArgumentsProvider
(via 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_excepthandler(self, node:
nodes.ExceptHandler
):
(source)
¶
Undocumented
def leave_module(self, node:
nodes.Module
):
(source)
¶
Leave module: check globals.
def visit_assign(self, node:
nodes.Assign
):
(source)
¶
Check unbalanced tuple unpacking for assignments and unpacking non-sequences as well as in case self/cls get assigned.
def visit_const(self, node:
nodes.Const
):
(source)
¶
Take note of names that appear inside string literal type annotations unless the string is a parameter to `typing.Literal` or `typing.Annotation`.
def visit_excepthandler(self, node:
nodes.ExceptHandler
):
(source)
¶
Undocumented
def visit_for(self, node:
nodes.For
):
(source)
¶
Undocumented
def visit_global(self, node:
nodes.Global
):
(source)
¶
Check names imported exists in the global scope.
def visit_import(self, node:
nodes.Import
):
(source)
¶
Check modules attribute accesses.
def visit_importfrom(self, node:
nodes.ImportFrom
):
(source)
¶
Check modules attribute accesses.
Don't add the 'utils.only_required_for_messages' decorator here! It's important that all 'Name' nodes are visited, otherwise the 'NamesConsumers' won't be correct.
def _defined_in_function_definition(node:
nodes.NodeNG
, frame: nodes.NodeNG
) -> bool
:
(source)
¶
Undocumented
def _in_lambda_or_comprehension_body(node:
nodes.NodeNG
, frame: nodes.NodeNG
) -> bool
:
(source)
¶
Return True if node within a lambda/comprehension body (or similar) and thus should not have access to class attributes in frame.
def _is_first_level_self_reference(node:
nodes.Name
, defstmt: nodes.ClassDef
, found_nodes: list[ nodes.NodeNG]
) -> tuple[ VariableVisitConsumerAction, list[ nodes.NodeNG]|None]
:
(source)
¶
Check if a first level method's annotation or default values refers to its own class, and return a consumer action.
def _is_never_evaluated(defnode:
nodes.NamedExpr
, defnode_parent: nodes.IfExp
) -> bool
:
(source)
¶
Check if a NamedExpr is inside a side of if ... else that never gets evaluated.
def _is_variable_violation(node:
nodes.Name
, defnode: nodes.NodeNG
, stmt: nodes.Statement
, defstmt: nodes.Statement
, frame: nodes.LocalsDictNodeNG
, defframe: nodes.LocalsDictNodeNG
, base_scope_type: str
, is_recursive_klass: bool
) -> tuple[ bool, bool, bool]
:
(source)
¶
Undocumented
nodes.ClassDef
, parent_node: nodes.Module|nodes.FunctionDef
) -> list[ tuple[ dict[ str, list[ nodes.NodeNG]], str]]
:
(source)
¶
Undocumented
nodes.Name
, stmt: nodes.NodeNG
, frame: nodes.LocalsDictNodeNG
, current_consumer: NamesConsumer
, base_scope_type: str
) -> tuple[ VariableVisitConsumerAction, list[ nodes.NodeNG]|None]
:
(source)
¶
Checks a consumer for conditions that should trigger messages.
str
, node: nodes.FunctionDef
, stmt: nodes.NodeNG
, global_names: set[ str]
, nonlocal_names: Iterable[ str]
, comprehension_target_names: Iterable[ str]
):
(source)
¶
Undocumented
Check whether node is a cell var that is assigned within a containing loop. Special cases where we don't care about the error: 1. When the node's function is immediately called, e.g. (lambda: i)() 2. When the node's function is returned from within the loop, e.g. return lambda: i
_base_nodes.ImportNode
, module: nodes.Module
, module_names: list[ str]
) -> nodes.Module|None
:
(source)
¶
Check that module_names (list of string) are accessible through the given module, if the latest access name corresponds to a module, return it.
nodes.Subscript
, inferred_slice: nodes.NodeNG|None
):
(source)
¶
Check for the potential-index-error message.
InferenceResult
, node: nodes.Assign
, targets: list[ nodes.NodeNG]
):
(source)
¶
Check for unbalanced tuple unpacking and unpacking non sequences.
str
, node: nodes.FunctionDef
, stmt: nodes.NodeNG
, argnames: list[ str]
, nonlocal_names: Iterable[ str]
):
(source)
¶
Undocumented
Return True if the node is in a local class scope, as an assignment. Detect if we are in a local class scope, as an assignment. For example, the following is fair game. class A: b = 1 c = lambda b=b: b * b class B: tp = 1 def func(self, arg: tp): ... class C: tp = 2 def func(self, arg=tp): ... class C: class Tp: pass class D(Tp): ...
nodes.NodeNG
, name: str
) -> (re.Pattern[ str]|re.Match[ str])|None
:
(source)
¶
Undocumented
nodes.NodeNG
, inferred: InferenceResult
, targets: list[ nodes.NodeNG]
, values: list[ nodes.NodeNG]
, details: str
):
(source)
¶
Undocumented
nodes.Name
, consumer: NamesConsumer
, is_start_index: bool
) -> bool
:
(source)
¶
Tests a consumer and node for various conditions in which the node shouldn't be checked for the undefined-variable and used-before-assignment checks.