class documentation

class TypeChecker(BaseChecker): (source)

View In Hierarchy

Try to find bugs in the code using type inference.

Method open Called before visiting project (i.e. set of modules).
Method visit_assign Process assignments in the AST.
Method visit_assignattr Undocumented
Method visit_attribute Check that the accessed attribute exists.
Method visit_await Undocumented
Method visit_binop Undocumented
Method visit_call Check that called functions/methods are inferred to callable objects, and that passed arguments match the parameters in the inferred function.
Method visit_classdef Undocumented
Method visit_compare Undocumented
Method visit_delattr Undocumented
Method visit_dict Undocumented
Method visit_for Undocumented
Method visit_functiondef Undocumented
Method visit_set Undocumented
Method visit_subscript Undocumented
Method visit_unaryop Detect TypeErrors for unary operands.
Method visit_with Undocumented
Class Variable name Name of the provider.
Class Variable options Options provided by this provider.
Static Method _is_ignored_function Undocumented
Static Method _is_list_sort_method Undocumented
Static Method _keyword_argument_is_in_all_decorator_returns Check if the keyword argument exists in all signatures of the return values of all decorators of the function.
Method _check_argument_order Match the supplied argument names against the function parameters.
Method _check_assignment_from_function_call When assigning to a function call, check that the function returns a valid value.
Method _check_await_outside_coroutine Undocumented
Method _check_binop_errors Undocumented
Method _check_dundername_is_string Check a string is assigned to self.__name__.
Method _check_invalid_sequence_index Undocumented
Method _check_invalid_slice_index Undocumented
Method _check_isinstance_args Undocumented
Method _check_membership_test Undocumented
Method _check_not_callable Checks to see if the not-callable message should be emitted.
Method _check_uninferable_call Check that the given uninferable Call node does not call an actual function.
Method _check_unsupported_alternative_union_syntax Check if left or right node is of type `type`.
Method _detect_unsupported_alternative_union_syntax Detect if unsupported alternative Union syntax (PEP 604) was used.
Method _get_nomember_msgid_hint Undocumented
Method _includes_version_compatible_overload Check if a set of overloads of an operator includes one that can be relied upon for our configured Python version.
Method _recursive_search_for_classdef_type Undocumented
Method _visit_augassign Detect TypeErrors for augmented binary arithmetic operands.
Method _visit_binop Detect TypeErrors for binary arithmetic operands.
Instance Variable _mixin_class_rgx Undocumented
Instance Variable _py310_plus Undocumented
Property _compiled_generated_members Undocumented
Property _suggestion_mode Undocumented

Inherited from BaseChecker:

Method __eq__ Permit to assert Checkers are equal.
Method __gt__ Sorting of checkers.
Method __hash__ Make Checker hashable.
Method __init__ Checker instances should have the linter as argument.
Method __repr__ Undocumented
Method __str__ This might be incomplete because multiple classes inheriting BaseChecker can have the same name.
Method add_message Undocumented
Method check_consistency Check the consistency of msgid.
Method close Called after visiting project (i.e set of modules).
Method create_message_definition_from_tuple Undocumented
Method get_full_documentation Undocumented
Method get_map_data Undocumented
Method get_message_definition Undocumented
Method reduce_map_data 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_option_def DEPRECATED: Return the dictionary defining an option given its name.
Method level.setter Undocumented
Method load_defaults DEPRECATED: Initialize the provider using default values.
Method option_attrname DEPRECATED: Get the config attribute corresponding to opt.
Method option_value DEPRECATED: Get the current value for the given option.
Method options_and_values DEPRECATED.
Method options_by_section DEPRECATED: Return an iterator on options grouped by section.
Method set_option DEPRECATED: Method called to set an option (registered in the options list).
Class Variable option_groups_descs Option groups of this provider and their descriptions.
Property config Undocumented
Property level Undocumented
Instance Variable _arguments_manager The manager that will parse and register any options provided.
Instance Variable _level Undocumented
def open(self): (source)

Called before visiting project (i.e. set of modules).

@only_required_for_messages('assignment-from-no-return', 'assignment-from-none', 'non-str-assignment-to-dunder-name')
def visit_assign(self, node: nodes.Assign): (source)

Process assignments in the AST.

def visit_assignattr(self, node: nodes.AssignAttr): (source)

Undocumented

@only_required_for_messages('no-member', 'c-extension-no-member')
def visit_attribute(self, node: (nodes.Attribute|nodes.AssignAttr)|nodes.DelAttr): (source)

Check that the accessed attribute exists. to avoid too much false positives for now, we'll consider the code as correct if a single of the inferred nodes has the accessed attribute. function/method, super call and metaclasses are ignored

@only_required_for_messages('await-outside-async')
def visit_await(self, node: nodes.Await): (source)

Undocumented

@only_required_for_messages('unsupported-binary-operation')
def visit_binop(self, node: nodes.BinOp): (source)

Undocumented

def visit_call(self, node: nodes.Call): (source)

Check that called functions/methods are inferred to callable objects, and that passed arguments match the parameters in the inferred function.

@only_required_for_messages('invalid-metaclass')
def visit_classdef(self, node: nodes.ClassDef): (source)

Undocumented

@only_required_for_messages('unsupported-membership-test')
def visit_compare(self, node: nodes.Compare): (source)

Undocumented

def visit_delattr(self, node: nodes.DelAttr): (source)

Undocumented

@only_required_for_messages('unhashable-member')
def visit_dict(self, node: nodes.Dict): (source)

Undocumented

@only_required_for_messages('dict-items-missing-iter')
def visit_for(self, node: nodes.For): (source)

Undocumented

@only_required_for_messages('keyword-arg-before-vararg')
def visit_functiondef(self, node: nodes.FunctionDef): (source)

Undocumented

@only_required_for_messages('unhashable-member')
def visit_set(self, node: nodes.Set): (source)

Undocumented

@only_required_for_messages('unsubscriptable-object', 'unsupported-assignment-operation', 'unsupported-delete-operation', 'unhashable-member', 'invalid-sequence-index', 'invalid-slice-index', 'invalid-slice-step')
def visit_subscript(self, node: nodes.Subscript): (source)

Undocumented

@only_required_for_messages('invalid-unary-operand-type')
def visit_unaryop(self, node: nodes.UnaryOp): (source)

Detect TypeErrors for unary operands.

@only_required_for_messages('not-context-manager')
def visit_with(self, node: nodes.With): (source)

Undocumented

Name of the provider.

options: tuple[tuple, ...] = (source)

Options provided by this provider.

@staticmethod
def _is_ignored_function(function_node: nodes.FunctionDef|bases.UnboundMethod) -> bool: (source)

Undocumented

@staticmethod
def _is_list_sort_method(node: nodes.Call) -> bool: (source)

Undocumented

@staticmethod
def _keyword_argument_is_in_all_decorator_returns(func: nodes.FunctionDef, keyword: str) -> bool: (source)

Check if the keyword argument exists in all signatures of the return values of all decorators of the function.

def _check_argument_order(self, node: nodes.Call, call_site: arguments.CallSite, called: CallableObjects, called_param_names: list[str|None]): (source)

Match the supplied argument names against the function parameters. Warn if some argument names are not in the same order as they are in the function signature.

def _check_assignment_from_function_call(self, node: nodes.Assign): (source)

When assigning to a function call, check that the function returns a valid value.

def _check_await_outside_coroutine(self, node: nodes.Await): (source)

Undocumented

def _check_binop_errors(self, node: nodes.BinOp|nodes.AugAssign): (source)

Undocumented

def _check_dundername_is_string(self, node: nodes.Assign): (source)

Check a string is assigned to self.__name__.

def _check_invalid_sequence_index(self, subscript: nodes.Subscript): (source)

Undocumented

def _check_invalid_slice_index(self, node: nodes.Slice): (source)

Undocumented

def _check_isinstance_args(self, node: nodes.Call): (source)

Undocumented

def _check_membership_test(self, node: nodes.NodeNG): (source)

Undocumented

def _check_not_callable(self, node: nodes.Call, inferred_call: nodes.NodeNG|None): (source)

Checks to see if the not-callable message should be emitted. Only functions, generators and objects defining __call__ are "callable" We ignore instances of descriptors since astroid cannot properly handle them yet

def _check_uninferable_call(self, node: nodes.Call): (source)

Check that the given uninferable Call node does not call an actual function.

def _check_unsupported_alternative_union_syntax(self, node: nodes.BinOp): (source)

Check if left or right node is of type `type`. If either is, and doesn't support an or operator via a metaclass, infer that this is a mistaken attempt to use alternative union syntax when not supported.

def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp): (source)

Detect if unsupported alternative Union syntax (PEP 604) was used.

def _get_nomember_msgid_hint(self, node: (nodes.Attribute|nodes.AssignAttr)|nodes.DelAttr, owner: SuccessfulInferenceResult) -> tuple[Literal['c-extension-no-member', 'no-member'], str]: (source)

Undocumented

def _includes_version_compatible_overload(self, attrs: list[nodes.NodeNG]) -> bool: (source)

Check if a set of overloads of an operator includes one that can be relied upon for our configured Python version. If we are running under a Python 3.10+ runtime but configured for pre-3.10 compatibility then Astroid will have inferred the existence of __or__ / __ror__ on builtins.type, but these aren't available in the configured version of Python.

def _recursive_search_for_classdef_type(self, node: nodes.ClassDef, operation: Literal['__or__', '__ror__']) -> bool|VERSION_COMPATIBLE_OVERLOAD: (source)

Undocumented

@only_required_for_messages('unsupported-binary-operation')
def _visit_augassign(self, node: nodes.AugAssign): (source)

Detect TypeErrors for augmented binary arithmetic operands.

@only_required_for_messages('unsupported-binary-operation')
def _visit_binop(self, node: nodes.BinOp): (source)

Detect TypeErrors for binary arithmetic operands.

_mixin_class_rgx = (source)

Undocumented

_py310_plus = (source)

Undocumented

@cached_property
_compiled_generated_members: tuple[Pattern[str], ...] = (source)

Undocumented

@cached_property
_suggestion_mode: bool = (source)

Undocumented