module documentation

Some functions that may be useful for various checkers.

Exception IncompleteFormatString A format string ended in the middle of a format specifier.
Exception InferredTypeError Undocumented
Exception NoSuchArgumentError Undocumented
Exception UnsupportedFormatCharacter A format character in a format string is not one of the supported format characters.
Function assign_parent Return the higher parent which is not an AssignName, Tuple or List node.
Function assigned_bool Returns true if a node is a nodes.Assign that returns a constant boolean.
Function check_messages Kept for backwards compatibility, deprecated.
Function class_is_abstract Return true if the given class node should be considered as an abstract class.
Function collect_string_fields Given a format string, return an iterator of all the valid format fields.
Function decorated_with Determine if the `func` node has a decorator with the qualified name `qname`.
Function decorated_with_property Detect if the given function node is decorated with a property.
Function defnode_in_scope Undocumented
Function error_of_type Check if the given exception handler catches the given error_type.
Function find_assigned_names_recursive Yield the names of assignment targets, accounting for nested ones.
Function find_except_wrapper_node_in_scope Return the ExceptHandler in which the node is, without going out of scope.
Function find_inferred_fn_from_register Undocumented
Function find_try_except_wrapper_node Return the ExceptHandler or the TryExcept node in which the node is.
Function get_all_elements Recursively returns all atoms in nested lists and tuples.
Function get_argument_from_call Returns the specified argument from a function call.
Function get_contextlib_suppressors Return the contextlib suppressors handling the exception.
Function get_contextlib_with_statements Get all contextlib.with statements in the ancestors of the given node.
Function get_exception_handlers Return the collections of handlers handling the exception in arguments.
Function get_import_name Get a prepared module name from the given import node.
Function get_inverse_comparator Returns the inverse comparator given a comparator.
Function get_iterating_dictionary_name Get the name of the dictionary which keys are being iterated over on a ``nodes.For`` or ``nodes.Comprehension`` node.
Function get_node_first_ancestor_of_type Return the first parent node that is any of the provided types (or None).
Function get_node_first_ancestor_of_type_and_its_child Modified version of get_node_first_ancestor_of_type to also return the descendant visited directly before reaching the sought ancestor.
Function get_node_last_lineno Get the last lineno of the given node.
Function get_outer_class Return the class that is the outer class of given (nested) class_node.
Function get_subscript_const_value Returns the value 'subscript.slice' of a Subscript node.
Function has_known_bases Return true if all base classes of a class could be inferred.
Function has_starred_node_recursive Yield ``True`` if a Starred node is found recursively.
Function in_for_else_branch Returns True if stmt is inside the else branch for a parent For stmt.
Function in_type_checking_block Check if a node is guarded by a TYPE_CHECKING guard.
Function infer_all Undocumented
Function inherit_from_std_ex Return whether the given class node is subclass of exceptions.Exception.
Function is_ancestor_name Return whether `frame` is an astroid.Class node with `node` in the subtree of its bases attribute.
Function is_assign_name_annotated_with Test if AssignName node has `typing_name` annotation.
Function is_attr_private Check that attribute name is private (at least two leading underscores, at most one trailing underscore).
Function is_attr_protected Return True if attribute name is protected (start with _ and some other details), False otherwise.
Function is_attribute_typed_annotation Test if attribute is typed annotation in current node or any base nodes.
Function is_augmented_assign Determine if the node is assigning itself (with modifications) to itself.
Function is_base_container Undocumented
Function is_being_called Return True if node is the function being called in a Call node.
Function is_builtin Return true if <name> could be considered as a builtin defined by python.
Function is_builtin_object Returns True if the given node is an object from the __builtin__ module.
Function is_call_of_name Checks if node is a function call with the given name.
Function is_class_attr Undocumented
Function is_class_subscriptable_pep585_with_postponed_evaluation_enabled Check if class is subscriptable with PEP 585 and postponed evaluation enabled.
Function is_classdef_type Test if ClassDef node is Type.
Function is_comprehension Undocumented
Function is_default_argument Return true if the given Name node is used in function or lambda default argument's value.
Function is_defined Searches for a tree node that defines the given variable name.
Function is_defined_before Check if the given variable node is defined before.
Function is_defined_in_scope Undocumented
Function is_deleted_after_current Check if the given variable name is deleted in the same scope after the current node.
Function is_empty_dict_literal Undocumented
Function is_empty_str_literal Undocumented
Function is_enum Undocumented
Function is_error Return true if the given function node only raises an exception.
Function is_from_fallback_block Check if the given node is from a fallback import block.
Function is_func_decorator Return true if the name is used in function decorator.
Function is_function_body_ellipsis Checks whether a function body only consists of a single Ellipsis.
Function is_hashable Return whether any inferred value of `node` is hashable.
Function is_inside_abstract_class Undocumented
Function is_inside_lambda Return whether the given node is inside a lambda.
Function is_iterable Undocumented
Function is_mapping Undocumented
Function is_module_ignored Undocumented
Function is_node_in_guarded_import_block Return True if node is part for guarded if block.
Function is_node_in_type_annotation_context Check if node is in type annotation context.
Function is_node_in_typing_guarded_import_block Return True if node is part for guarded `typing.TYPE_CHECKING` if block.
Function is_node_inside_try_except Check if the node is directly under a Try/Except statement (but not under an ExceptHandler!).
Function is_none Undocumented
Function is_overload_stub Check if a node is a function stub decorated with typing.overload.
Function is_postponed_evaluation_enabled Check if the postponed evaluation of annotations is enabled.
Function is_property_deleter Check if the given node is a property deleter.
Function is_property_setter Check if the given node is a property setter.
Function is_property_setter_or_deleter Check if the given node is either a property setter or a deleter.
Function is_protocol_class Check if the given node represents a protocol class.
Function is_reassigned_after_current Check if the given variable name is reassigned in the same scope after the current node.
Function is_registered_in_singledispatch_function Check if the given function node is a singledispatch function.
Function is_registered_in_singledispatchmethod_function Check if the given function node is a singledispatchmethod function.
Function is_singleton_const Undocumented
Function is_subclass_of Check if first node is a subclass of second node.
Function is_super Return True if the node is referencing the "super" builtin function.
Function is_sys_guard Return True if IF stmt is a sys.version_info guard.
Function is_terminating_func Detect call to exit(), quit(), os._exit(), or sys.exit().
Function is_test_condition Returns true if the given node is being tested for truthiness.
Function is_typing_guard Return True if IF stmt is a typing guard.
Function is_typing_member Check if `node` is a member of the `typing` module and has one of the names from `names_to_check`.
Function node_frame_class Return the class that is wrapping the given node.
Function node_ignores_exception Check if the node is in a TryExcept which handles the given exception.
Function node_type Return the inferred type for `node`.
Function not_condition_as_string Undocumented
Function only_required_for_messages Decorator to store messages that are handled by a checker method as an attribute of the function object.
Function overrides_a_method Return True if <name> is a method overridden from an ancestor which is not the base object class.
Function parse_format_method_string Parses a PEP 3101 format string, returning a tuple of (keyword_arguments, implicit_pos_args_cnt, explicit_pos_args).
Function parse_format_string Parses a format string, returning a tuple (keys, num_args).
Function returns_bool Returns true if a node is a nodes.Return that returns a constant boolean.
Function safe_infer Return the inferred value for the given node.
Function split_format_field_names Undocumented
Function supports_delitem Undocumented
Function supports_getitem Undocumented
Function supports_membership_test Undocumented
Function supports_setitem Undocumented
Function unimplemented_abstract_methods Get the unimplemented abstract methods for the given *node*.
Function uninferable_final_decorators Return a list of uninferable `typing.final` decorators in `node`.
Constant ABC_METHODS Undocumented
Constant ABC_MODULES Undocumented
Constant AITER_METHOD Undocumented
Constant CLASS_GETITEM_METHOD Undocumented
Constant COMMUTATIVE_OPERATORS Undocumented
Constant COMP_NODE_TYPES Undocumented
Constant CONTAINS_METHOD Undocumented
Constant DELITEM_METHOD Undocumented
Constant EXCEPTIONS_MODULE Undocumented
Constant GETITEM_METHOD Undocumented
Constant ITER_METHOD Undocumented
Constant KEYS_METHOD Undocumented
Constant NEXT_METHOD Undocumented
Constant PYMETHODS Undocumented
Constant SETITEM_METHOD Undocumented
Constant SINGLETON_VALUES Undocumented
Constant SPECIAL_BUILTINS Undocumented
Constant SPECIAL_METHODS_PARAMS Undocumented
Constant SUBSCRIPTABLE_CLASSES_PEP585 Undocumented
Constant TERMINATING_FUNCS_QNAMES Undocumented
Constant TYPING_PROTOCOLS Undocumented
Type Alias AstCallbackMethod Undocumented
Variable builtins Undocumented
Function _except_handlers_ignores_exceptions Undocumented
Function _get_python_type_of_node Undocumented
Function _is_abstract_class_name Undocumented
Function _is_property_decorator Undocumented
Function _is_property_kind Undocumented
Function _is_target_name_in_binop_side Determine whether the target name-like node is referenced in the side node.
Function _supports_async_iteration_protocol Undocumented
Function _supports_delitem_protocol Undocumented
Function _supports_getitem_protocol Undocumented
Function _supports_iteration_protocol Undocumented
Function _supports_mapping_protocol Undocumented
Function _supports_membership_test_protocol Undocumented
Function _supports_protocol Undocumented
Function _supports_protocol_method Undocumented
Function _supports_setitem_protocol Undocumented
Function _suppresses_exception Check if the given node suppresses the given exception.
Constant _SPECIAL_METHODS_PARAMS Undocumented
Type Variable _CheckerT Undocumented
Type Variable _NodeT Undocumented
def assign_parent(node: nodes.NodeNG) -> nodes.NodeNG: (source)

Return the higher parent which is not an AssignName, Tuple or List node.

def assigned_bool(node: nodes.NodeNG) -> bool: (source)

Returns true if a node is a nodes.Assign that returns a constant boolean.

Kept for backwards compatibility, deprecated. Use only_required_for_messages instead, which conveys the intent of the decorator much clearer.

def class_is_abstract(node: nodes.ClassDef) -> bool: (source)

Return true if the given class node should be considered as an abstract class.

def collect_string_fields(format_string: str) -> Iterable[str|None]: (source)

Given a format string, return an iterator of all the valid format fields. It handles nested fields as well.

def decorated_with(func: ((nodes.ClassDef|nodes.FunctionDef)|astroid.BoundMethod)|astroid.UnboundMethod, qnames: Iterable[str]) -> bool: (source)

Determine if the `func` node has a decorator with the qualified name `qname`.

def decorated_with_property(node: nodes.FunctionDef) -> bool: (source)

Detect if the given function node is decorated with a property.

def defnode_in_scope(var_node: nodes.NodeNG, varname: str, scope: nodes.NodeNG) -> nodes.NodeNG|None: (source)

Undocumented

def error_of_type(handler: nodes.ExceptHandler, error_type: (str|type[Exception])|tuple[str|type[Exception], ...]) -> bool: (source)

Check if the given exception handler catches the given error_type. The *handler* parameter is a node, representing an ExceptHandler node. The *error_type* can be an exception, such as AttributeError, the name of an exception, or it can be a tuple of errors. The function will return True if the handler catches any of the given errors.

def find_assigned_names_recursive(target: nodes.AssignName|nodes.BaseContainer) -> Iterator[str]: (source)

Yield the names of assignment targets, accounting for nested ones.

def find_except_wrapper_node_in_scope(node: nodes.NodeNG) -> (nodes.ExceptHandler|nodes.TryExcept)|None: (source)

Return the ExceptHandler in which the node is, without going out of scope.

def find_inferred_fn_from_register(node: nodes.NodeNG) -> nodes.FunctionDef|None: (source)

Undocumented

def find_try_except_wrapper_node(node: nodes.NodeNG) -> (nodes.ExceptHandler|nodes.TryExcept)|None: (source)

Return the ExceptHandler or the TryExcept node in which the node is.

def get_all_elements(node: nodes.NodeNG) -> Iterable[nodes.NodeNG]: (source)

Recursively returns all atoms in nested lists and tuples.

def get_argument_from_call(call_node: nodes.Call, position: int|None = None, keyword: str|None = None) -> nodes.Name: (source)

Returns the specified argument from a function call. :param nodes.Call call_node: Node representing a function call to check. :param int position: position of the argument. :param str keyword: the keyword of the argument. :returns: The node representing the argument, None if the argument is not found. :rtype: nodes.Name :raises ValueError: if both position and keyword are None. :raises NoSuchArgumentError: if no argument at the provided position or with the provided keyword.

def get_contextlib_suppressors(node: nodes.NodeNG, exception: type[Exception]|str = Exception) -> Iterator[nodes.With]: (source)

Return the contextlib suppressors handling the exception. Args: node (nodes.NodeNG): A node that is potentially wrapped in a contextlib.suppress. exception (builtin.Exception): exception or name of the exception. Yields: nodes.With: A with node that is suppressing the exception.

def get_contextlib_with_statements(node: nodes.NodeNG) -> Iterator[nodes.With]: (source)

Get all contextlib.with statements in the ancestors of the given node.

def get_exception_handlers(node: nodes.NodeNG, exception: type[Exception]|str = Exception) -> list[nodes.ExceptHandler]|None: (source)

Return the collections of handlers handling the exception in arguments. Args: node (nodes.NodeNG): A node that is potentially wrapped in a try except. exception (builtin.Exception or str): exception or name of the exception. Returns: list: the collection of handlers that are handling the exception or None.

def get_import_name(importnode: ImportNode, modname: str|None) -> str|None: (source)

Get a prepared module name from the given import node. In the case of relative imports, this will return the absolute qualified module name, which might be useful for debugging. Otherwise, the initial module name is returned unchanged. :param importnode: node representing import statement. :param modname: module name from import statement. :returns: absolute qualified module name of the module used in import.

def get_inverse_comparator(op: str) -> str: (source)

Returns the inverse comparator given a comparator. E.g. when given "==", returns "!=" :param str op: the comparator to look up. :returns: The inverse of the comparator in string format :raises KeyError: if input is not recognized as a comparator

def get_iterating_dictionary_name(node: nodes.For|nodes.Comprehension) -> str|None: (source)

Get the name of the dictionary which keys are being iterated over on a ``nodes.For`` or ``nodes.Comprehension`` node. If the iterating object is not either the keys method of a dictionary or a dictionary itself, this returns None.

def get_node_first_ancestor_of_type(node: nodes.NodeNG, ancestor_type: type[_NodeT]|tuple[type[_NodeT], ...]) -> _NodeT|None: (source)

Return the first parent node that is any of the provided types (or None).

def get_node_first_ancestor_of_type_and_its_child(node: nodes.NodeNG, ancestor_type: type[_NodeT]|tuple[type[_NodeT], ...]) -> tuple[None, None]|tuple[_NodeT, nodes.NodeNG]: (source)

Modified version of get_node_first_ancestor_of_type to also return the descendant visited directly before reaching the sought ancestor. Useful for extracting whether a statement is guarded by a try, except, or finally when searching for a TryFinally ancestor.

def get_node_last_lineno(node: nodes.NodeNG) -> int: (source)

Get the last lineno of the given node. For a simple statement this will just be node.lineno, but for a node that has child statements (e.g. a method) this will be the lineno of the last child statement recursively.

def get_outer_class(class_node: astroid.ClassDef) -> astroid.ClassDef|None: (source)

Return the class that is the outer class of given (nested) class_node.

def get_subscript_const_value(node: nodes.Subscript) -> nodes.Const: (source)

Returns the value 'subscript.slice' of a Subscript node. :param node: Subscript Node to extract value from :returns: Const Node containing subscript value :raises InferredTypeError: if the subscript node cannot be inferred as a Const

def has_known_bases(klass: nodes.ClassDef, context: InferenceContext|None = None) -> bool: (source)

Return true if all base classes of a class could be inferred.

def has_starred_node_recursive(node: (nodes.For|nodes.Comprehension)|nodes.Set) -> Iterator[bool]: (source)

Yield ``True`` if a Starred node is found recursively.

@lru_cache()
def in_for_else_branch(parent: nodes.NodeNG, stmt: nodes.Statement) -> bool: (source)

Returns True if stmt is inside the else branch for a parent For stmt.

def in_type_checking_block(node: nodes.NodeNG) -> bool: (source)

Check if a node is guarded by a TYPE_CHECKING guard.

@lru_cache(maxsize=512)
def infer_all(node: nodes.NodeNG, context: InferenceContext|None = None) -> list[InferenceResult]: (source)

Undocumented

def inherit_from_std_ex(node: nodes.NodeNG|astroid.Instance) -> bool: (source)

Return whether the given class node is subclass of exceptions.Exception.

def is_ancestor_name(frame: nodes.ClassDef, node: nodes.NodeNG) -> bool: (source)

Return whether `frame` is an astroid.Class node with `node` in the subtree of its bases attribute.

def is_assign_name_annotated_with(node: nodes.AssignName, typing_name: str) -> bool: (source)

Test if AssignName node has `typing_name` annotation. Especially useful to check for `typing._SpecialForm` instances like: `Union`, `Optional`, `Literal`, `ClassVar`, `Final`.

def is_attr_private(attrname: str) -> Match[str]|None: (source)

Check that attribute name is private (at least two leading underscores, at most one trailing underscore).

def is_attr_protected(attrname: str) -> bool: (source)

Return True if attribute name is protected (start with _ and some other details), False otherwise.

def is_attribute_typed_annotation(node: nodes.ClassDef|astroid.Instance, attr_name: str) -> bool: (source)

Test if attribute is typed annotation in current node or any base nodes.

def is_augmented_assign(node: nodes.Assign) -> tuple[bool, str]: (source)

Determine if the node is assigning itself (with modifications) to itself. For example: x = 1 + x

def is_base_container(node: nodes.NodeNG|None) -> bool: (source)

Undocumented

def is_being_called(node: nodes.NodeNG) -> bool: (source)

Return True if node is the function being called in a Call node.

def is_builtin(name: str) -> bool: (source)

Return true if <name> could be considered as a builtin defined by python.

def is_builtin_object(node: nodes.NodeNG) -> bool: (source)

Returns True if the given node is an object from the __builtin__ module.

def is_call_of_name(node: nodes.NodeNG, name: str) -> bool: (source)

Checks if node is a function call with the given name.

def is_class_attr(name: str, klass: nodes.ClassDef) -> bool: (source)

Undocumented

def is_class_subscriptable_pep585_with_postponed_evaluation_enabled(value: nodes.ClassDef, node: nodes.NodeNG) -> bool: (source)

Check if class is subscriptable with PEP 585 and postponed evaluation enabled.

def is_classdef_type(node: nodes.ClassDef) -> bool: (source)

Test if ClassDef node is Type.

def is_comprehension(node: nodes.NodeNG) -> bool: (source)

Undocumented

def is_default_argument(node: nodes.NodeNG, scope: nodes.NodeNG|None = None) -> bool: (source)

Return true if the given Name node is used in function or lambda default argument's value.

def is_defined(name: str, node: nodes.NodeNG) -> bool: (source)

Searches for a tree node that defines the given variable name.

def is_defined_before(var_node: nodes.Name) -> bool: (source)

Check if the given variable node is defined before. Verify that the variable node is defined by a parent node (e.g. if or with) earlier than `var_node`, or is defined by a (list, set, dict, or generator comprehension, lambda) or in a previous sibling node on the same line (statement_defining ; statement_using).

def is_defined_in_scope(var_node: nodes.NodeNG, varname: str, scope: nodes.NodeNG) -> bool: (source)

Undocumented

def is_deleted_after_current(node: nodes.NodeNG, varname: str) -> bool: (source)

Check if the given variable name is deleted in the same scope after the current node.

def is_empty_dict_literal(node: nodes.NodeNG|None) -> bool: (source)

Undocumented

def is_empty_str_literal(node: nodes.NodeNG|None) -> bool: (source)

Undocumented

def is_enum(node: nodes.ClassDef) -> bool: (source)

Undocumented

def is_error(node: nodes.FunctionDef) -> bool: (source)

Return true if the given function node only raises an exception.

def is_from_fallback_block(node: nodes.NodeNG) -> bool: (source)

Check if the given node is from a fallback import block.

def is_func_decorator(node: nodes.NodeNG) -> bool: (source)

Return true if the name is used in function decorator.

def is_function_body_ellipsis(node: nodes.FunctionDef) -> bool: (source)

Checks whether a function body only consists of a single Ellipsis.

def is_hashable(node: nodes.NodeNG) -> bool: (source)

Return whether any inferred value of `node` is hashable. When finding ambiguity, return True.

def is_inside_abstract_class(node: nodes.NodeNG) -> bool: (source)

Undocumented

def is_inside_lambda(node: nodes.NodeNG) -> bool: (source)

Return whether the given node is inside a lambda.

def is_iterable(value: nodes.NodeNG, check_async: bool = False) -> bool: (source)

Undocumented

def is_mapping(value: nodes.NodeNG) -> bool: (source)

Undocumented

def is_module_ignored(module: nodes.Module, ignored_modules: Iterable[str]) -> bool: (source)

Undocumented

def is_node_in_guarded_import_block(node: nodes.NodeNG) -> bool: (source)

Return True if node is part for guarded if block. I.e. `sys.version_info` or `typing.TYPE_CHECKING`

def is_node_in_type_annotation_context(node: nodes.NodeNG) -> bool: (source)

Check if node is in type annotation context. Check for 'AnnAssign', function 'Arguments', or part of function return type annotation.

def is_node_in_typing_guarded_import_block(node: nodes.NodeNG) -> bool: (source)

Return True if node is part for guarded `typing.TYPE_CHECKING` if block.

def is_node_inside_try_except(node: nodes.Raise) -> bool: (source)

Check if the node is directly under a Try/Except statement (but not under an ExceptHandler!). Args: node (nodes.Raise): the node raising the exception. Returns: bool: True if the node is inside a try/except statement, False otherwise.

def is_none(node: nodes.NodeNG) -> bool: (source)

Undocumented

@lru_cache(maxsize=1024)
def is_overload_stub(node: nodes.NodeNG) -> bool: (source)

Check if a node is a function stub decorated with typing.overload. :param node: Node to check. :returns: True if node is an overload function stub. False otherwise.

def is_postponed_evaluation_enabled(node: nodes.NodeNG) -> bool: (source)

Check if the postponed evaluation of annotations is enabled.

def is_property_deleter(node: nodes.NodeNG) -> bool: (source)

Check if the given node is a property deleter.

def is_property_setter(node: nodes.NodeNG) -> bool: (source)

Check if the given node is a property setter.

def is_property_setter_or_deleter(node: nodes.NodeNG) -> bool: (source)

Check if the given node is either a property setter or a deleter.

def is_protocol_class(cls: nodes.NodeNG) -> bool: (source)

Check if the given node represents a protocol class. :param cls: The node to check :returns: True if the node is or inherits from typing.Protocol directly, false otherwise.

def is_reassigned_after_current(node: nodes.NodeNG, varname: str) -> bool: (source)

Check if the given variable name is reassigned in the same scope after the current node.

def is_registered_in_singledispatch_function(node: nodes.FunctionDef) -> bool: (source)

Check if the given function node is a singledispatch function.

def is_registered_in_singledispatchmethod_function(node: nodes.FunctionDef) -> bool: (source)

Check if the given function node is a singledispatchmethod function.

def is_singleton_const(node: nodes.NodeNG) -> bool: (source)

Undocumented

def is_subclass_of(child: nodes.ClassDef, parent: nodes.ClassDef) -> bool: (source)

Check if first node is a subclass of second node. :param child: Node to check for subclass. :param parent: Node to check for superclass. :returns: True if child is derived from parent. False otherwise.

def is_super(node: nodes.NodeNG) -> bool: (source)

Return True if the node is referencing the "super" builtin function.

def is_sys_guard(node: nodes.If) -> bool: (source)

Return True if IF stmt is a sys.version_info guard. >>> import sys >>> if sys.version_info > (3, 8): >>> from typing import Literal >>> else: >>> from typing_extensions import Literal

def is_terminating_func(node: nodes.Call) -> bool: (source)

Detect call to exit(), quit(), os._exit(), or sys.exit().

def is_test_condition(node: nodes.NodeNG, parent: nodes.NodeNG|None = None) -> bool: (source)

Returns true if the given node is being tested for truthiness.

def is_typing_guard(node: nodes.If) -> bool: (source)

Return True if IF stmt is a typing guard. >>> from typing import TYPE_CHECKING >>> if TYPE_CHECKING: >>> from xyz import a

def is_typing_member(node: nodes.NodeNG, names_to_check: tuple[str, ...]) -> bool: (source)

Check if `node` is a member of the `typing` module and has one of the names from `names_to_check`.

def node_frame_class(node: nodes.NodeNG) -> nodes.ClassDef|None: (source)

Return the class that is wrapping the given node. The function returns a class for a method node (or a staticmethod or a classmethod), otherwise it returns `None`.

def node_ignores_exception(node: nodes.NodeNG, exception: type[Exception]|str = Exception) -> bool: (source)

Check if the node is in a TryExcept which handles the given exception. If the exception is not given, the function is going to look for bare excepts.

Return the inferred type for `node`. If there is more than one possible type, or if inferred type is Uninferable or None, return None

def not_condition_as_string(test_node: (((nodes.Compare|nodes.Name)|nodes.UnaryOp)|nodes.BoolOp)|nodes.BinOp) -> str: (source)

Undocumented

def only_required_for_messages(*messages: str) -> Callable[[AstCallbackMethod[_CheckerT, _NodeT]], AstCallbackMethod[_CheckerT, _NodeT]]: (source)

Decorator to store messages that are handled by a checker method as an attribute of the function object. This information is used by ``ASTWalker`` to decide whether to call the decorated method or not. If none of the messages is enabled, the method will be skipped. Therefore, the list of messages must be well maintained at all times! This decorator only has an effect on ``visit_*`` and ``leave_*`` methods of a class inheriting from ``BaseChecker``.

def overrides_a_method(class_node: nodes.ClassDef, name: str) -> bool: (source)

Return True if <name> is a method overridden from an ancestor which is not the base object class.

def parse_format_method_string(format_string: str) -> tuple[list[tuple[str, list[tuple[bool, str]]]], int, int]: (source)

Parses a PEP 3101 format string, returning a tuple of (keyword_arguments, implicit_pos_args_cnt, explicit_pos_args). keyword_arguments is the set of mapping keys in the format string, implicit_pos_args_cnt is the number of arguments required by the format string and explicit_pos_args is the number of arguments passed with the position.

def parse_format_string(format_string: str) -> tuple[set[str], int, dict[str, str], list[str]]: (source)

Parses a format string, returning a tuple (keys, num_args). Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number of arguments required by the format string. Raises IncompleteFormatString or UnsupportedFormatCharacter if a parse error occurs.

def returns_bool(node: nodes.NodeNG) -> bool: (source)

Returns true if a node is a nodes.Return that returns a constant boolean.

@lru_cache(maxsize=1024)
def safe_infer(node: nodes.NodeNG, context: InferenceContext|None = None, *, compare_constants: bool = False) -> InferenceResult|None: (source)

Return the inferred value for the given node. Return None if inference failed or if there is some ambiguity (more than one node has been inferred of different types). If compare_constants is True and if multiple constants are inferred, unequal inferred values are also considered ambiguous and return None.

def split_format_field_names(format_string: str) -> tuple[str, Iterable[tuple[bool, str]]]: (source)

Undocumented

def supports_delitem(value: nodes.NodeNG, _: nodes.NodeNG) -> bool: (source)

Undocumented

def supports_getitem(value: nodes.NodeNG, node: nodes.NodeNG) -> bool: (source)

Undocumented

def supports_membership_test(value: nodes.NodeNG) -> bool: (source)

Undocumented

def supports_setitem(value: nodes.NodeNG, _: nodes.NodeNG) -> bool: (source)

Undocumented

@lru_cache(maxsize=1024)
def unimplemented_abstract_methods(node: nodes.ClassDef, is_abstract_cb: nodes.FunctionDef = None) -> dict[str, nodes.FunctionDef]: (source)

Get the unimplemented abstract methods for the given *node*. A method can be considered abstract if the callback *is_abstract_cb* returns a ``True`` value. The check defaults to verifying that a method is decorated with abstract methods. It will return a dictionary of abstract method names and their inferred objects.

def uninferable_final_decorators(node: nodes.Decorators) -> list[(nodes.Attribute|nodes.Name)|None]: (source)

Return a list of uninferable `typing.final` decorators in `node`. This function is used to determine if the `typing.final` decorator is used with an unsupported Python version; the decorator cannot be inferred when using a Python version lower than 3.8.

ABC_METHODS: set[str] = (source)

Undocumented

Value
set(['abc.abstractproperty',
     'abc.abstractmethod',
     'abc.abstractclassmethod',
     'abc.abstractstaticmethod'])
ABC_MODULES: set[str] = (source)

Undocumented

Value
set(['abc', '_py_abc'])
AITER_METHOD: str = (source)

Undocumented

Value
'__aiter__'
CLASS_GETITEM_METHOD: str = (source)

Undocumented

Value
'__class_getitem__'
COMMUTATIVE_OPERATORS = (source)

Undocumented

Value
frozenset(set(['*', '+', '^', '&', '|']))
COMP_NODE_TYPES = (source)

Undocumented

Value
(nodes.ListComp, nodes.SetComp, nodes.DictComp, nodes.GeneratorExp)
CONTAINS_METHOD: str = (source)

Undocumented

Value
'__contains__'
DELITEM_METHOD: str = (source)

Undocumented

Value
'__delitem__'
EXCEPTIONS_MODULE: str = (source)

Undocumented

Value
'builtins'
GETITEM_METHOD: str = (source)

Undocumented

Value
'__getitem__'
ITER_METHOD: str = (source)

Undocumented

Value
'__iter__'
KEYS_METHOD: str = (source)

Undocumented

Value
'keys'
NEXT_METHOD: str = (source)

Undocumented

Value
'__next__'
PYMETHODS = (source)

Undocumented

Value
set(SPECIAL_METHODS_PARAMS)
SETITEM_METHOD: str = (source)

Undocumented

Value
'__setitem__'
SINGLETON_VALUES: set = (source)

Undocumented

Value
set([True, False, None])
SPECIAL_BUILTINS: tuple[str, ...] = (source)

Undocumented

Value
('__builtins__')
SPECIAL_METHODS_PARAMS = (source)

Undocumented

Value
{name: params for params, methods in _SPECIAL_METHODS_PARAMS.items() for
    name in methods}
SUBSCRIPTABLE_CLASSES_PEP585 = (source)

Undocumented

Value
frozenset(('builtins.tuple',
           'builtins.list',
           'builtins.dict',
           'builtins.set',
           'builtins.frozenset',
           'builtins.type',
           'collections.deque',
...
TERMINATING_FUNCS_QNAMES = (source)

Undocumented

Value
frozenset(set(['_sitebuiltins.Quitter', 'sys.exit', 'posix._exit', 'nt._exit']))
TYPING_PROTOCOLS = (source)

Undocumented

Value
frozenset(set(['typing.Protocol', 'typing_extensions.Protocol', '.Protocol']))
AstCallbackMethod = (source)

Undocumented

Value
Callable[[_CheckerT, _NodeT], None]
builtins = (source)

Undocumented

def _except_handlers_ignores_exceptions(handlers: nodes.ExceptHandler, exceptions: tuple[type[ImportError], type[ModuleNotFoundError]]) -> bool: (source)

Undocumented

def _get_python_type_of_node(node: nodes.NodeNG) -> str|None: (source)

Undocumented

def _is_abstract_class_name(name: str) -> bool: (source)

Undocumented

def _is_property_decorator(decorator: nodes.Name) -> bool: (source)

Undocumented

def _is_property_kind(node: nodes.NodeNG, *kinds: str) -> bool: (source)

Undocumented

def _is_target_name_in_binop_side(target: nodes.AssignName|nodes.AssignAttr, side: nodes.NodeNG|None) -> bool: (source)

Determine whether the target name-like node is referenced in the side node.

def _supports_async_iteration_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_delitem_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_getitem_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_iteration_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_mapping_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_membership_test_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _supports_protocol(value: nodes.NodeNG, protocol_callback: Callable[[nodes.NodeNG], bool]) -> bool: (source)

Undocumented

def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool: (source)

Undocumented

def _supports_setitem_protocol(value: nodes.NodeNG) -> bool: (source)

Undocumented

def _suppresses_exception(call: nodes.Call, exception: type[Exception]|str = Exception) -> bool: (source)

Check if the given node suppresses the given exception.

_SPECIAL_METHODS_PARAMS: dict = (source)

Undocumented

Value
{None: ('__new__', '__init__', '__call__', '__init_subclass__'),
 0: ('__del__',
     '__repr__',
     '__str__',
     '__bytes__',
     '__hash__',
     '__bool__',
...
_CheckerT = (source)

Undocumented

Value
TypeVar('_CheckerT',
        bound='BaseChecker')

Undocumented

Value
TypeVar('_NodeT',
        bound=nodes.NodeNG)