main: move NoMatch raising to _collect()

This is a more sensible interface for matchnodes.

This also fixes a sort-of bug where a recursive call to matchnodes
raises NoMatch which would terminate the entire tree, even if other
branches may find a match. Though I don't think it's actually possible.
This commit is contained in:
Ran Benita 2020-08-21 14:45:03 +03:00
parent a2c919d350
commit 0c6b2f39b2
1 changed files with 3 additions and 4 deletions

View File

@ -724,6 +724,8 @@ class Session(nodes.FSCollector):
if col:
self._collection_node_cache1[argpath] = col
m = self.matchnodes(col, names)
if not m:
raise NoMatch(col)
# If __init__.py was the only file requested, then the matched node will be
# the corresponding Package, and the first yielded item will be the __init__
# Module itself, so just use that. If this special case isn't taken, then all
@ -780,10 +782,7 @@ class Session(nodes.FSCollector):
self.trace("matchnodes finished -> ", len(result), "nodes")
self.trace.root.indent -= 1
if not result:
raise NoMatch(matching, names[:1])
else:
return result
return result
def genitems(
self, node: Union[nodes.Item, nodes.Collector]