From 48d177e215d7ea1ff07ae6a598d222505ecf3313 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 8 Feb 2025 23:22:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[Python]=20=E3=80=8C=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E3=80=8D=E3=81=AB=E3=81=A4=E3=81=84?= =?UTF-8?q?=E3=81=A6=E3=82=B1=E3=82=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../python/voicevox_core/_rust/asyncio.pyi | 8 +++- .../python/voicevox_core/_rust/blocking.pyi | 8 +++- crates/voicevox_core_python_api/src/lib.rs | 47 +++++++++++++++++-- 3 files changed, 58 insertions(+), 5 deletions(-) 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 ec4070e88..619b3e2e5 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 @@ -1,5 +1,5 @@ from os import PathLike -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, NoReturn, Union from uuid import UUID if TYPE_CHECKING: @@ -18,6 +18,9 @@ class VoiceModelFile: """ 音声モデルファイル。""" + def __new__( + cls, *args: tuple[object], **kwargs: dict[object, object] + ) -> NoReturn: ... @staticmethod async def open(path: str | PathLike[str]) -> VoiceModelFile: """ @@ -95,6 +98,9 @@ class Onnxruntime: LIB_UNVERSIONED_FILENAME: str """:attr:`LIB_NAME` からなる動的ライブラリのファイル名。""" + def __new__( + cls, *args: tuple[object], **kwargs: dict[object, object] + ) -> NoReturn: ... @staticmethod def get() -> Union["Onnxruntime", None]: """ 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 d6484dc51..ff5316b66 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 @@ -1,5 +1,5 @@ from os import PathLike -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, NoReturn, Union from uuid import UUID if TYPE_CHECKING: @@ -18,6 +18,9 @@ class VoiceModelFile: """ 音声モデルファイル。""" + def __new__( + cls, *args: tuple[object], **kwargs: dict[object, object] + ) -> NoReturn: ... @staticmethod def open(path: str | PathLike[str]) -> VoiceModelFile: """ @@ -95,6 +98,9 @@ class Onnxruntime: LIB_UNVERSIONED_FILENAME: str """:attr:`LIB_NAME` からなる動的ライブラリのファイル名。""" + def __new__( + cls, *args: tuple[object], **kwargs: dict[object, object] + ) -> NoReturn: ... @staticmethod def get() -> Union["Onnxruntime", None]: """ diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index 26d580285..7200fc3a1 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -294,9 +294,9 @@ mod blocking { use camino::Utf8PathBuf; use pyo3::{ - exceptions::{PyIndexError, PyValueError}, + exceptions::{PyIndexError, PyTypeError, PyValueError}, pyclass, pymethods, - types::{IntoPyDict as _, PyBytes, PyDict, PyList}, + types::{IntoPyDict as _, PyBytes, PyDict, PyList, PyTuple, PyType}, Py, PyAny, PyObject, PyRef, PyResult, Python, }; use uuid::Uuid; @@ -316,6 +316,16 @@ mod blocking { #[pymethods] impl VoiceModelFile { + #[new] + #[classmethod] + #[pyo3(signature = (*_args, **_kwargs))] + fn new(_cls: &PyType, _args: &PyTuple, _kwargs: Option<&PyDict>) -> PyResult { + Err(PyTypeError::new_err(( + "`VoiceModelFile` does not have a normal constructor. Use \ + `VoiceModelFile.load_once` to construct", + ))) + } + #[staticmethod] fn open(py: Python<'_>, path: PathBuf) -> PyResult { let model = voicevox_core::blocking::VoiceModelFile::open(path).into_py_result(py)?; @@ -384,6 +394,16 @@ mod blocking { const LIB_UNVERSIONED_FILENAME: &'static str = voicevox_core::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME; + #[new] + #[classmethod] + #[pyo3(signature = (*_args, **_kwargs))] + fn new(_cls: &PyType, _args: &PyTuple, _kwargs: Option<&PyDict>) -> PyResult { + Err(PyTypeError::new_err(( + "`Onnxruntime` does not have a normal constructor. Use `Onnxruntime.load_once` or \ + `Onnxruntime.get` to construct", + ))) + } + #[staticmethod] fn get(py: Python<'_>) -> PyResult>> { let result = ONNXRUNTIME.get_or_try_init(|| { @@ -883,8 +903,9 @@ mod asyncio { use camino::Utf8PathBuf; use pyo3::{ + exceptions::PyTypeError, pyclass, pymethods, - types::{IntoPyDict as _, PyBytes, PyDict, PyList}, + types::{IntoPyDict as _, PyBytes, PyDict, PyList, PyTuple, PyType}, Py, PyAny, PyErr, PyObject, PyRef, PyResult, Python, ToPyObject as _, }; use uuid::Uuid; @@ -904,6 +925,16 @@ mod asyncio { #[pymethods] impl VoiceModelFile { + #[new] + #[classmethod] + #[pyo3(signature = (*_args, **_kwargs))] + fn new(_cls: &PyType, _args: &PyTuple, _kwargs: Option<&PyDict>) -> PyResult { + Err(PyTypeError::new_err(( + "`VoiceModelFile` does not have a normal constructor. Use \ + `VoiceModelFile.load_once` to construct", + ))) + } + #[staticmethod] fn open(py: Python<'_>, path: PathBuf) -> PyResult<&PyAny> { pyo3_asyncio::tokio::future_into_py(py, async move { @@ -986,6 +1017,16 @@ mod asyncio { const LIB_UNVERSIONED_FILENAME: &'static str = voicevox_core::nonblocking::Onnxruntime::LIB_UNVERSIONED_FILENAME; + #[new] + #[classmethod] + #[pyo3(signature = (*_args, **_kwargs))] + fn new(_cls: &PyType, _args: &PyTuple, _kwargs: Option<&PyDict>) -> PyResult { + Err(PyTypeError::new_err(( + "`Onnxruntime` does not have a normal constructor. Use `Onnxruntime.load_once` or \ + `Onnxruntime.get` to construct", + ))) + } + #[staticmethod] fn get(py: Python<'_>) -> PyResult>> { let result =