Skip to content

Commit

Permalink
help: fix potential bug in _seek_node
Browse files Browse the repository at this point in the history
_seek_node would not yield any results should the searched node be in
the exclusion list
  • Loading branch information
epsy committed Mar 14, 2017
1 parent 7fd62f3 commit db5fd3b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clize/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@ def add_docstring(self, docstring, name, pnames, primary):


class _NodeSeeker(dunodes.GenericNodeVisitor, object):
def __init__(self, *args, **kwargs):
def __init__(self, node, *args, **kwargs):
include = kwargs.pop('include')
exclude = kwargs.pop('exclude', (dunodes.system_message,))
super(_NodeSeeker, self).__init__(*args, **kwargs)
self.node = node
self.include = include
self.exclude = exclude
self.result = []
Expand All @@ -585,7 +586,7 @@ def __iter__(self):
return iter(self.result)

def default_visit(self, node):
if isinstance(node, self.exclude):
if isinstance(node, self.exclude) and node != self.node:
raise dunodes.SkipChildren
elif isinstance(node, self.include):
self.result.append(node)
Expand Down Expand Up @@ -630,7 +631,7 @@ def __init__(self, *args, **kwargs):
self.result = []

def seek_nodes(self, node, include, exclude=(dunodes.system_message)):
visitor = _NodeSeeker(self.document, include=include, exclude=exclude)
visitor = _NodeSeeker(node, self.document, include=include, exclude=exclude)
node.walk(visitor)
return list(visitor)

Expand Down

0 comments on commit db5fd3b

Please sign in to comment.