diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-03 18:35:03 +0800 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-04 06:52:05 -0700 |
commit | 2fcb7e6e4ea33ea8b38429f85f55d681a0cf1e35 (patch) | |
tree | 7908d447b14323d5e567cec4d777ffaca87e00a7 | |
parent | 7284b5b714f0504d95f31033037c572d9f5ea4cd (diff) | |
download | astroid-git-2fcb7e6e4ea33ea8b38429f85f55d681a0cf1e35.tar.gz |
Removed AsStringRegexpPredicate in favour of transform predicates
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | astroid/__init__.py | 25 | ||||
-rw-r--r-- | doc/extending.rst | 5 |
3 files changed, 5 insertions, 31 deletions
@@ -2,7 +2,11 @@ Change log for the astroid package (used to be astng) ===================================================== -- 2.0 --- + + * AsStringRegexpPredicate has been removed. + + Use transform predicates instead of it. + * Switched to using typed_ast for getting access to type comments As a side effect of this change, some nodes gained a new `type_annotation` attribute, diff --git a/astroid/__init__.py b/astroid/__init__.py index bd9069d3..3c9c80cb 100644 --- a/astroid/__init__.py +++ b/astroid/__init__.py @@ -32,8 +32,6 @@ Main modules are: import os import sys -import re -from operator import attrgetter import enum @@ -74,29 +72,6 @@ del AstroidManager # transform utilities (filters and decorator) -class AsStringRegexpPredicate(object): - """ClassDef to be used as predicate that may be given to `register_transform` - - First argument is a regular expression that will be searched against the `as_string` - representation of the node onto which it's applied. - - If specified, the second argument is an `attrgetter` expression that will be - applied on the node first to get the actual node on which `as_string` should - be called. - - WARNING: This can be fairly slow, as it has to convert every AST node back - to Python code; you should consider examining the AST directly instead. - """ - def __init__(self, regexp, expression=None): - self.regexp = re.compile(regexp) - self.expression = expression - - def __call__(self, node): - if self.expression is not None: - node = attrgetter(self.expression)(node) - # pylint: disable=no-member; github.com/pycqa/astroid/126 - return self.regexp.search(node.as_string()) - def inference_tip(infer_function, raise_on_overwrite=False): """Given an instance specific inference function, return a function to be given to MANAGER.register_transform to set this inference function. diff --git a/doc/extending.rst b/doc/extending.rst index 83ffe512..bf32963e 100644 --- a/doc/extending.rst +++ b/doc/extending.rst @@ -15,11 +15,6 @@ subdirectory, which are taken from the `pylint-brain`_ project. Transformation functions are registered using the `register_transform` method of the Astroid manager: - -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. - Last but not least, the :func:`inference_tip` function is there to register a custom inference function. |