@@ -121,14 +121,24 @@ pub trait DerefToPyAny {
121
121
// Implementations core to all native types
122
122
#[ doc( hidden) ]
123
123
#[ macro_export]
124
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
125
+ #[ cfg( not( feature = "gil-refs" ) ) ]
126
+ macro_rules! pyobject_native_type_base(
127
+ // empty implementation on non-gil-refs
128
+ ( $name: ty $( ; $generics: ident) * ) => { } ;
129
+ ) ;
130
+
131
+ // Implementations core to all native types
132
+ #[ doc( hidden) ]
133
+ #[ macro_export]
134
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
135
+ #[ cfg( feature = "gil-refs" ) ]
124
136
macro_rules! pyobject_native_type_base(
125
137
( $name: ty $( ; $generics: ident) * ) => {
126
- #[ cfg( feature = "gil-refs" ) ]
127
138
unsafe impl <$( $generics, ) * > $crate:: PyNativeType for $name {
128
139
type AsRefSource = Self ;
129
140
}
130
141
131
- #[ cfg( feature = "gil-refs" ) ]
132
142
impl <$( $generics, ) * > :: std:: fmt:: Debug for $name {
133
143
fn fmt( & self , f: & mut :: std:: fmt:: Formatter <' _>)
134
144
-> :: std:: result:: Result <( ) , :: std:: fmt:: Error >
@@ -139,7 +149,6 @@ macro_rules! pyobject_native_type_base(
139
149
}
140
150
}
141
151
142
- #[ cfg( feature = "gil-refs" ) ]
143
152
impl <$( $generics, ) * > :: std:: fmt:: Display for $name {
144
153
fn fmt( & self , f: & mut :: std:: fmt:: Formatter <' _>)
145
154
-> :: std:: result:: Result <( ) , :: std:: fmt:: Error >
@@ -157,7 +166,6 @@ macro_rules! pyobject_native_type_base(
157
166
}
158
167
}
159
168
160
- #[ cfg( feature = "gil-refs" ) ]
161
169
impl <$( $generics, ) * > $crate:: ToPyObject for $name
162
170
{
163
171
#[ inline]
@@ -172,6 +180,35 @@ macro_rules! pyobject_native_type_base(
172
180
// make sense on PyAny / have different implementations).
173
181
#[ doc( hidden) ]
174
182
#[ macro_export]
183
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
184
+ #[ cfg( not( feature = "gil-refs" ) ) ]
185
+ macro_rules! pyobject_native_type_named (
186
+ ( $name: ty $( ; $generics: ident) * ) => {
187
+
188
+ impl <$( $generics, ) * > :: std:: convert:: AsRef <$crate:: PyAny > for $name {
189
+ #[ inline]
190
+ fn as_ref( & self ) -> & $crate:: PyAny {
191
+ & self . 0
192
+ }
193
+ }
194
+
195
+ impl <$( $generics, ) * > :: std:: ops:: Deref for $name {
196
+ type Target = $crate:: PyAny ;
197
+
198
+ #[ inline]
199
+ fn deref( & self ) -> & $crate:: PyAny {
200
+ & self . 0
201
+ }
202
+ }
203
+
204
+ impl $crate:: types:: DerefToPyAny for $name { }
205
+ } ;
206
+ ) ;
207
+
208
+ #[ doc( hidden) ]
209
+ #[ macro_export]
210
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
211
+ #[ cfg( feature = "gil-refs" ) ]
175
212
macro_rules! pyobject_native_type_named (
176
213
( $name: ty $( ; $generics: ident) * ) => {
177
214
$crate:: pyobject_native_type_base!( $name $( ; $generics) * ) ;
@@ -202,7 +239,6 @@ macro_rules! pyobject_native_type_named (
202
239
203
240
// FIXME https://github.com/PyO3/pyo3/issues/3903
204
241
#[ allow( unknown_lints, non_local_definitions) ]
205
- #[ cfg( feature = "gil-refs" ) ]
206
242
impl <$( $generics, ) * > $crate:: IntoPy <$crate:: Py <$name>> for & ' _ $name {
207
243
#[ inline]
208
244
fn into_py( self , py: $crate:: Python <' _>) -> $crate:: Py <$name> {
@@ -212,7 +248,6 @@ macro_rules! pyobject_native_type_named (
212
248
213
249
// FIXME https://github.com/PyO3/pyo3/issues/3903
214
250
#[ allow( unknown_lints, non_local_definitions) ]
215
- #[ cfg( feature = "gil-refs" ) ]
216
251
impl <$( $generics, ) * > :: std:: convert:: From <& ' _ $name> for $crate:: Py <$name> {
217
252
#[ inline]
218
253
fn from( other: & $name) -> Self {
@@ -223,7 +258,6 @@ macro_rules! pyobject_native_type_named (
223
258
224
259
// FIXME https://github.com/PyO3/pyo3/issues/3903
225
260
#[ allow( unknown_lints, non_local_definitions) ]
226
- #[ cfg( feature = "gil-refs" ) ]
227
261
impl <' a, $( $generics, ) * > :: std:: convert:: From <& ' a $name> for & ' a $crate:: PyAny {
228
262
fn from( ob: & ' a $name) -> Self {
229
263
unsafe { & * ( ob as * const $name as * const $crate:: PyAny ) }
@@ -279,11 +313,23 @@ macro_rules! pyobject_native_type_info(
279
313
// because rust-numpy has a special implementation.
280
314
#[ doc( hidden) ]
281
315
#[ macro_export]
316
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
317
+ #[ cfg( not( feature = "gil-refs" ) ) ]
318
+ macro_rules! pyobject_native_type_extract {
319
+ // no body for non-gil-refs
320
+ ( $name: ty $( ; $generics: ident) * ) => { } ;
321
+ }
322
+
323
+ // NOTE: This macro is not included in pyobject_native_type_base!
324
+ // because rust-numpy has a special implementation.
325
+ #[ doc( hidden) ]
326
+ #[ macro_export]
327
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
328
+ #[ cfg( feature = "gil-refs" ) ]
282
329
macro_rules! pyobject_native_type_extract {
283
330
( $name: ty $( ; $generics: ident) * ) => {
284
331
// FIXME https://github.com/PyO3/pyo3/issues/3903
285
332
#[ allow( unknown_lints, non_local_definitions) ]
286
- #[ cfg( feature = "gil-refs" ) ]
287
333
impl <' py, $( $generics, ) * > $crate:: FromPyObject <' py> for & ' py $name {
288
334
#[ inline]
289
335
fn extract_bound( obj: & $crate:: Bound <' py, $crate:: PyAny >) -> $crate:: PyResult <Self > {
0 commit comments