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_getattr_args Undocumented
Function _infer_object__new__decorator Undocumented
Function _infer_object__new__decorator_check Predicate before inference_tip
def infer_bool(node, context=None): (source)

Understand bool calls.

def infer_callable(node, context=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=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=None): (source)

Infer dict.fromkeys

Parameters
nodeUndocumented
contextUndocumented
nodes.Call nodedict.fromkeys() call to infer
context.InferenceContext contextnode context
Returns
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.Undocumented
def infer_getattr(node, context=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=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=None): (source)

Infer int() calls

Parameters
nodeUndocumented
contextUndocumented
nodes.Call nodeint() call to infer
context.InferenceContextnode context
Returns
a Const containing the integer value of the int() callUndocumented
def infer_isinstance(callnode, context=None): (source)

Infer isinstance calls

Parameters
callnodeUndocumented
contextUndocumented
nodes.Call callnodean isinstance call
InferenceContext contextcontext for call (currently unused but is a common interface for inference)
Returns
Boolean Const value of isinstance callUndocumented
Raises
UseInferenceDefaultIf the node cannot be inferred
def infer_issubclass(callnode, context=None): (source)

Infer issubclass() calls

Parameters
callnodeUndocumented
contextUndocumented
nodes.Call callnodean issubclass call
InferenceContext contextthe context for the inference
Returns
Boolean Const value of the issubclass callUndocumented
Raises
UseInferenceDefaultIf the node cannot be inferred
def infer_len(node, context=None): (source)

Infer length calls

Parameters
nodeUndocumented
contextUndocumented
nodes.Call nodelen call to infer
context.InferenceContextnode context
Returns
a Const node with the inferred length, if possibleUndocumented
def infer_property(node, context=None): (source)

Understand property class

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

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

Understand slice calls.

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

Infer str() calls

Parameters
nodeUndocumented
contextUndocumented
nodes.Call nodestr() call to infer
context.InferenceContextnode context
Returns
a Const containing an empty stringUndocumented
def infer_super(node, context=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=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): (source)

Undocumented

def _class_or_tuple_to_container(node, context=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_getattr_args(node, context): (source)

Undocumented

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

Undocumented

def _infer_object__new__decorator_check(node): (source)

Predicate before inference_tip

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