File tree Expand file tree Collapse file tree 8 files changed +37
-21
lines changed Expand file tree Collapse file tree 8 files changed +37
-21
lines changed Original file line number Diff line number Diff line change @@ -1229,7 +1229,7 @@ fn impl_complex_enum_struct_variant_cls(
12291229 let field_getter_impl = quote ! {
12301230 fn #field_name( slf: #pyo3_path:: PyClassGuard <' _, Self >, py: #pyo3_path:: Python <' _>) -> #pyo3_path:: PyResult <#pyo3_path:: PyObject > {
12311231 #[ allow( unused_imports) ]
1232- use #pyo3_path:: impl_:: pyclass:: Probe ;
1232+ use #pyo3_path:: impl_:: pyclass:: Probe as _ ;
12331233 match & * slf. into_super( ) {
12341234 #enum_name:: #variant_ident { #field_name, .. } =>
12351235 #pyo3_path:: impl_:: pyclass:: ConvertField :: <
@@ -1305,7 +1305,7 @@ fn impl_complex_enum_tuple_variant_field_getters(
13051305 let field_getter_impl: syn:: ImplItemFn = parse_quote ! {
13061306 fn #field_name( slf: #pyo3_path:: PyClassGuard <' _, Self >, py: #pyo3_path:: Python <' _>) -> #pyo3_path:: PyResult <#pyo3_path:: PyObject > {
13071307 #[ allow( unused_imports) ]
1308- use #pyo3_path:: impl_:: pyclass:: Probe ;
1308+ use #pyo3_path:: impl_:: pyclass:: Probe as _ ;
13091309 match & * slf. into_super( ) {
13101310 #enum_name:: #variant_ident ( #( #field_access_tokens) , * ) =>
13111311 #pyo3_path:: impl_:: pyclass:: ConvertField :: <
Original file line number Diff line number Diff line change @@ -853,7 +853,7 @@ pub fn impl_py_getter_def(
853853 #cfg_attrs
854854 {
855855 #[ allow( unused_imports) ] // might not be used if all probes are positve
856- use #pyo3_path:: impl_:: pyclass:: Probe ;
856+ use #pyo3_path:: impl_:: pyclass:: Probe as _ ;
857857
858858 struct Offset ;
859859 unsafe impl #pyo3_path:: impl_:: pyclass:: OffsetCalculator <#cls, #ty> for Offset {
Original file line number Diff line number Diff line change @@ -852,6 +852,7 @@ impl_signed_integer!(isize);
852852mod tests {
853853 use super :: PyErrState ;
854854 use crate :: exceptions:: { self , PyTypeError , PyValueError } ;
855+ use crate :: impl_:: pyclass:: { value_of, IsSend , IsSync } ;
855856 use crate :: { ffi, PyErr , PyTypeInfo , Python } ;
856857
857858 #[ test]
@@ -977,14 +978,11 @@ mod tests {
977978
978979 #[ test]
979980 fn test_pyerr_send_sync ( ) {
980- fn is_send < T : Send > ( ) { }
981- fn is_sync < T : Sync > ( ) { }
981+ assert ! ( value_of! ( IsSend , PyErr ) ) ;
982+ assert ! ( value_of! ( IsSync , PyErr ) ) ;
982983
983- is_send :: < PyErr > ( ) ;
984- is_sync :: < PyErr > ( ) ;
985-
986- is_send :: < PyErrState > ( ) ;
987- is_sync :: < PyErrState > ( ) ;
984+ assert ! ( value_of!( IsSend , PyErrState ) ) ;
985+ assert ! ( value_of!( IsSync , PyErrState ) ) ;
988986 }
989987
990988 #[ test]
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ use std::{
2525
2626mod assertions;
2727mod lazy_type_object;
28+ #[ macro_use]
2829mod probes;
2930
3031pub use assertions:: * ;
Original file line number Diff line number Diff line change 4646 pub const VALUE : bool = true ;
4747}
4848
49+ probe ! ( IsSend ) ;
50+
51+ impl < T : Send > IsSend < T > {
52+ pub const VALUE : bool = true ;
53+ }
54+
4955probe ! ( IsSync ) ;
5056
5157impl < T : Sync > IsSync < T > {
@@ -57,3 +63,15 @@ probe!(IsOption);
5763impl < T > IsOption < Option < T > > {
5864 pub const VALUE : bool = true ;
5965}
66+
67+ #[ cfg( test) ]
68+ macro_rules! value_of {
69+ ( $probe: ident, $ty: ty) => { {
70+ #[ allow( unused_imports) ] // probe trait not used if VALUE is true
71+ use crate :: impl_:: pyclass:: Probe as _;
72+ $probe:: <$ty>:: VALUE
73+ } } ;
74+ }
75+
76+ #[ cfg( test) ]
77+ pub ( crate ) use value_of;
Original file line number Diff line number Diff line change @@ -411,6 +411,11 @@ pub use inventory; // Re-exported for `#[pyclass]` and `#[pymethods]` with `mult
411411#[ macro_use]
412412mod tests;
413413
414+ // Macro dependencies, also contains macros exported for use across the codebase and
415+ // in expanded macros.
416+ #[ doc( hidden) ]
417+ pub mod impl_;
418+
414419#[ macro_use]
415420mod internal_tricks;
416421mod internal;
@@ -424,8 +429,6 @@ pub mod coroutine;
424429mod err;
425430pub mod exceptions;
426431pub mod ffi;
427- #[ doc( hidden) ]
428- pub mod impl_;
429432mod instance;
430433mod interpreter_lifecycle;
431434pub mod marker;
Original file line number Diff line number Diff line change @@ -315,6 +315,7 @@ use impl_traits;
315315#[ cfg( test) ]
316316mod test {
317317 use super :: * ;
318+ use crate :: impl_:: pyclass:: { value_of, IsSend , IsSync } ;
318319 use crate :: types:: PyAnyMethods as _;
319320 use crate :: { IntoPyObject , Python } ;
320321 use std:: collections:: hash_map:: DefaultHasher ;
@@ -424,14 +425,11 @@ mod test {
424425
425426 #[ test]
426427 fn test_backed_types_send_sync ( ) {
427- fn is_send < T : Send > ( ) { }
428- fn is_sync < T : Sync > ( ) { }
428+ assert ! ( value_of! ( IsSend , PyBackedStr ) ) ;
429+ assert ! ( value_of! ( IsSync , PyBackedStr ) ) ;
429430
430- is_send :: < PyBackedStr > ( ) ;
431- is_sync :: < PyBackedStr > ( ) ;
432-
433- is_send :: < PyBackedBytes > ( ) ;
434- is_sync :: < PyBackedBytes > ( ) ;
431+ assert ! ( value_of!( IsSend , PyBackedBytes ) ) ;
432+ assert ! ( value_of!( IsSync , PyBackedBytes ) ) ;
435433 }
436434
437435 #[ cfg( feature = "py-clone" ) ]
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments