diff options
author | Ceridwen <ceridwenv@gmail.com> | 2016-03-11 11:34:33 -0500 |
---|---|---|
committer | Ceridwen <ceridwenv@gmail.com> | 2016-03-11 11:34:33 -0500 |
commit | 0aa2025afa101a19aa7d4ec2daa78aa7fc8e6c18 (patch) | |
tree | 6eae0e66a8b7fe40e270867720c0bf3ab8791fe7 /astroid/tree/zipper.py | |
parent | 3c601315485baeb237927e0770c28db7a88f1e06 (diff) | |
download | astroid-git-0aa2025afa101a19aa7d4ec2daa78aa7fc8e6c18.tar.gz |
Improve zipper's backwards compatibility and fix bugs
Diffstat (limited to 'astroid/tree/zipper.py')
-rw-r--r-- | astroid/tree/zipper.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/astroid/tree/zipper.py b/astroid/tree/zipper.py index cd30b6e9..51360851 100644 --- a/astroid/tree/zipper.py +++ b/astroid/tree/zipper.py @@ -260,7 +260,7 @@ class Zipper(wrapt.ObjectProxy): location = location.up() return location - def get_children(self): + def children(self): '''Iterates over the children of the focus.''' child = self.down() while child is not None: @@ -285,10 +285,10 @@ class Zipper(wrapt.ObjectProxy): yield location if dont_recurse_on is None: to_visit.extend(c for c in - reversed(tuple(location.get_children()))) + reversed(tuple(location.children()))) else: to_visit.extend(c for c in - reversed(tuple(location.get_children())) + reversed(tuple(location.children())) if not isinstance(c, dont_recurse_on)) def postorder_descendants(self, dont_recurse_on=None): @@ -306,10 +306,10 @@ class Zipper(wrapt.ObjectProxy): visited_ancestors.append(location) if dont_recurse_on is None: to_visit.extend(c for c in - reversed(tuple(location.get_children()))) + reversed(tuple(location.children()))) else: to_visit.extend(c for c in - reversed(tuple(location.get_children())) + reversed(tuple(location.children())) if not isinstance(c, dont_recurse_on)) continue visited_ancestors.pop() @@ -325,7 +325,7 @@ class Zipper(wrapt.ObjectProxy): not include nodes of this type or types or any of the descendants of those nodes. ''' - return (d for d in self.preorder_descendants(skip_class) if isinstance(node, cls)) + return (d for d in self.preorder_descendants(skip_class) if isinstance(d, cls)) # if isinstance(self, cls): # yield self # child = self.down() @@ -350,6 +350,22 @@ class Zipper(wrapt.ObjectProxy): else: return location + def get_children(self): + '''Iterates over nodes that are children or grandchildren, no + sequences. + + ''' + child = self.down() + while child is not None: + if isinstance(child, collections.Sequence): + grandchild = child.down() + for _ in range(len(child)): + yield grandchild + grandchild = grandchild.right() + else: + yield child + child = child.right() + def last_child(self): return self.rightmost() |