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

Add deprecation warning #97

Merged
Merged
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
26 changes: 20 additions & 6 deletions python/src/morpheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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
Expand Down Expand Up @@ -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<PyMorphemeListWrapper> {
fn split(&self, py: Python, mode: PySplitMode) -> PyResult<PyMorphemeListWrapper> {
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)
Expand Down Expand Up @@ -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<PyWordInfo> {
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())
}
}