<commit_before>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<commit_msg>Review documentation for the new extensions API.<commit_after>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
{'fraction_non_alphanumeric': 0.08298582151793162, 'fraction_numerical': 0.0, 'mean_word_length': 5.519021739130435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3552528', 'n_tokens_mistral': 634, 'n_tokens_neox': 609, 'n_words': 278}