From 4e4e2ebd7adab0c9dc579b9aa896c6e8c8d1f96f Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Wed, 1 Jan 2025 22:18:34 +0900 Subject: [PATCH] =?UTF-8?q?fix!:=20Python=E3=81=AE`Synthesizer.metas`?= =?UTF-8?q?=E3=81=A8`UserDict.words`=E3=82=92=E9=9D=9E=E3=82=B2=E3=83=83?= =?UTF-8?q?=E3=82=BF=E3=83=BC=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../python/test/test_asyncio_metas.py | 2 +- .../test/test_asyncio_user_dict_manipulate.py | 18 +++++++++--------- .../python/test/test_blocking_metas.py | 2 +- .../test/test_blocking_user_dict_manipulate.py | 18 +++++++++--------- ...test_pseudo_raii_for_asyncio_synthesizer.py | 6 +++--- ...est_pseudo_raii_for_blocking_synthesizer.py | 6 +++--- .../python/voicevox_core/_rust/asyncio.pyi | 8 +++++--- .../python/voicevox_core/_rust/blocking.pyi | 8 +++++--- crates/voicevox_core_python_api/src/lib.rs | 4 ---- example/python/run-asyncio.py | 2 +- example/python/run.py | 2 +- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/crates/voicevox_core_python_api/python/test/test_asyncio_metas.py b/crates/voicevox_core_python_api/python/test/test_asyncio_metas.py index 3b6f857e3..a8ea5874a 100644 --- a/crates/voicevox_core_python_api/python/test/test_asyncio_metas.py +++ b/crates/voicevox_core_python_api/python/test/test_asyncio_metas.py @@ -21,7 +21,7 @@ async def test_synthesizer_metas_works(voice_model: VoiceModelFile) -> None: await OpenJtalk.new(conftest.open_jtalk_dic_dir), ) await synthesizer.load_voice_model(voice_model) - _ = synthesizer.metas + _ = synthesizer.metas() @pytest_asyncio.fixture diff --git a/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_manipulate.py b/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_manipulate.py index 493fade53..ab63268a8 100644 --- a/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_manipulate.py +++ b/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_manipulate.py @@ -27,8 +27,8 @@ async def test_user_dict_load() -> None: ) ) assert isinstance(uuid_a, UUID) - assert dict_a.words[uuid_a].surface == "hoge" - assert dict_a.words[uuid_a].pronunciation == "ホゲ" + assert dict_a.words()[uuid_a].surface == "hoge" + assert dict_a.words()[uuid_a].pronunciation == "ホゲ" # 単語の更新 dict_a.update_word( @@ -39,8 +39,8 @@ async def test_user_dict_load() -> None: ), ) - assert dict_a.words[uuid_a].surface == "fuga" - assert dict_a.words[uuid_a].pronunciation == "フガ" + assert dict_a.words()[uuid_a].surface == "fuga" + assert dict_a.words()[uuid_a].pronunciation == "フガ" # ユーザー辞書のインポート dict_b = voicevox_core.asyncio.UserDict() @@ -52,7 +52,7 @@ async def test_user_dict_load() -> None: ) dict_a.import_dict(dict_b) - assert uuid_b in dict_a.words + assert uuid_b in dict_a.words() # ユーザー辞書のエクスポート dict_c = voicevox_core.asyncio.UserDict() @@ -66,13 +66,13 @@ async def test_user_dict_load() -> None: os.close(temp_path_fd) await dict_c.save(temp_path) await dict_a.load(temp_path) - assert uuid_a in dict_a.words - assert uuid_c in dict_a.words + assert uuid_a in dict_a.words() + assert uuid_c in dict_a.words() # 単語の削除 dict_a.remove_word(uuid_a) - assert uuid_a not in dict_a.words - assert uuid_c in dict_a.words + assert uuid_a not in dict_a.words() + assert uuid_c in dict_a.words() # 単語のバリデーション with pytest.raises(pydantic.ValidationError): diff --git a/crates/voicevox_core_python_api/python/test/test_blocking_metas.py b/crates/voicevox_core_python_api/python/test/test_blocking_metas.py index a6aa6441d..5bb656b7a 100644 --- a/crates/voicevox_core_python_api/python/test/test_blocking_metas.py +++ b/crates/voicevox_core_python_api/python/test/test_blocking_metas.py @@ -19,7 +19,7 @@ def test_synthesizer_metas_works(voice_model: VoiceModelFile) -> None: OpenJtalk(conftest.open_jtalk_dic_dir), ) synthesizer.load_voice_model(voice_model) - _ = synthesizer.metas + _ = synthesizer.metas() @pytest.fixture diff --git a/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_manipulate.py b/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_manipulate.py index 23131ec49..44afccfe2 100644 --- a/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_manipulate.py +++ b/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_manipulate.py @@ -26,8 +26,8 @@ def test_user_dict_load() -> None: ) ) assert isinstance(uuid_a, UUID) - assert dict_a.words[uuid_a].surface == "hoge" - assert dict_a.words[uuid_a].pronunciation == "ホゲ" + assert dict_a.words()[uuid_a].surface == "hoge" + assert dict_a.words()[uuid_a].pronunciation == "ホゲ" # 単語の更新 dict_a.update_word( @@ -38,8 +38,8 @@ def test_user_dict_load() -> None: ), ) - assert dict_a.words[uuid_a].surface == "fuga" - assert dict_a.words[uuid_a].pronunciation == "フガ" + assert dict_a.words()[uuid_a].surface == "fuga" + assert dict_a.words()[uuid_a].pronunciation == "フガ" # ユーザー辞書のインポート dict_b = voicevox_core.blocking.UserDict() @@ -51,7 +51,7 @@ def test_user_dict_load() -> None: ) dict_a.import_dict(dict_b) - assert uuid_b in dict_a.words + assert uuid_b in dict_a.words() # ユーザー辞書のエクスポート dict_c = voicevox_core.blocking.UserDict() @@ -65,13 +65,13 @@ def test_user_dict_load() -> None: os.close(temp_path_fd) dict_c.save(temp_path) dict_a.load(temp_path) - assert uuid_a in dict_a.words - assert uuid_c in dict_a.words + assert uuid_a in dict_a.words() + assert uuid_c in dict_a.words() # 単語の削除 dict_a.remove_word(uuid_a) - assert uuid_a not in dict_a.words - assert uuid_c in dict_a.words + assert uuid_a not in dict_a.words() + assert uuid_c in dict_a.words() # 単語のバリデーション with pytest.raises(pydantic.ValidationError): diff --git a/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_asyncio_synthesizer.py b/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_asyncio_synthesizer.py index bfadf8471..46ad6e852 100644 --- a/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_asyncio_synthesizer.py +++ b/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_asyncio_synthesizer.py @@ -14,7 +14,7 @@ async def test_enter_returns_workable_self(synthesizer: Synthesizer) -> None: async with synthesizer as ctx: assert ctx is synthesizer - _ = synthesizer.metas + _ = synthesizer.metas() @pytest.mark.asyncio @@ -30,7 +30,7 @@ async def test_closing_multiple_times_is_allowed(synthesizer: Synthesizer) -> No async def test_access_after_close_denied(synthesizer: Synthesizer) -> None: await synthesizer.close() with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): - _ = synthesizer.metas + _ = synthesizer.metas() @pytest.mark.asyncio @@ -38,7 +38,7 @@ async def test_access_after_exit_denied(synthesizer: Synthesizer) -> None: async with synthesizer: pass with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): - _ = synthesizer.metas + _ = synthesizer.metas() @pytest_asyncio.fixture diff --git a/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_blocking_synthesizer.py b/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_blocking_synthesizer.py index dc55eafc4..06edec040 100644 --- a/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_blocking_synthesizer.py +++ b/crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_blocking_synthesizer.py @@ -12,7 +12,7 @@ def test_enter_returns_workable_self(synthesizer: Synthesizer) -> None: with synthesizer as ctx: assert ctx is synthesizer - _ = synthesizer.metas + _ = synthesizer.metas() def test_closing_multiple_times_is_allowed(synthesizer: Synthesizer) -> None: @@ -26,14 +26,14 @@ def test_closing_multiple_times_is_allowed(synthesizer: Synthesizer) -> None: def test_access_after_close_denied(synthesizer: Synthesizer) -> None: synthesizer.close() with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): - _ = synthesizer.metas + _ = synthesizer.metas() def test_access_after_exit_denied(synthesizer: Synthesizer) -> None: with synthesizer: pass with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): - _ = synthesizer.metas + _ = synthesizer.metas() @pytest.fixture diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi index 199ced742..1a748b8c8 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi @@ -43,7 +43,11 @@ class VoiceModelFile: ... @property def metas(self) -> List[SpeakerMeta]: - """メタ情報。""" + """ + メタ情報。 + + この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。 + """ ... async def __aenter__(self) -> "VoiceModelFile": ... async def __aexit__(self, exc_type, exc_value, traceback) -> None: ... @@ -181,7 +185,6 @@ class Synthesizer: def is_gpu_mode(self) -> bool: """ハードウェアアクセラレーションがGPUモードかどうか。""" ... - @property def metas(self) -> List[SpeakerMeta]: """メタ情報。""" ... @@ -427,7 +430,6 @@ class Synthesizer: class UserDict: """ユーザー辞書。""" - @property def words(self) -> Dict[UUID, UserDictWord]: """このオプジェクトの :class:`dict` としての表現。""" ... diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi index 2db76bc7a..120240efa 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi @@ -43,7 +43,11 @@ class VoiceModelFile: ... @property def metas(self) -> List[SpeakerMeta]: - """メタ情報。""" + """ + メタ情報。 + + この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。 + """ ... def __enter__(self) -> "VoiceModelFile": ... def __exit__(self, exc_type, exc_value, traceback) -> None: ... @@ -181,7 +185,6 @@ class Synthesizer: def is_gpu_mode(self) -> bool: """ハードウェアアクセラレーションがGPUモードかどうか。""" ... - @property def metas(self) -> List[SpeakerMeta]: """メタ情報。""" ... @@ -439,7 +442,6 @@ class Synthesizer: class UserDict: """ユーザー辞書。""" - @property def words(self) -> Dict[UUID, UserDictWord]: """このオプジェクトの :class:`dict` としての表現。""" ... diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index fc12a9712..b540c8ec5 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -532,7 +532,6 @@ mod blocking { Ok(synthesizer.is_gpu_mode()) } - #[getter] fn metas<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { let synthesizer = self.synthesizer.read()?; crate::convert::to_pydantic_voice_model_meta(&synthesizer.metas(), py) @@ -860,7 +859,6 @@ mod blocking { Ok(()) } - #[getter] fn words<'py>(&self, py: Python<'py>) -> PyResult<&'py PyDict> { let words = self.dict.with_words(|words| { words @@ -1129,7 +1127,6 @@ mod asyncio { Ok(synthesizer.is_gpu_mode()) } - #[getter] fn metas<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { let synthesizer = self.synthesizer.read()?; crate::convert::to_pydantic_voice_model_meta(&synthesizer.metas(), py) @@ -1520,7 +1517,6 @@ mod asyncio { Ok(()) } - #[getter] fn words<'py>(&self, py: Python<'py>) -> PyResult<&'py PyDict> { let words = self.dict.with_words(|words| { words diff --git a/example/python/run-asyncio.py b/example/python/run-asyncio.py index 3cb8a7e48..5d83593c2 100644 --- a/example/python/run-asyncio.py +++ b/example/python/run-asyncio.py @@ -100,7 +100,7 @@ async def main() -> None: ), # https://github.com/VOICEVOX/voicevox_core/issues/888 ) - logger.debug("%s", f"{synthesizer.metas=}") + logger.debug("%s", f"{synthesizer.metas()=}") logger.debug("%s", f"{synthesizer.is_gpu_mode=}") logger.info("%s", f"Loading `{args.vvm}`") diff --git a/example/python/run.py b/example/python/run.py index 5970f5dff..87b0ea85d 100644 --- a/example/python/run.py +++ b/example/python/run.py @@ -104,7 +104,7 @@ def main() -> None: ), # https://github.com/VOICEVOX/voicevox_core/issues/888 ) - logger.debug("%s", f"{synthesizer.metas=}") + logger.debug("%s", f"{synthesizer.metas()=}") logger.debug("%s", f"{synthesizer.is_gpu_mode=}") logger.info("%s", f"Loading `{args.vvm}`")