Skip to content

Commit

Permalink
__getattr__から誘導する
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 25, 2025
1 parent 04dadbd commit 31b8dea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/voicevox_core_python_api/python/voicevox_core/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""ユーザー辞書の単語の品詞。"""
Expand Down

0 comments on commit 31b8dea

Please sign in to comment.