summaryrefslogtreecommitdiff
path: root/doc/extending.rst
blob: 946d0116517f3ffc1ec302133f088538894c9388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Extending Astroid Syntax Tree
=============================

Sometimes Astroid will miss some potentially important information
users may wish to add, for instance with the standard library
`hashlib` module. In some other cases, users may want to customize the
way inference works, for instance to explain Astroid that calls to
`collections.namedtuple` are returning a class with some known
attributes.

Modifications in the AST are now possible using the using the generic
transformation API. You can find examples in the `brain/`
subdirectory, which are taken from the the `pylint-brain`_ project.

Transformation functions are registered using the `register_transform` method of
the Astroid manager:

.. automethod:: astroid.manager.AstroidManager.register_transform

To add filtering based on the `as_string` representation of the node
in addition to the type, the :class:`astroid.AsStringRegexpPredicate`
predicate object can be used.

.. autoclass:: astroid.AsStringRegexpPredicate

Last but not least, the :func:`inference_tip` function is there to register
a custom inference function.

.. autofunction:: astroid.inference_tip

.. _`pylint-brain`: https://bitbucket.org/logilab/pylint-brain