From a07e449ceba3042b086b989be3573918f21b9e74 Mon Sep 17 00:00:00 2001 From: mh-northlander Date: Thu, 14 Oct 2021 17:55:54 +0900 Subject: [PATCH] Add deprecation warning --- python/src/morpheme.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/python/src/morpheme.rs b/python/src/morpheme.rs index cd26ca68..f2736351 100644 --- a/python/src/morpheme.rs +++ b/python/src/morpheme.rs @@ -58,13 +58,16 @@ impl PyMorphemeListWrapper { /// Returns an empty morpheme list with dictionary #[classmethod] #[pyo3(text_signature = "(dict)")] - fn empty(_cls: &PyType, dict: &PyDictionary) -> Self { - Self { + fn empty(_cls: &PyType, py: Python, dict: &PyDictionary) -> PyResult { + let cat = PyModule::import(py, "builtins")?.getattr("DeprecationWarning")?; + PyErr::warn(py, cat, "Users should not generate MorphemeList by themselves. Use Tokenizer.tokenize(\"\") if you need.", 1)?; + + Ok(Self { inner: Arc::new(PyMorphemeList { list: MorphemeList::empty(dict.dictionary.as_ref().unwrap().clone()), boundaries: Vec::new(), }), - } + }) } /// Returns the total cost of the path @@ -255,7 +258,15 @@ impl PyMorpheme { /// Returns a list of morphemes splitting itself with given split mode #[pyo3(text_signature = "($self, mode, /)")] - fn split(&self, mode: PySplitMode) -> PyResult { + fn split(&self, py: Python, mode: PySplitMode) -> PyResult { + let cat = PyModule::import(py, "builtins")?.getattr("DeprecationWarning")?; + PyErr::warn( + py, + cat, + "API around this functionality will change. See github issue #92 for more.", + 1, + )?; + Ok(self .list .split(mode.into(), self.index) @@ -292,7 +303,10 @@ impl PyMorpheme { /// Returns the word info #[pyo3(text_signature = "($self)")] - fn get_word_info(&self) -> PyWordInfo { - self.list.get_word_info(self.index).clone().into() + fn get_word_info(&self, py: Python) -> PyResult { + let cat = PyModule::import(py, "builtins")?.getattr("DeprecationWarning")?; + PyErr::warn(py, cat, "Users should not touch the raw WordInfo.", 1)?; + + Ok(self.list.get_word_info(self.index).clone().into()) } }