Skip to content

Commit 9ded115

Browse files
committed
inline unnecessary IssueWriter class
1 parent cbc5db8 commit 9ded115

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

PythonScripts/audit_translations/auditor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
and for performing full language audits.
66
"""
77

8+
import json
89
import sys
910
from pathlib import Path
1011
from typing import List, Optional, TextIO, Tuple
@@ -14,7 +15,7 @@
1415

1516
from .dataclasses import RuleInfo, ComparisonResult
1617
from .parsers import parse_yaml_file, diff_rules
17-
from .renderer import IssueWriter, collect_issues, console, print_warnings
18+
from .renderer import collect_issues, console, print_warnings
1819

1920
# Re-export console so existing `from .auditor import console` callers keep working.
2021
__all__ = ["console"]
@@ -192,8 +193,6 @@ def audit_language(
192193
if output_path:
193194
out_stream = open(output_path, "w", encoding="utf-8", newline="")
194195

195-
writer = IssueWriter(output_format, out_stream) if output_format != "rich" else None
196-
197196
total_issues = 0
198197
total_missing = 0
199198
total_untranslated = 0
@@ -231,7 +230,7 @@ def audit_language(
231230
else:
232231
issues_list = collect_issues(result, file_name, language)
233232
for issue in issues_list:
234-
writer.write(issue)
233+
out_stream.write(json.dumps(issue, ensure_ascii=False) + "\n")
235234
if issues_list:
236235
files_with_issues += 1
237236
total_issues += len(issues_list)

PythonScripts/audit_translations/renderer.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import json
99
from pathlib import Path
10-
from typing import Any, Dict, List, TextIO, Tuple
10+
from typing import Any, Dict, List, Tuple
1111

1212
from rich.console import Console
1313
from rich.markup import escape
@@ -157,16 +157,6 @@ def collect_issues(
157157
return issues
158158

159159

160-
class IssueWriter:
161-
def __init__(self, output_format: str, stream: TextIO):
162-
if output_format != "jsonl":
163-
raise ValueError(f"Unsupported output format: {output_format}")
164-
self.stream = stream
165-
166-
def write(self, issue: dict) -> None:
167-
self.stream.write(json.dumps(issue, ensure_ascii=False) + "\n")
168-
169-
170160
def print_warnings(
171161
result: ComparisonResult,
172162
file_name: str,

PythonScripts/audit_translations/tests/test_output_jsonl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66

77
from ..auditor import compare_files
8-
from ..renderer import IssueWriter, collect_issues
8+
from ..renderer import collect_issues
99

1010

1111
def load_jsonl(text: str) -> list[dict]:
@@ -27,16 +27,14 @@ def test_jsonl_output_matches_golden():
2727
files = sorted(path.name for path in english_dir.glob("*.yaml"))
2828

2929
stream = StringIO()
30-
writer = IssueWriter("jsonl", stream)
3130

3231
for file_name in files:
3332
result = compare_files(
3433
str(english_dir / file_name),
3534
str(translated_dir / file_name),
3635
)
37-
issues = collect_issues(result, file_name, "de")
38-
for issue in issues:
39-
writer.write(issue)
36+
for issue in collect_issues(result, file_name, "de"):
37+
stream.write(json.dumps(issue, ensure_ascii=False) + "\n")
4038

4139
actual = load_jsonl(stream.getvalue())
4240

0 commit comments

Comments
 (0)