module documentation

Various helper utilities.

Function class_instance_as_index Get the value as an index for the given instance.
Function has_known_bases Return whether all base classes of a class could be inferred.
Function is_subtype Check if *type1* is a subtype of *type2*.
Function is_supertype Check if *type2* is a supertype of *type1*.
Function object_isinstance Check if a node 'isinstance' any node in class_or_seq.
Function object_issubclass Check if a type is a subclass of any node in class_or_seq.
Function object_len Infer length of given node object.
Function object_type Obtain the type of the given node.
Function safe_infer Return the inferred value for the given node.
Function _build_proxy_class Undocumented
Function _function_type Undocumented
Function _object_type Undocumented
Function _object_type_is_subclass Undocumented
Function _type_check Undocumented
def class_instance_as_index(node: SuccessfulInferenceResult) -> nodes.Const|None: (source)

Get the value as an index for the given instance. If an instance provides an __index__ method, then it can be used in some scenarios where an integer is expected, for instance when multiplying or subscripting a list.

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

Return whether all base classes of a class could be inferred.

def is_subtype(type1, type2) -> bool: (source)

Check if *type1* is a subtype of *type2*.

def is_supertype(type1, type2) -> bool: (source)

Check if *type2* is a supertype of *type1*.

def object_isinstance(node, class_or_seq, context: InferenceContext|None = None): (source)

Check if a node 'isinstance' any node in class_or_seq. :param node: A given node :param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]] :rtype: bool :raises AstroidTypeError: if the given ``classes_or_seq`` are not types

def object_issubclass(node, class_or_seq, context: InferenceContext|None = None): (source)

Check if a type is a subclass of any node in class_or_seq. :param node: A given node :param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]] :rtype: bool :raises AstroidTypeError: if the given ``classes_or_seq`` are not types :raises AstroidError: if the type of the given node cannot be inferred or its type's mro doesn't work

def object_len(node, context: InferenceContext|None = None): (source)

Infer length of given node object. :param Union[nodes.ClassDef, nodes.Instance] node: :param node: Node to infer length of :raises AstroidTypeError: If an invalid node is returned from __len__ method or no __len__ method exists :raises InferenceError: If the given node cannot be inferred or if multiple nodes are inferred or if the code executed in python would result in a infinite recursive check for length :rtype int: Integer length of node

Obtain the type of the given node. This is used to implement the ``type`` builtin, which means that it's used for inferring type calls, as well as used in a couple of other places in the inference. The node will be inferred first, so this function can support all sorts of objects, as long as they support inference.

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).

def _build_proxy_class(cls_name: str, builtins: nodes.Module) -> nodes.ClassDef: (source)

Undocumented

def _function_type(function: nodes.Lambda|bases.UnboundMethod, builtins: nodes.Module) -> nodes.ClassDef: (source)

Undocumented

def _object_type_is_subclass(obj_type, class_or_seq, context: InferenceContext|None = None): (source)

Undocumented

def _type_check(type1, type2) -> bool: (source)

Undocumented