Skip to content

Commit 2ff4eb9

Browse files
gramalingamCopilot
andauthored
Update onnxscript/rewriter/_rewrite_rule.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent db355eb commit 2ff4eb9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

onnxscript/rewriter/_rewrite_rule.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,21 @@ def get_replacement(self, match: _basics.MatchResult) -> ReplacementSubgraph | N
230230
return None
231231
if isinstance(new_outputs, _basics.MatchResult):
232232
if not new_outputs:
233+
# A falsy MatchResult is the recommended way to signal failure with
234+
# reason/source information from a replacement function.
233235
match.fail(
234236
new_outputs.reason,
235237
new_outputs.failure_nodes_and_values,
236238
)
237-
return None
239+
return None
240+
# A truthy MatchResult should never be returned from a replacement
241+
# function. Treat this as a programmer error to avoid silent failures.
242+
raise TypeError(
243+
"Replacement function returned a truthy MatchResult. "
244+
"Replacement functions should either return None/False for a "
245+
"generic failure, return a *falsy* MatchResult to provide "
246+
"failure details, or raise MatchFailureError."
247+
)
238248
if not isinstance(new_outputs, Sequence):
239249
new_outputs = [new_outputs]
240250
return ReplacementSubgraph(

0 commit comments

Comments
 (0)