From a2db7366fe3a1a25c2c675c2bb65046ce6aa7e22 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Wed, 28 May 2025 17:22:45 -0700 Subject: [PATCH 1/2] Implement `__repr__` for MatchResult --- onnxscript/rewriter/_basics.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/onnxscript/rewriter/_basics.py b/onnxscript/rewriter/_basics.py index a875626d3f..2098d7dfbc 100644 --- a/onnxscript/rewriter/_basics.py +++ b/onnxscript/rewriter/_basics.py @@ -38,6 +38,12 @@ def __init__(self) -> None: # We use a stack of partial matches to handle OR patterns that require backtracking. self._partial_matches: list[PartialMatchResult] = [PartialMatchResult()] + def __repr__(self) -> str: + """Returns a string representation of the match result.""" + if not self._partial_matches: + return "MatchResult()" + return f"MatchResult(success={bool(self)}, reason={self.reason!r}, nodes={self.nodes!r})" + @property def _current_match(self) -> PartialMatchResult: """Returns the current match result.""" From 6caf05074ef55440e167fee99e4434b1dfd5a9be Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 29 May 2025 09:00:48 -0700 Subject: [PATCH 2/2] format --- onnxscript/rewriter/_basics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/onnxscript/rewriter/_basics.py b/onnxscript/rewriter/_basics.py index 2098d7dfbc..6529bea627 100644 --- a/onnxscript/rewriter/_basics.py +++ b/onnxscript/rewriter/_basics.py @@ -42,7 +42,9 @@ def __repr__(self) -> str: """Returns a string representation of the match result.""" if not self._partial_matches: return "MatchResult()" - return f"MatchResult(success={bool(self)}, reason={self.reason!r}, nodes={self.nodes!r})" + return ( + f"MatchResult(success={bool(self)}, reason={self.reason!r}, nodes={self.nodes!r})" + ) @property def _current_match(self) -> PartialMatchResult: