diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_models.py b/crates/voicevox_core_python_api/python/voicevox_core/_models.py index dfbb2d702..1a0942062 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_models.py +++ b/crates/voicevox_core_python_api/python/voicevox_core/_models.py @@ -249,12 +249,20 @@ def __post_init__(self) -> None: としてのフィールドをハックする。 """ + self.__attr_names: dict[str, str] = {} for field in dataclasses.fields(self): rename = _rename_audio_query_field(field.name) if rename != field.name: - setattr(self, rename, getattr(self, field.name)) + self.__attr_names[rename] = field.name field.name = rename + def __getattr__(self, name: str) -> object: + """camelCaseの名前に対し、対応するsnake_caseの名前があるならそれについて返す。""" + + if attr_name := self.__attr_names.get(name): + return getattr(self, attr_name) + raise AttributeError(f"{type(self).__name__!r} has no attribute {name!r}") + class UserDictWordType(str, Enum): """ユーザー辞書の単語の品詞。"""