@@ -8,9 +8,9 @@ use std::sync::{Arc, Mutex};
8
8
use std:: thread:: sleep;
9
9
use std:: time:: { Duration , SystemTime } ;
10
10
11
- use pyo3:: create_exception;
12
- use pyo3:: exceptions:: { PyFileNotFoundError , PyOSError , PyPermissionError , PyRuntimeError , PyTypeError } ;
11
+ use pyo3:: exceptions:: { PyFileNotFoundError , PyOSError , PyPermissionError , PyRuntimeError } ;
13
12
use pyo3:: prelude:: * ;
13
+ use pyo3:: { create_exception, intern} ;
14
14
15
15
use notify:: event:: { Event , EventKind , ModifyKind , RenameMode } ;
16
16
use notify:: {
@@ -243,7 +243,7 @@ impl RustNotify {
243
243
} )
244
244
}
245
245
246
- pub fn watch (
246
+ fn watch (
247
247
slf : & Bound < Self > ,
248
248
py : Python ,
249
249
debounce_ms : u64 ,
@@ -256,14 +256,7 @@ impl RustNotify {
256
256
}
257
257
let stop_event_is_set: Option < Bound < PyAny > > = match stop_event. is_none ( py) {
258
258
true => None ,
259
- false => {
260
- let func = stop_event. getattr ( py, "is_set" ) ?. into_bound ( py) ;
261
- if !func. is_callable ( ) {
262
- return Err ( PyTypeError :: new_err ( "'stop_event.is_set' must be callable" ) ) ;
263
- }
264
-
265
- Some ( func)
266
- }
259
+ false => Some ( stop_event. getattr ( py, intern ! ( py, "is_set" ) ) ?. into_bound ( py) ) ,
267
260
} ;
268
261
269
262
let mut max_debounce_time: Option < SystemTime > = None ;
@@ -279,7 +272,7 @@ impl RustNotify {
279
272
Ok ( _) => ( ) ,
280
273
Err ( _) => {
281
274
slf. borrow ( ) . clear ( ) ;
282
- return Ok ( "signal" . to_object ( py) ) ;
275
+ return Ok ( intern ! ( py , "signal" ) . into_py ( py) ) ;
283
276
}
284
277
} ;
285
278
@@ -288,13 +281,13 @@ impl RustNotify {
288
281
return wf_error ! ( error. clone( ) ) ;
289
282
}
290
283
291
- if let Some ( is_set) = stop_event_is_set. as_ref ( ) {
284
+ if let Some ( is_set) = & stop_event_is_set {
292
285
if is_set. call0 ( ) ?. is_truthy ( ) ? {
293
286
if slf. borrow ( ) . debug {
294
287
eprintln ! ( "stop event set, stopping..." ) ;
295
288
}
296
289
slf. borrow ( ) . clear ( ) ;
297
- return Ok ( "stop" . to_object ( py) ) ;
290
+ return Ok ( intern ! ( py , "stop" ) . into_py ( py) ) ;
298
291
}
299
292
}
300
293
@@ -316,7 +309,7 @@ impl RustNotify {
316
309
} else if let Some ( max_time) = max_timeout_time {
317
310
if SystemTime :: now ( ) > max_time {
318
311
slf. borrow ( ) . clear ( ) ;
319
- return Ok ( "timeout" . to_object ( py) ) ;
312
+ return Ok ( intern ! ( py , "timeout" ) . into_py ( py) ) ;
320
313
}
321
314
}
322
315
}
@@ -326,19 +319,19 @@ impl RustNotify {
326
319
}
327
320
328
321
/// https://github.com/PyO3/pyo3/issues/1205#issuecomment-1164096251 for advice on `__enter__`
329
- pub fn __enter__ ( slf : Py < Self > ) -> Py < Self > {
322
+ fn __enter__ ( slf : Py < Self > ) -> Py < Self > {
330
323
slf
331
324
}
332
325
333
- pub fn close ( & mut self ) {
326
+ fn close ( & mut self ) {
334
327
self . watcher = WatcherEnum :: None ;
335
328
}
336
329
337
- pub fn __exit__ ( & mut self , _exc_type : PyObject , _exc_value : PyObject , _traceback : PyObject ) {
330
+ fn __exit__ ( & mut self , _exc_type : PyObject , _exc_value : PyObject , _traceback : PyObject ) {
338
331
self . close ( ) ;
339
332
}
340
333
341
- pub fn __repr__ ( & self ) -> PyResult < String > {
334
+ fn __repr__ ( & self ) -> PyResult < String > {
342
335
Ok ( format ! ( "RustNotify({:#?})" , self . watcher) )
343
336
}
344
337
}
0 commit comments