module documentation

Variables checkers for Python code.

Class NamesConsumer A simple class to handle consumed, to consume and scope type info of node locals.
Class ScopeConsumer Store nodes and their consumption states.
Class VariablesChecker BaseChecker for variables.
Class VariableVisitConsumerAction Reported by _check_consumer() and its sub-methods to determine the subsequent action to take in _undefined_and_used_before_checker().
Function overridden_method Get overridden method if any.
Function register Undocumented
Constant BUILTIN_RANGE Undocumented
Constant DICT_TYPES Undocumented
Constant FUTURE Undocumented
Constant IGNORED_ARGUMENT_NAMES Undocumented
Constant METACLASS_NAME_TRANSFORMS Undocumented
Constant MSGS Undocumented
Constant NODES_WITH_VALUE_ATTR Undocumented
Constant SPECIAL_OBJ Undocumented
Constant TYPING_MODULE Undocumented
Constant TYPING_NAMES Undocumented
Function _assigned_locally Checks if name_node has corresponding assign statement in same scope.
Function _detect_global_scope Detect that the given frames share a global scope.
Function _find_frame_imports Detect imports in the frame, with the required *name*.
Function _fix_dot_imports Try to fix imports with multiple dots, by returning a dictionary with the import names expanded.
Function _flattened_scope_names Undocumented
Function _get_unpacking_extra_info Return extra information to add to the message for unpacking-non-sequence and unbalanced-tuple/dict-unpacking errors.
Function _has_locals_call_after_node Undocumented
Function _import_name_is_global Undocumented
Function _infer_name_module Undocumented
Function _is_from_future_import Check if the name is a future import from another module.
@lru_cache(maxsize=1000)
def overridden_method(klass: nodes.LocalsDictNodeNG, name: str|None) -> nodes.FunctionDef|None: (source)

Get overridden method if any.

def register(linter: PyLinter): (source)

Undocumented

BUILTIN_RANGE: str = (source)

Undocumented

Value
'builtins.range'
DICT_TYPES = (source)

Undocumented

Value
(astroid.objects.DictValues,
 astroid.objects.DictKeys,
 astroid.objects.DictItems,
 astroid.nodes.node_classes.Dict)

Undocumented

Value
'__future__'
IGNORED_ARGUMENT_NAMES = (source)

Undocumented

Value
re.compile(r'_.*|^ignored_|^unused_')
METACLASS_NAME_TRANSFORMS: dict[str, str] = (source)

Undocumented

Value
{'_py_abc': 'abc'}

Undocumented

Value
{'E0601': ('Using variable %r before assignment',
           'used-before-assignment',
           'Emitted when a local variable is accessed before its assignment took
 place. Assignments in try blocks are assumed not to have occurred when evaluati
ng associated except/finally blocks. Assignments in except blocks are assumed no
t to have occurred when evaluating statements outside the block, except when the
 associated try block contains a return statement.'),
...
SPECIAL_OBJ = (source)

Undocumented

Value
re.compile(r'^_{2}[a-z]+_{2}$')
TYPING_MODULE: str = (source)

Undocumented

Value
'typing'
TYPING_NAMES = (source)

Undocumented

Value
frozenset(set(['Any',
               'Callable',
               'ClassVar',
               'Generic',
               'Optional',
               'Tuple',
               'Type',
...
def _assigned_locally(name_node: nodes.Name) -> bool: (source)

Checks if name_node has corresponding assign statement in same scope.

def _detect_global_scope(node: nodes.Name, frame: nodes.LocalsDictNodeNG, defframe: nodes.LocalsDictNodeNG) -> bool: (source)

Detect that the given frames share a global scope. Two frames share a global scope when neither of them are hidden under a function scope, as well as any parent scope of them, until the root scope. In this case, depending from something defined later on will only work if guarded by a nested function definition. Example: class A: # B has the same global scope as `C`, leading to a NameError. # Return True to indicate a shared scope. class B(C): ... class C: ... Whereas this does not lead to a NameError: class A: def guard(): # Return False to indicate no scope sharing. class B(C): ... class C: ...

def _find_frame_imports(name: str, frame: nodes.LocalsDictNodeNG) -> bool: (source)

Detect imports in the frame, with the required *name*. Such imports can be considered assignments if they are not globals. Returns True if an import for the given name was found.

def _fix_dot_imports(not_consumed: dict[str, list[nodes.NodeNG]]) -> list[tuple[str, _base_nodes.ImportNode]]: (source)

Try to fix imports with multiple dots, by returning a dictionary with the import names expanded. The function unflattens root imports, like 'xml' (when we have both 'xml.etree' and 'xml.sax'), to 'xml.etree' and 'xml.sax' respectively.

def _flattened_scope_names(iterator: Iterator[nodes.Global|nodes.Nonlocal]) -> set[str]: (source)

Undocumented

def _get_unpacking_extra_info(node: nodes.Assign, inferred: InferenceResult) -> str: (source)

Return extra information to add to the message for unpacking-non-sequence and unbalanced-tuple/dict-unpacking errors.

def _has_locals_call_after_node(stmt: nodes.NodeNG, scope: nodes.FunctionDef) -> bool: (source)

Undocumented

def _import_name_is_global(stmt: nodes.Global|_base_nodes.ImportNode, global_names: set[str]) -> bool: (source)

Undocumented

def _infer_name_module(node: nodes.Import, name: str) -> Generator[InferenceResult, None, None]: (source)

Undocumented

def _is_from_future_import(stmt: nodes.ImportFrom, name: str) -> bool|None: (source)

Check if the name is a future import from another module.