module documentation
(source)

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​.​Inference​Context 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​.​Inference​Contextnode 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
​Inference​Context 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
​Inference​Context 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​.​Inference​Contextnode 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​.​Inference​Contextnode 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