From 4345772882bd4a87511ac136e8906b38c77581c1 Mon Sep 17 00:00:00 2001 From: mh-northlander Date: Fri, 7 Jun 2024 09:09:16 +0900 Subject: [PATCH] use pyo3::intern macro inside pretokenizer --- python/src/dictionary.rs | 10 +++++++--- python/src/pretokenizer.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python/src/dictionary.rs b/python/src/dictionary.rs index 251267ab..e9cbf1ed 100644 --- a/python/src/dictionary.rs +++ b/python/src/dictionary.rs @@ -461,20 +461,24 @@ fn read_config(config_opt: &Bound) -> PyResult { } pub(crate) fn read_default_config(py: Python) -> PyResult { - let path = PyModule::import_bound(py, "sudachipy")?.getattr("_DEFAULT_SETTINGFILE")?; + let path = py + .import_bound("sudachipy")? + .getattr("_DEFAULT_SETTINGFILE")?; let path = path.downcast::()?.to_str()?; let path = PathBuf::from(path); wrap_ctx(ConfigBuilder::from_opt_file(Some(&path)), &path) } pub(crate) fn get_default_resource_dir(py: Python) -> PyResult { - let path = PyModule::import_bound(py, "sudachipy")?.getattr("_DEFAULT_RESOURCEDIR")?; + let path = py + .import_bound("sudachipy")? + .getattr("_DEFAULT_RESOURCEDIR")?; let path = path.downcast::()?.to_str()?; Ok(PathBuf::from(path)) } fn find_dict_path(py: Python, dict_type: &str) -> PyResult { - let pyfunc = PyModule::import_bound(py, "sudachipy")?.getattr("_find_dict_path")?; + let pyfunc = py.import_bound("sudachipy")?.getattr("_find_dict_path")?; let path = pyfunc.call1((dict_type,))?; let path = path.downcast::()?.to_str()?; Ok(PathBuf::from(path)) diff --git a/python/src/pretokenizer.rs b/python/src/pretokenizer.rs index cd15b1b3..20e5cf65 100644 --- a/python/src/pretokenizer.rs +++ b/python/src/pretokenizer.rs @@ -163,7 +163,7 @@ impl PyPretokenizer { py: Python<'py>, data: &Bound<'py, PyAny>, ) -> PyResult> { - data.call_method1("split", PyTuple::new_bound(py, [self_])) + data.call_method1(intern!(py, "split"), PyTuple::new_bound(py, [self_])) } } @@ -190,7 +190,7 @@ fn make_result_for_projection<'py>( ) -> PyResult> { let result = PyList::empty_bound(py); let nstring = { - static NORMALIZED_STRING: GILOnceCell> = pyo3::sync::GILOnceCell::new(); + static NORMALIZED_STRING: GILOnceCell> = GILOnceCell::new(); NORMALIZED_STRING.get_or_try_init(py, || -> PyResult> { let ns = py.import_bound("tokenizers")?.getattr("NormalizedString")?; let tpe = ns.downcast::()?;