main: make matchnodes non-recursive

It's a little more sane this way.
This commit is contained in:
Ran Benita 2020-08-21 16:50:28 +03:00
parent 841521fedb
commit c2256189ae
1 changed files with 35 additions and 33 deletions

View File

@ -747,10 +747,13 @@ class Session(nodes.FSCollector):
matching: Sequence[Union[nodes.Item, nodes.Collector]],
names: Sequence[str],
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
result = []
work = [(matching, names)]
while work:
self.trace("matchnodes", matching, names)
self.trace.root.indent += 1
result = []
matching, names = work.pop()
for node in matching:
if not names:
result.append(node)
@ -770,10 +773,10 @@ class Session(nodes.FSCollector):
if x.name == names[0] or x.name.split("[")[0] == names[0]:
submatching.append(x)
if submatching:
result.extend(self.matchnodes(submatching, names[1:]))
work.append((submatching, names[1:]))
# XXX Accept IDs that don't have "()" for class instances.
elif len(rep.result) == 1 and rep.result[0].name == "()":
result.extend(self.matchnodes(rep.result, names))
work.append((rep.result, names))
else:
# Report collection failures here to avoid failing to run some test
# specified in the command line because the module could not be
@ -782,7 +785,6 @@ class Session(nodes.FSCollector):
self.trace("matchnodes finished -> ", len(result), "nodes")
self.trace.root.indent -= 1
return result
def genitems(