From 31b8deacbfdbc22242f9fe068627a12465501f45 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 26 Jan 2025 06:11:03 +0900 Subject: [PATCH] =?UTF-8?q?`=5F=5Fgetattr=5F=5F`=E3=81=8B=E3=82=89?= =?UTF-8?q?=E8=AA=98=E5=B0=8E=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/VOICEVOX/voicevox_core/pull/946#discussion_r1929606669 --- .../python/voicevox_core/_models.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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): """ユーザー辞書の単語の品詞。"""