1- use pyo3:: { exceptions:: PyValueError , prelude:: * , types:: PyUnicode } ;
1+ use pyo3:: { exceptions:: PyValueError , prelude:: * , types:: PyString } ;
22
33use :: daachorse:: {
44 CharwiseDoubleArrayAhoCorasick , CharwiseDoubleArrayAhoCorasickBuilder , MatchKind ,
@@ -19,22 +19,19 @@ use ::daachorse::{
1919/// :type match_kind: int
2020/// :rtype: daachorse.Automaton
2121#[ pyclass]
22- #[ pyo3( text_signature = "(patterns, /, match_kind = daachorse.MATCH_KIND_STANDARD)" ) ]
2322struct Automaton {
2423 pma : CharwiseDoubleArrayAhoCorasick < usize > ,
2524 match_kind : MatchKind ,
26- patterns : Vec < Py < PyUnicode > > ,
25+ patterns : Vec < Py < PyString > > ,
2726}
2827
2928#[ pymethods]
3029impl Automaton {
3130 #[ new]
32- #[ args( match_kind = "0" ) ]
33- fn new ( py : Python , patterns : Vec < Py < PyUnicode > > , match_kind : u8 ) -> PyResult < Self > {
34- let raw_patterns: PyResult < Vec < String > > = patterns
35- . iter ( )
36- . map ( |pat| pat. as_ref ( py) . extract ( ) )
37- . collect ( ) ;
31+ #[ pyo3( signature = ( patterns, /, match_kind = 0 ) ) ]
32+ fn new ( py : Python , patterns : Vec < Py < PyString > > , match_kind : u8 ) -> PyResult < Self > {
33+ let raw_patterns: PyResult < Vec < String > > =
34+ patterns. iter ( ) . map ( |pat| pat. extract ( py) ) . collect ( ) ;
3835 let raw_patterns = raw_patterns?;
3936 let match_kind = MatchKind :: from ( match_kind) ;
4037 Ok ( Self {
@@ -142,7 +139,7 @@ impl Automaton {
142139 /// :type haystack: str
143140 /// :rtype: list[str]
144141 #[ pyo3( text_signature = "($self, haystack, /)" ) ]
145- fn find_as_strings ( self_ : PyRef < Self > , haystack : & str ) -> PyResult < Vec < Py < PyUnicode > > > {
142+ fn find_as_strings ( self_ : PyRef < Self > , haystack : & str ) -> PyResult < Vec < Py < PyString > > > {
146143 let match_kind = self_. match_kind ;
147144 let py = self_. py ( ) ;
148145 let pma = & self_. pma ;
@@ -222,7 +219,7 @@ impl Automaton {
222219 fn find_overlapping_as_strings (
223220 self_ : PyRef < Self > ,
224221 haystack : & str ,
225- ) -> PyResult < Vec < Py < PyUnicode > > > {
222+ ) -> PyResult < Vec < Py < PyString > > > {
226223 if self_. match_kind != MatchKind :: Standard {
227224 return Err ( PyValueError :: new_err ( "match_kind must be STANDARD" ) ) ;
228225 }
@@ -314,7 +311,7 @@ impl Automaton {
314311 fn find_overlapping_no_suffix_as_strings (
315312 self_ : PyRef < Self > ,
316313 haystack : & str ,
317- ) -> PyResult < Vec < Py < PyUnicode > > > {
314+ ) -> PyResult < Vec < Py < PyString > > > {
318315 if self_. match_kind != MatchKind :: Standard {
319316 return Err ( PyValueError :: new_err ( "match_kind must be STANDARD" ) ) ;
320317 }
@@ -333,7 +330,7 @@ impl Automaton {
333330}
334331
335332#[ pymodule]
336- fn daachorse ( _py : Python , m : & PyModule ) -> PyResult < ( ) > {
333+ fn daachorse ( _py : Python , m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
337334 m. add_class :: < Automaton > ( ) ?;
338335 m. add ( "MATCH_KIND_STANDARD" , MatchKind :: Standard as u8 ) ?;
339336 m. add (
0 commit comments