Make the module-level helpers private instead of protected
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,7 @@ def parse_args(argv: list[str] | None) -> argparse.Namespace:
|
|||||||
return parser.parse_args(argv)
|
return parser.parse_args(argv)
|
||||||
|
|
||||||
|
|
||||||
def _no_duplicate_keys(
|
def __no_duplicate_keys(
|
||||||
pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
||||||
"""Build a dict from JSON object pairs, rejecting duplicates.
|
"""Build a dict from JSON object pairs, rejecting duplicates.
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ def _no_duplicate_keys(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _load_json_object(path: Path, label: str) -> dict[str, Any]:
|
def __load_json_object(path: Path, label: str) -> dict[str, Any]:
|
||||||
"""Load a single JSON object from a file, in file order.
|
"""Load a single JSON object from a file, in file order.
|
||||||
|
|
||||||
:param path: The JSON file.
|
:param path: The JSON file.
|
||||||
@@ -104,7 +104,7 @@ def _load_json_object(path: Path, label: str) -> dict[str, Any]:
|
|||||||
text: str = file.read()
|
text: str = file.read()
|
||||||
try:
|
try:
|
||||||
data: Any = json.loads(
|
data: Any = json.loads(
|
||||||
text, object_pairs_hook=_no_duplicate_keys)
|
text, object_pairs_hook=__no_duplicate_keys)
|
||||||
except json.JSONDecodeError as error:
|
except json.JSONDecodeError as error:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"invalid JSON in {label} file {path}: {error}") \
|
f"invalid JSON in {label} file {path}: {error}") \
|
||||||
@@ -124,7 +124,7 @@ def load_extras(path: Path) -> dict[str, Any]:
|
|||||||
:raises ValueError: When the file is not valid JSON, is not
|
:raises ValueError: When the file is not valid JSON, is not
|
||||||
a JSON object, has duplicate keys, or has a "lyrics" key.
|
a JSON object, has duplicate keys, or has a "lyrics" key.
|
||||||
"""
|
"""
|
||||||
data: dict[str, Any] = _load_json_object(path, "extras")
|
data: dict[str, Any] = __load_json_object(path, "extras")
|
||||||
if "lyrics" in data:
|
if "lyrics" in data:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"extras file {path} must not have a \"lyrics\" key")
|
f"extras file {path} must not have a \"lyrics\" key")
|
||||||
@@ -143,7 +143,7 @@ def load_extras_per_id(path: Path) -> dict[str, dict[str, Any]]:
|
|||||||
a JSON object, has duplicate keys, has a song whose value
|
a JSON object, has duplicate keys, has a song whose value
|
||||||
is not a JSON object, or has a song with a "lyrics" key.
|
is not a JSON object, or has a song with a "lyrics" key.
|
||||||
"""
|
"""
|
||||||
data: dict[str, Any] = _load_json_object(path, "per-ID extras")
|
data: dict[str, Any] = __load_json_object(path, "per-ID extras")
|
||||||
song_id: str
|
song_id: str
|
||||||
extras: Any
|
extras: Any
|
||||||
for song_id, extras in data.items():
|
for song_id, extras in data.items():
|
||||||
@@ -158,7 +158,7 @@ def load_extras_per_id(path: Path) -> dict[str, dict[str, Any]]:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def _build_content(
|
def __build_content(
|
||||||
lyrics: str,
|
lyrics: str,
|
||||||
extras: dict[str, Any] | None,
|
extras: dict[str, Any] | None,
|
||||||
song_extras: dict[str, Any] | None) -> str:
|
song_extras: dict[str, Any] | None) -> str:
|
||||||
@@ -229,7 +229,7 @@ def build_lines(
|
|||||||
f"song {song.id} \"{song.title}\": no lyrics")
|
f"song {song.id} \"{song.title}\": no lyrics")
|
||||||
song_extras: dict[str, Any] | None = None \
|
song_extras: dict[str, Any] | None = None \
|
||||||
if extras_per_id is None else extras_per_id[song_id]
|
if extras_per_id is None else extras_per_id[song_id]
|
||||||
content: str = _build_content(
|
content: str = __build_content(
|
||||||
song.lyrics, extras, song_extras)
|
song.lyrics, extras, song_extras)
|
||||||
record: dict[str, str] = {
|
record: dict[str, str] = {
|
||||||
"id": song_id, "content": content}
|
"id": song_id, "content": content}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ SLEEP_SECONDS: float = 1.0
|
|||||||
"""The delay between consecutive HTTP requests, in seconds."""
|
"""The delay between consecutive HTTP requests, in seconds."""
|
||||||
|
|
||||||
|
|
||||||
def _build_normalization() -> dict[int, str | None]:
|
def __build_normalization() -> dict[int, str | None]:
|
||||||
"""Build the lyrics normalization translation table.
|
"""Build the lyrics normalization translation table.
|
||||||
|
|
||||||
:return: The codepoint-to-replacement mapping, a replacement
|
:return: The codepoint-to-replacement mapping, a replacement
|
||||||
@@ -79,7 +79,7 @@ def _build_normalization() -> dict[int, str | None]:
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
NORMALIZATION: dict[int, str | None] = _build_normalization()
|
NORMALIZATION: dict[int, str | None] = __build_normalization()
|
||||||
"""The codepoint-to-replacement mapping applied to fetched
|
"""The codepoint-to-replacement mapping applied to fetched
|
||||||
lyrics: cp1252-mojibake restoration for U+0080-U+009F (with the
|
lyrics: cp1252-mojibake restoration for U+0080-U+009F (with the
|
||||||
five byte values undefined in cp1252 removed), homoglyph
|
five byte values undefined in cp1252 removed), homoglyph
|
||||||
|
|||||||
Reference in New Issue
Block a user