@@ -19,6 +19,7 @@ use std::ops::Deref;
1919use std:: sync:: Arc ;
2020
2121use pyo3:: exceptions:: PyIndexError ;
22+ use pyo3:: ffi:: c_str;
2223use pyo3:: prelude:: * ;
2324use pyo3:: types:: { PyList , PyString , PyTuple , PyType } ;
2425
@@ -101,7 +102,7 @@ impl PyMorphemeListWrapper {
101102fn empty ( _cls : & Bound < PyType > , py : Python , dict : & PyDictionary ) ->PyResult < Self > {
102103 errors:: warn_deprecation (
103104 py,
104- "Use Tokenizer.tokenize(\" \" ) if you need an empty MorphemeList." ,
105+ c_str ! ( "Use Tokenizer.tokenize(\" \" ) if you need an empty MorphemeList." ) ,
105106) ?;
106107
107108let cloned = dict. dictionary . as_ref ( ) . unwrap ( ) . clone ( ) ;
@@ -165,7 +166,7 @@ impl PyMorphemeListWrapper {
165166 result. push ( ' ' ) ;
166167}
167168}
168- PyString :: new_bound ( py, result. as_str ( ) )
169+ PyString :: new ( py, result. as_str ( ) )
169170}
170171
171172fn __repr__ ( slf : Py < PyMorphemeListWrapper > , py : Python ) ->PyResult < Bound < PyString > > {
@@ -184,7 +185,7 @@ impl PyMorphemeListWrapper {
184185 result. push_str ( ",\n " ) ;
185186}
186187 result. push_str ( "]>" ) ;
187- Ok ( PyString :: new_bound ( py, result. as_str ( ) ) )
188+ Ok ( PyString :: new ( py, result. as_str ( ) ) )
188189}
189190
190191fn __iter__ ( slf : Py < Self > ) ->PyMorphemeIter {
@@ -301,7 +302,7 @@ impl PyMorpheme {
301302let list =self . list ( py) ;
302303let morph =self . morph ( py) ;
303304match list. projection ( ) {
304- None =>PyString :: new_bound ( py, morph. surface ( ) . deref ( ) ) ,
305+ None =>PyString :: new ( py, morph. surface ( ) . deref ( ) ) ,
305306Some ( proj) => proj. project ( morph. deref ( ) , py) ,
306307}
307308}
@@ -311,7 +312,7 @@ impl PyMorpheme {
311312/// See `Config.projection`.
312313#[ pyo3( text_signature ="(self, /) -> str" ) ]
313314fn raw_surface < ' py > ( & ' py self , py : Python < ' py > ) ->Bound < ' py , PyString > {
314- PyString :: new_bound ( py, self . morph ( py) . surface ( ) . deref ( ) )
315+ PyString :: new ( py, self . morph ( py) . surface ( ) . deref ( ) )
315316}
316317
317318/// Returns the part of speech as a six-element tuple.
@@ -334,20 +335,32 @@ impl PyMorpheme {
334335
335336/// Returns the dictionary form.
336337#[ pyo3( text_signature ="(self, /) -> str" ) ]
337- fn dictionary_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyObject {
338- self . morph ( py) . get_word_info ( ) . dictionary_form ( ) . into_py ( py)
338+ fn dictionary_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyResult < Bound < PyString > > {
339+ Ok ( self
340+ . morph ( py)
341+ . get_word_info ( )
342+ . dictionary_form ( )
343+ . into_pyobject ( py) ?)
339344}
340345
341346/// Returns the normalized form.
342347#[ pyo3( text_signature ="(self, /) -> str" ) ]
343- fn normalized_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyObject {
344- self . morph ( py) . get_word_info ( ) . normalized_form ( ) . into_py ( py)
348+ fn normalized_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyResult < Bound < PyString > > {
349+ Ok ( self
350+ . morph ( py)
351+ . get_word_info ( )
352+ . normalized_form ( )
353+ . into_pyobject ( py) ?)
345354}
346355
347356/// Returns the reading form.
348357#[ pyo3( text_signature ="(self, /) -> str" ) ]
349- fn reading_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyObject {
350- self . morph ( py) . get_word_info ( ) . reading_form ( ) . into_py ( py)
358+ fn reading_form < ' py > ( & ' py self , py : Python < ' py > ) ->PyResult < Bound < PyString > > {
359+ Ok ( self
360+ . morph ( py)
361+ . get_word_info ( )
362+ . reading_form ( )
363+ . into_pyobject ( py) ?)
351364}
352365
353366/// Returns sub-morphemes in the provided split mode.
@@ -431,10 +444,10 @@ impl PyMorpheme {
431444
432445/// Returns the list of synonym group ids.
433446#[ pyo3( text_signature ="(self, /) -> List[int]" ) ]
434- fn synonym_group_ids < ' py > ( & ' py self , py : Python < ' py > ) ->Bound < PyList > {
447+ fn synonym_group_ids < ' py > ( & ' py self , py : Python < ' py > ) ->PyResult < Bound < PyList > > {
435448let mref =self . morph ( py) ;
436449let ids = mref. get_word_info ( ) . synonym_group_ids ( ) ;
437- PyList :: new_bound ( py, ids)
450+ PyList :: new ( py, ids)
438451}
439452
440453/// Returns the word info.
@@ -443,7 +456,7 @@ impl PyMorpheme {
443456/// Users should not touch the raw WordInfo.
444457#[ pyo3( text_signature ="(self, /) -> WordInfo" ) ]
445458fn get_word_info ( & self , py : Python ) ->PyResult < PyWordInfo > {
446- errors:: warn_deprecation ( py, "Users should not touch the raw WordInfo." ) ?;
459+ errors:: warn_deprecation ( py, c_str ! ( "Users should not touch the raw WordInfo." ) ) ?;
447460Ok ( self . morph ( py) . get_word_info ( ) . clone ( ) . into ( ) )
448461}
449462