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:
parent
a2c919d350
commit
0c6b2f39b2
|
@ -724,6 +724,8 @@ class Session(nodes.FSCollector):
|
||||||
if col:
|
if col:
|
||||||
self._collection_node_cache1[argpath] = col
|
self._collection_node_cache1[argpath] = col
|
||||||
m = self.matchnodes(col, names)
|
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
|
# 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__
|
# 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
|
# 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("matchnodes finished -> ", len(result), "nodes")
|
||||||
self.trace.root.indent -= 1
|
self.trace.root.indent -= 1
|
||||||
|
|
||||||
if not result:
|
return result
|
||||||
raise NoMatch(matching, names[:1])
|
|
||||||
else:
|
|
||||||
return result
|
|
||||||
|
|
||||||
def genitems(
|
def genitems(
|
||||||
self, node: Union[nodes.Item, nodes.Collector]
|
self, node: Union[nodes.Item, nodes.Collector]
|
||||||
|
|
Loading…
Reference in New Issue