Skip to content

Commit d1eb856

Browse files
justinchubybmehta001
authored andcommitted
Implement __repr__ for MatchResult (microsoft#2353)
This pull request adds a `__repr__` method to the `MatchResult` class in `onnxscript/rewriter/_basics.py`. The new method provides a string representation of the match result, improving debugging and readability.
1 parent a23ee07 commit d1eb856

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

onnxscript/rewriter/_basics.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def __init__(self) -> None:
3838
# We use a stack of partial matches to handle OR patterns that require backtracking.
3939
self._partial_matches: list[PartialMatchResult] = [PartialMatchResult()]
4040

41+
def __repr__(self) -> str:
42+
"""Returns a string representation of the match result."""
43+
if not self._partial_matches:
44+
return "MatchResult()"
45+
return (
46+
f"MatchResult(success={bool(self)}, reason={self.reason!r}, nodes={self.nodes!r})"
47+
)
48+
4149
@property
4250
def _current_match(self) -> PartialMatchResult:
4351
"""Returns the current match result."""

0 commit comments

Comments
 (0)