summaryrefslogtreecommitdiff
path: root/doc/extending.rst
blob: da3b4e6aa5fbf27ffbf08fd26d89f894fbb7e8c9 (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
Extending Astroid Syntax Tree
=============================

Sometimes Astroid will miss some potentially important information you may wish
you add, as content of the standard library `hashlib` module. In some other
cases, you may want to customize the way inference work, for instance to explain
Astroid that `collections.namedtuple` is returning a class with some known
attributes.

The good news is that you can do it using the transformation API. You'll find
examples in the `brain/` subdirectory. Those come from the `pylint-brain`_ project.

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

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

You may want to use :class:`astroid.AsStringRegexpPredicate` predicate objects
to filter on the `as_string` representation of the node.

.. autoclass:: astroid.AsStringRegexpPredicate

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

.. autofunction:: astroid.inference_tip

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