module documentation

Astroid hooks for various builtins.

Function infer_bool Understand bool calls.
Function infer_callable Understand callable calls.
Function infer_dict Try to infer a dict call to a Dict node.
Function infer_dict_fromkeys Infer dict.fromkeys.
Function infer_getattr Understand getattr calls.
Function infer_hasattr Understand hasattr calls.
Function infer_int Infer int() calls.
Function infer_isinstance Infer isinstance calls.
Function infer_issubclass Infer issubclass() calls.
Function infer_len Infer length calls.
Function infer_property Understand `property` class.
Function infer_slice Understand `slice` calls.
Function infer_str Infer str() calls.
Function infer_super Understand super calls.
Function infer_type Understand the one-argument form of *type*.
Function register_builtin_transform Register a new transform function for the given *builtin_name*.
Constant BYTES_CLASS Undocumented
Constant OBJECT_DUNDER_NEW Undocumented
Constant STR_CLASS Undocumented
Variable infer_frozenset Undocumented
Variable infer_list Undocumented
Variable infer_set Undocumented
Variable infer_tuple Undocumented
Function _builtin_filter_predicate Undocumented
Function _class_or_tuple_to_container Undocumented
Function _container_generic_inference Undocumented
Function _container_generic_transform Undocumented
Function _extend_builtins Undocumented
Function _extend_string_class Function to extend builtin str/unicode class.
Function _get_elts Undocumented
Function _infer_builtin_container Undocumented
Function _infer_copy_method Undocumented
Function _infer_getattr_args Undocumented
Function _infer_object__new__decorator Undocumented
Function _infer_object__new__decorator_check Predicate before inference_tip.
Function _infer_str_format_call Return a Const node based on the template and passed arguments.
Function _is_str_format_call Catch calls to str.format().
def infer_bool(node, context: InferenceContext|None = None): (source)

Understand bool calls.

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

Understand callable calls. This follows Python's semantics, where an object is callable if it provides an attribute __call__, even though that attribute is something which can't be called.

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

Try to infer a dict call to a Dict node. The function treats the following cases: * dict() * dict(mapping) * dict(iterable) * dict(iterable, **kwargs) * dict(mapping, **kwargs) * dict(**kwargs) If a case can't be inferred, we'll fallback to default inference.

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

Infer dict.fromkeys. :param nodes.Call node: dict.fromkeys() call to infer :param context.InferenceContext context: node context :rtype nodes.Dict: a Dictionary containing the values that astroid was able to infer. In case the inference failed for any reason, an empty dictionary will be inferred instead.

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

Understand getattr calls. If one of the arguments is an Uninferable object, then the result will be an Uninferable object. Otherwise, the normal attribute lookup will be done.

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

Understand hasattr calls. This always guarantees three possible outcomes for calling hasattr: Const(False) when we are sure that the object doesn't have the intended attribute, Const(True) when we know that the object has the attribute and Uninferable when we are unsure of the outcome of the function call.

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

Infer int() calls. :param nodes.Call node: int() call to infer :param context.InferenceContext: node context :rtype nodes.Const: a Const containing the integer value of the int() call

def infer_isinstance(callnode, context: InferenceContext|None = None): (source)

Infer isinstance calls. :param nodes.Call callnode: an isinstance call :rtype nodes.Const: Boolean Const value of isinstance call :raises UseInferenceDefault: If the node cannot be inferred

def infer_issubclass(callnode, context: InferenceContext|None = None): (source)

Infer issubclass() calls. :param nodes.Call callnode: an `issubclass` call :param InferenceContext context: the context for the inference :rtype nodes.Const: Boolean Const value of the `issubclass` call :raises UseInferenceDefault: If the node cannot be inferred

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

Infer length calls. :param nodes.Call node: len call to infer :param context.InferenceContext: node context :rtype nodes.Const: a Const node with the inferred length, if possible

def infer_property(node: nodes.Call, context: InferenceContext|None = None) -> objects.Property: (source)

Understand `property` class. This only infers the output of `property` call, not the arguments themselves.

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

Understand `slice` calls.

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

Infer str() calls. :param nodes.Call node: str() call to infer :param context.InferenceContext: node context :rtype nodes.Const: a Const containing an empty string

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

Understand super calls. There are some restrictions for what can be understood: * unbounded super (one argument form) is not understood. * if the super call is not inside a function (classmethod or method), then the default inference will be used. * if the super arguments can't be inferred, the default inference will be used.

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

Understand the one-argument form of *type*.

def register_builtin_transform(transform, builtin_name): (source)

Register a new transform function for the given *builtin_name*. The transform function must accept two parameters, a node and an optional context.

BYTES_CLASS: str = (source)

Undocumented

Value
'''
class whatever(object):
    def join(self, iterable):
        return {rvalue}
    def replace(self, old, new, count=None):
        return {rvalue}
    def decode(self, encoding=\'ascii\', errors=None):
...
OBJECT_DUNDER_NEW: str = (source)

Undocumented

Value
'object.__new__'
STR_CLASS: str = (source)

Undocumented

Value
'''
class whatever(object):
    def join(self, iterable):
        return {rvalue}
    def replace(self, old, new, count=None):
        return {rvalue}
    def format(self, *args, **kwargs):
...
infer_frozenset = (source)

Undocumented

infer_list = (source)

Undocumented

infer_set = (source)

Undocumented

infer_tuple = (source)

Undocumented

def _builtin_filter_predicate(node, builtin_name) -> bool: (source)

Undocumented

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

Undocumented

def _container_generic_inference(node, context, node_type, transform): (source)

Undocumented

def _container_generic_transform(arg, context, klass, iterables, build_elts): (source)

Undocumented

def _extend_builtins(class_transforms): (source)

Undocumented

def _extend_string_class(class_node, code, rvalue): (source)

Function to extend builtin str/unicode class.

def _get_elts(arg, context): (source)

Undocumented

def _infer_builtin_container(node, context, klass=None, iterables=None, build_elts=None): (source)

Undocumented

def _infer_copy_method(node: nodes.Call, context: InferenceContext|None = None) -> Iterator[nodes.NodeNG]: (source)

Undocumented

def _infer_getattr_args(node, context): (source)

Undocumented

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

Undocumented

def _infer_object__new__decorator_check(node) -> bool: (source)

Predicate before inference_tip. Check if the given ClassDef has an @object.__new__ decorator

Return a Const node based on the template and passed arguments.

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

Catch calls to str.format().