From 2d75090d5d88b7dbcb7789bf53fa71918a32ebc3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 29 Aug 2026 00:58:50 +0000 Subject: [PATCH] refactor: use str.removesuffix in _normalize_label_for_match _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 --- src/frontend_visualqa/grounding.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frontend_visualqa/grounding.py b/src/frontend_visualqa/grounding.py index 9948937..f9cbf67 100644 --- a/src/frontend_visualqa/grounding.py +++ b/src/frontend_visualqa/grounding.py @@ -292,8 +292,7 @@ def _normalize_label_for_match(value: str) -> str: for quote in ("'", '"', "‘", "’", "“", "”"): text = text.replace(quote, "") for suffix in (" dropdown", " menu", " icon", " button"): - if text.endswith(suffix): - text = text[: -len(suffix)] + text = text.removesuffix(suffix) text = "".join(ch for ch in text if unicodedata.category(ch)[0] not in ("S",) and ch not in "▼▶▾▸◀◂✕×›‹«»") return collapse_whitespace(text)