General API

Python Abstract Syntax Tree New Generation

The aim of this module is to provide a common base representation of python source code for projects such as pychecker, pyreverse, pylint… Well, actually the development of this library is essentially governed by pylint’s needs.

It extends class defined in the python’s _ast module with some additional methods and attributes. Instance attributes are added by a builder object, which can either generate extended ast (let’s call them astroid ;) by visiting an existent ast tree or by inspecting living object. Methods are added by monkey patching ast classes.

Main modules are:

  • nodes and scoped_nodes for more information about methods and attributes added to different node classes
  • the manager contains a high level object to get astroid trees from source files and living objects. It maintains a cache of previously constructed tree for quick access
  • builder contains the class responsible to build astroid trees
astroid.inference_tip(infer_function, raise_on_overwrite=False)[source]

Given an instance specific inference function, return a function to be given to MANAGER.register_transform to set this inference function.

Parameters:raise_on_overwrite (bool) – Raise an InferenceOverwriteError if the inference tip will overwrite another. Used for debugging

Typical usage

MANAGER.register_transform(Call, inference_tip(infer_named_tuple),
                           predicate)

Note

Using an inference tip will override any previously set inference tip for the given node. Use a predicate in the transform to prevent excess overwrites.

astroid.register_module_extender(manager, module_name, get_extension_mod)[source]