Skip to content

Commit 4f82f37

Browse files
committed
implement David's suggestion for pyobject_subclassable_native_type
1 parent b6571a8 commit 4f82f37

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/types/any.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use crate::conversion::{FromPyObject, IntoPyObject};
44
use crate::err::{PyErr, PyResult};
55
use crate::exceptions::{PyAttributeError, PyTypeError};
66
use crate::ffi_ptr_ext::FfiPtrExt;
7-
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
7+
#[cfg(not(all(Py_3_12, Py_LIMITED_API)))]
88
use crate::impl_::pycell::{PyClassObjectBase, PyStaticClassObject};
9-
#[cfg(_Py_OPAQUE_PYOBJECT)]
10-
use crate::impl_::pycell::{PyVariableClassObject, PyVariableClassObjectBase};
119
use crate::instance::Bound;
1210
use crate::internal::get_slot::TP_DESCR_GET;
1311
use crate::py_result_ext::PyResultExt;
@@ -54,21 +52,19 @@ pyobject_native_type_info!(
5452
);
5553

5654
pyobject_native_type_sized!(PyAny, ffi::PyObject);
57-
// We cannot use `pyobject_subclassable_native_type!()` because it cfgs out on `Py_LIMITED_API`.
55+
// We cannot use `pyobject_subclassable_native_type!()` because it cfgs out on `Py_LIMITED_API` for Python < 3.12.
56+
#[cfg(not(all(Py_3_12, Py_LIMITED_API)))]
5857
impl crate::impl_::pyclass::PyClassBaseType for PyAny {
59-
#[cfg(_Py_OPAQUE_PYOBJECT)]
60-
type LayoutAsBase = PyVariableClassObjectBase;
61-
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
6258
type LayoutAsBase = PyClassObjectBase<ffi::PyObject>;
6359
type BaseNativeType = PyAny;
6460
type Initializer = crate::impl_::pyclass_init::PyNativeTypeInitializer<Self>;
6561
type PyClassMutability = crate::pycell::impl_::ImmutableClass;
66-
#[cfg(_Py_OPAQUE_PYOBJECT)]
67-
type Layout<T: crate::impl_::pyclass::PyClassImpl> = PyVariableClassObject<T>;
68-
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
6962
type Layout<T: crate::impl_::pyclass::PyClassImpl> = PyStaticClassObject<T>;
7063
}
7164

65+
#[cfg(all(Py_3_12, Py_LIMITED_API))]
66+
pyobject_subclassable_native_type!(PyAny, ffi::PyObject);
67+
7268
/// This trait represents the Python APIs which are usable on all Python objects.
7369
///
7470
/// It is recommended you import this trait via `use pyo3::prelude::*` rather than

0 commit comments

Comments
 (0)