Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: PythonのSynthesizer.metasUserDict.wordsを非ゲッターに #914

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,15 +30,15 @@ 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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -181,7 +185,6 @@ class Synthesizer:
def is_gpu_mode(self) -> bool:
"""ハードウェアアクセラレーションがGPUモードかどうか。"""
...
@property
def metas(self) -> List[SpeakerMeta]:
"""メタ情報。"""
...
Expand Down Expand Up @@ -427,7 +430,6 @@ class Synthesizer:
class UserDict:
"""ユーザー辞書。"""

@property
def words(self) -> Dict[UUID, UserDictWord]:
"""このオプジェクトの :class:`dict` としての表現。"""
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -181,7 +185,6 @@ class Synthesizer:
def is_gpu_mode(self) -> bool:
"""ハードウェアアクセラレーションがGPUモードかどうか。"""
...
@property
def metas(self) -> List[SpeakerMeta]:
"""メタ情報。"""
...
Expand Down Expand Up @@ -439,7 +442,6 @@ class Synthesizer:
class UserDict:
"""ユーザー辞書。"""

@property
def words(self) -> Dict[UUID, UserDictWord]:
"""このオプジェクトの :class:`dict` としての表現。"""
...
Expand Down
4 changes: 0 additions & 4 deletions crates/voicevox_core_python_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/python/run-asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}`")
Expand Down
2 changes: 1 addition & 1 deletion example/python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}`")
Expand Down
Loading