@@ -43,18 +43,27 @@ pub fn weaklist_offset<T: PyClass>() -> ffi::Py_ssize_t {
43
43
PyClassObject :: < T > :: weaklist_offset ( )
44
44
}
45
45
46
+ mod sealed {
47
+ pub trait Sealed { }
48
+
49
+ impl Sealed for super :: PyClassDummySlot { }
50
+ impl Sealed for super :: PyClassDictSlot { }
51
+ impl Sealed for super :: PyClassWeakRefSlot { }
52
+ impl Sealed for super :: ThreadCheckerImpl { }
53
+ impl < T : Send > Sealed for super :: SendablePyClass < T > { }
54
+ }
55
+
46
56
/// Represents the `__dict__` field for `#[pyclass]`.
47
- pub trait PyClassDict {
57
+ pub trait PyClassDict : sealed :: Sealed {
48
58
/// Initial form of a [PyObject](crate::ffi::PyObject) `__dict__` reference.
49
59
const INIT : Self ;
50
60
/// Empties the dictionary of its key-value pairs.
51
61
#[ inline]
52
62
fn clear_dict ( & mut self , _py : Python < ' _ > ) { }
53
- private_decl ! { }
54
63
}
55
64
56
65
/// Represents the `__weakref__` field for `#[pyclass]`.
57
- pub trait PyClassWeakRef {
66
+ pub trait PyClassWeakRef : sealed :: Sealed {
58
67
/// Initializes a `weakref` instance.
59
68
const INIT : Self ;
60
69
/// Clears the weak references to the given object.
@@ -64,19 +73,16 @@ pub trait PyClassWeakRef {
64
73
/// - The GIL must be held.
65
74
#[ inline]
66
75
unsafe fn clear_weakrefs ( & mut self , _obj : * mut ffi:: PyObject , _py : Python < ' _ > ) { }
67
- private_decl ! { }
68
76
}
69
77
70
78
/// Zero-sized dummy field.
71
79
pub struct PyClassDummySlot ;
72
80
73
81
impl PyClassDict for PyClassDummySlot {
74
- private_impl ! { }
75
82
const INIT : Self = PyClassDummySlot ;
76
83
}
77
84
78
85
impl PyClassWeakRef for PyClassDummySlot {
79
- private_impl ! { }
80
86
const INIT : Self = PyClassDummySlot ;
81
87
}
82
88
@@ -88,7 +94,6 @@ impl PyClassWeakRef for PyClassDummySlot {
88
94
pub struct PyClassDictSlot ( * mut ffi:: PyObject ) ;
89
95
90
96
impl PyClassDict for PyClassDictSlot {
91
- private_impl ! { }
92
97
const INIT : Self = Self ( std:: ptr:: null_mut ( ) ) ;
93
98
#[ inline]
94
99
fn clear_dict ( & mut self , _py : Python < ' _ > ) {
@@ -106,7 +111,6 @@ impl PyClassDict for PyClassDictSlot {
106
111
pub struct PyClassWeakRefSlot ( * mut ffi:: PyObject ) ;
107
112
108
113
impl PyClassWeakRef for PyClassWeakRefSlot {
109
- private_impl ! { }
110
114
const INIT : Self = Self ( std:: ptr:: null_mut ( ) ) ;
111
115
#[ inline]
112
116
unsafe fn clear_weakrefs ( & mut self , obj : * mut ffi:: PyObject , _py : Python < ' _ > ) {
@@ -1034,12 +1038,11 @@ impl<T> PyClassNewTextSignature<T> for &'_ PyClassImplCollector<T> {
1034
1038
// Thread checkers
1035
1039
1036
1040
#[ doc( hidden) ]
1037
- pub trait PyClassThreadChecker < T > : Sized {
1041
+ pub trait PyClassThreadChecker < T > : Sized + sealed :: Sealed {
1038
1042
fn ensure ( & self ) ;
1039
1043
fn check ( & self ) -> bool ;
1040
1044
fn can_drop ( & self , py : Python < ' _ > ) -> bool ;
1041
1045
fn new ( ) -> Self ;
1042
- private_decl ! { }
1043
1046
}
1044
1047
1045
1048
/// Default thread checker for `#[pyclass]`.
@@ -1062,7 +1065,6 @@ impl<T: Send> PyClassThreadChecker<T> for SendablePyClass<T> {
1062
1065
fn new ( ) -> Self {
1063
1066
SendablePyClass ( PhantomData )
1064
1067
}
1065
- private_impl ! { }
1066
1068
}
1067
1069
1068
1070
/// Thread checker for `#[pyclass(unsendable)]` types.
@@ -1111,7 +1113,6 @@ impl<T> PyClassThreadChecker<T> for ThreadCheckerImpl {
1111
1113
fn new ( ) -> Self {
1112
1114
ThreadCheckerImpl ( thread:: current ( ) . id ( ) )
1113
1115
}
1114
- private_impl ! { }
1115
1116
}
1116
1117
1117
1118
/// Trait denoting that this class is suitable to be used as a base type for PyClass.
0 commit comments