From 2327196fd4bdfd3f61c50657e26592e160c1d70d Mon Sep 17 00:00:00 2001 From: dev-bearabbit Date: Sun, 17 Nov 2024 14:02:15 +0900 Subject: [PATCH] add type hint and docstring --- Cargo.toml | 7 +++++-- src/lib.rs | 8 ++++++++ tossicat.pyi | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tossicat.pyi diff --git a/Cargo.toml b/Cargo.toml index c765564..30e6e2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "tossicat-python" -version = "0.1.2" +version = "0.1.3" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [lib] name = "tossicat" crate-type = ["cdylib"] @@ -11,3 +11,6 @@ crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.22.6", features = ["extension-module"] } tossicat = "0.6.1" + +[package.metadata.maturin] +include = ["tossicat.pyi"] diff --git a/src/lib.rs b/src/lib.rs index 55977ac..40a1d24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,9 @@ use pyo3::exceptions::PyValueError; use pyo3::prelude::*; #[pyfunction] +#[pyo3(text_signature = "(word, tossi)")] +/// The transform function takes two strings (word, tossi) as input and returns a tuple containing the word +/// and tossi transformed according to Korean grammar rules. pub fn transform(word: &str, tossi: &str) -> PyResult<(String, String)> { match ::tossicat::transform(word, tossi) { Ok(result) => Ok(result), @@ -12,6 +15,8 @@ pub fn transform(word: &str, tossi: &str) -> PyResult<(String, String)> { } #[pyfunction] +#[pyo3(text_signature = "(word, tossi)")] +/// The postfix function takes two strings (word, tossi) as input and returns the appropriate tossi. pub fn postfix(word: &str, tossi: &str) -> PyResult { match ::tossicat::postfix(word, tossi) { Ok(result) => Ok(result), @@ -22,6 +27,9 @@ pub fn postfix(word: &str, tossi: &str) -> PyResult { } #[pyfunction] +#[pyo3(text_signature = "(sentence)")] +/// The modify_sentence function takes a sentence containing {word, tossi} templates as input +/// and returns a modified sentence with the templates properly adjusted. pub fn modify_sentence(sentence: &str) -> PyResult { match ::tossicat::modify_sentence(sentence) { Ok(result) => Ok(result), diff --git a/tossicat.pyi b/tossicat.pyi new file mode 100644 index 0000000..34c804b --- /dev/null +++ b/tossicat.pyi @@ -0,0 +1,9 @@ +# tossicat.pyi + +from typing import Tuple + +def transform(word: str, tossi: str) -> Tuple[str, str]: ... + +def postfix(word: str, tossi: str) -> str: ... + +def modify_sentence(sentence: str) -> str: ...