refactor: use str.removesuffix in _normalize_label_for_match - #306
Conversation
_normalize_label_for_match hand-rolled an endswith-check-then-slice to strip trailing " dropdown"/" menu"/" icon"/" button" qualifiers. Use the stdlib str.removesuffix instead, which is a no-op when the suffix doesn't match. Same behavior (each loop iteration strips at most one matching suffix from the current text), one fewer manual length computation. Mirrors the sibling str.removeprefix cleanup already applied to _parse_navigation_hint in #305. Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe label normalization implementation now uses ChangesLabel normalization
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This PR changes one label-normalization loop from an equivalent manual suffix check and slice to str.removesuffix without changing call sites or matching rules. Python 3.11 supports the method, so no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
grounding.py::_normalize_label_for_matchhand-rolled anendswith-check-then-slice to strip a trailing qualifier (dropdown,menu,icon,button) from a normalized label during fuzzy matching:Replaced with the stdlib
str.removesuffix, which is already a no-op when the suffix doesn't match:Why it's an improvement
len()/slice computation in favor of a purpose-built stdlib method.str.removeprefixcleanup already merged for_parse_navigation_hintin refactor: use str.removeprefix in _parse_navigation_hint #305 — same category, same file family (claim_parser.py→grounding.py).Why it's safe
text[: -len(suffix)]whentext.endswith(suffix)isTrueis exactlytext.removesuffix(suffix); when the suffix doesn't match, both leavetextunchanged. Verified with a standalone script comparing the old and new loop across representative inputs (single-suffix, multi-suffix chains, no match, empty string) — outputs identical in every case.git stashA/B).ruff check src/ tests/clean.ruff format --checkflags this file, but that drift is pre-existing (reproduced on the unmodified baseline) and unrelated to the touched lines — confirmed viaruff format --diff, which shows only pre-existing formatting elsewhere in the file, none on the lines this PR changes.Generated by Claude Code
Note
Low Risk
Single-function stdlib substitution with equivalent semantics; no API or grounding logic changes.
Overview
_normalize_label_for_matchingrounding.pynow strips trailing UI qualifiers (dropdown,menu,icon,button) withstr.removesuffixinstead of anendswith+ slice branch inside the same loop.Behavior for DOM label fuzzy matching is unchanged: each suffix is still applied in order, and non-matching suffixes leave the string as-is. This is a readability/stdlib cleanup only—no call sites or grounding rules change.
Reviewed by Cursor Bugbot for commit 2d75090. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit