mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-26 17:02:19 +08:00
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:
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user