fix: resolve ruff violations in GP scripts and main.py

- Use .values() instead of .items() when attr_name is unused (B007/PERF102)
- Split long print f-string to stay under 120 chars (E501)
- Add blank line in docstring between summary and description (D205)
- Use ternary operator for locale assignment in main.py (SIM108)
This commit is contained in:
RamGopalSrikar
2026-04-09 11:26:54 -04:00
parent 7ea27ee658
commit b7d30805ee
3 changed files with 6 additions and 6 deletions

View File

@ -51,7 +51,7 @@ def collect_strings() -> dict[str, str]:
print(f" SKIP {modname}: {e}")
continue
for attr_name, cls in vars(module).items():
for cls in vars(module).values():
if not isinstance(cls, type):
continue
# Only process classes defined in this module (avoid re-processing imports)
@ -109,7 +109,9 @@ def main() -> None:
print("Scanning lfx.components for translatable strings...")
strings = collect_strings()
print(
f"Found {len(strings)} translatable keys across {sum(1 for k in strings if k.endswith('.display_name') and '.inputs.' not in k and '.outputs.' not in k)} components."
f"Found {len(strings)} translatable keys across "
f"{sum(1 for k in strings if k.endswith('.display_name') and '.inputs.' not in k and '.outputs.' not in k)}"
" components."
)
new_content = json.dumps(strings, ensure_ascii=False, indent=2) + "\n"

View File

@ -34,6 +34,7 @@ class TestExtractBackendStrings:
def test_writes_keys_in_order_returned_by_collect_strings(self, tmp_path):
"""main() writes keys in the order collect_strings() returns them.
collect_strings() always returns sorted keys, so the output is sorted in practice.
"""
output_file = tmp_path / "en.json"

View File

@ -518,10 +518,7 @@ def create_app():
"""
accept_lang = request.headers.get("Accept-Language", "en")
primary = accept_lang.split(",")[0].strip()
if primary.lower().startswith("zh-hans"):
locale = "zh-Hans"
else:
locale = primary.split("-")[0] or "en"
locale = "zh-Hans" if primary.lower().startswith("zh-hans") else primary.split("-")[0] or "en"
request.state.locale = locale
return await call_next(request)