diff options
| author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-06-18 18:18:45 +0200 |
|---|---|---|
| committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-06-18 18:18:45 +0200 |
| commit | 1e60f0cf4be2bd38dd3871d154f6b5909842e9b1 (patch) | |
| tree | fca65861785229b19857eb21c67cf6b55a9c49a7 /manager.py | |
| parent | 655e4c41f5ed4d5f5a345861133773b5e2ad9c87 (diff) | |
| download | astroid-1e60f0cf4be2bd38dd3871d154f6b5909842e9b1.tar.gz | |
[transforms] allow transformation functions on any nodes, not only modules
Diffstat (limited to 'manager.py')
| -rw-r--r-- | manager.py | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -83,7 +83,7 @@ class AstroidManager(OptionsProviderMixIn): # NOTE: cache entries are added by the [re]builder self.astroid_cache = {} self._mod_file_cache = {} - self.transformers = [] + self.transforms = {} def astroid_from_file(self, filepath, modname=None, fallback=True, source=False): """given a module name, return the astroid object""" @@ -263,8 +263,15 @@ class AstroidManager(OptionsProviderMixIn): project.add_module(astroid) return project - def register_transformer(self, transformer): - self.transformers.append(transformer) + def register_transform(self, node_class, transform, predicate=None): + """Register `transform(node)` function to be applied on the given + Astroid's `node_class` if `predicate` is None or return a true value + when called with the node as argument. + + The transform function may return a value which is then used to + substitute the original node in the tree. + """ + self.transforms.setdefault(node_class, []).append( (transform, predicate) ) class Project: """a project handle a set of modules / packages""" |
