summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--astroid/tests/unittest_builder.py2
-rw-r--r--astroid/utils.py102
3 files changed, 4 insertions, 103 deletions
diff --git a/ChangeLog b/ChangeLog
index f999760..7ca8495 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -164,6 +164,9 @@ Change log for the astroid package (used to be astng)
it is the only known client of this module. No other change
was made to the exported API.
+ * astroid.utils.ASTWalker and astroid.utils.LocalsVisitor
+ were moved to pylint.pyreverse.utils.
+
2015-03-14 -- 1.3.6
diff --git a/astroid/tests/unittest_builder.py b/astroid/tests/unittest_builder.py
index 7720d88..9f0fbaf 100644
--- a/astroid/tests/unittest_builder.py
+++ b/astroid/tests/unittest_builder.py
@@ -605,7 +605,7 @@ class FileBuildTest(unittest.TestCase):
keys = sorted(_locals.keys())
should = ['MY_DICT', 'YO', 'YOUPI',
'__revision__', 'global_access', 'modutils', 'four_args',
- 'os', 'redirect', 'pb', 'LocalsVisitor', 'ASTWalker']
+ 'os', 'redirect', 'pb']
should.sort()
self.assertEqual(keys, sorted(should))
diff --git a/astroid/utils.py b/astroid/utils.py
deleted file mode 100644
index 9bf7925..0000000
--- a/astroid/utils.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
-"""this module contains some utilities to navigate in the tree or to
-extract information from it
-"""
-
-
-class ASTWalker(object):
- """a walker visiting a tree in preorder, calling on the handler:
-
- * visit_<class name> on entering a node, where class name is the class of
- the node in lower case
-
- * leave_<class name> on leaving a node, where class name is the class of
- the node in lower case
- """
-
- def __init__(self, handler):
- self.handler = handler
- self._cache = {}
-
- def walk(self, node, _done=None):
- """walk on the tree from <node>, getting callbacks from handler"""
- if _done is None:
- _done = set()
- if node in _done:
- raise AssertionError((id(node), node, node.parent))
- _done.add(node)
- self.visit(node)
- for child_node in node.get_children():
- assert child_node is not node
- self.walk(child_node, _done)
- self.leave(node)
- assert node.parent is not node
-
- def get_callbacks(self, node):
- """get callbacks from handler for the visited node"""
- klass = node.__class__
- methods = self._cache.get(klass)
- if methods is None:
- handler = self.handler
- kid = klass.__name__.lower()
- e_method = getattr(handler, 'visit_%s' % kid,
- getattr(handler, 'visit_default', None))
- l_method = getattr(handler, 'leave_%s' % kid,
- getattr(handler, 'leave_default', None))
- self._cache[klass] = (e_method, l_method)
- else:
- e_method, l_method = methods
- return e_method, l_method
-
- def visit(self, node):
- """walk on the tree from <node>, getting callbacks from handler"""
- method = self.get_callbacks(node)[0]
- if method is not None:
- method(node)
-
- def leave(self, node):
- """walk on the tree from <node>, getting callbacks from handler"""
- method = self.get_callbacks(node)[1]
- if method is not None:
- method(node)
-
-
-class LocalsVisitor(ASTWalker):
- """visit a project by traversing the locals dictionary"""
- def __init__(self):
- ASTWalker.__init__(self, self)
- self._visited = {}
-
- def visit(self, node):
- """launch the visit starting from the given node"""
- if node in self._visited:
- return
- self._visited[node] = 1 # FIXME: use set ?
- methods = self.get_callbacks(node)
- if methods[0] is not None:
- methods[0](node)
- if 'locals' in node.__dict__: # skip Instance and other proxy
- for local_node in node.values():
- self.visit(local_node)
- if methods[1] is not None:
- return methods[1](node)
-
-
-__all__ = ('LocalsVisitor', 'ASTWalker',)
-