Skip to content

Commit 3ed9290

Browse files
committed
Convert LazyTypeObject to use the Bound API
1 parent f04ad56 commit 3ed9290

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pyo3-macros-backend/src/pyclass.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ fn impl_pytypeinfo(
12831283

12841284
#[inline]
12851285
fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject {
1286+
use _pyo3::prelude::PyTypeMethods;
12861287
#deprecations
12871288

12881289
<#cls as _pyo3::impl_::pyclass::PyClassImpl>::lazy_type_object()

src/impl_/pyclass/lazy_type_object.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
pyclass::{create_type_object, PyClassTypeObject},
1313
sync::{GILOnceCell, GILProtected},
1414
types::PyType,
15-
PyClass, PyErr, PyMethodDefType, PyObject, PyResult, Python,
15+
Bound, PyClass, PyErr, PyMethodDefType, PyObject, PyResult, Python,
1616
};
1717

1818
use super::PyClassItemsIter;
@@ -46,15 +46,15 @@ impl<T> LazyTypeObject<T> {
4646

4747
impl<T: PyClass> LazyTypeObject<T> {
4848
/// Gets the type object contained by this `LazyTypeObject`, initializing it if needed.
49-
pub fn get_or_init<'py>(&'py self, py: Python<'py>) -> &'py PyType {
49+
pub fn get_or_init<'py>(&self, py: Python<'py>) -> &Bound<'py, PyType> {
5050
self.get_or_try_init(py).unwrap_or_else(|err| {
5151
err.print(py);
5252
panic!("failed to create type object for {}", T::NAME)
5353
})
5454
}
5555

5656
/// Fallible version of the above.
57-
pub(crate) fn get_or_try_init<'py>(&'py self, py: Python<'py>) -> PyResult<&'py PyType> {
57+
pub(crate) fn get_or_try_init<'py>(&self, py: Python<'py>) -> PyResult<&Bound<'py, PyType>> {
5858
self.0
5959
.get_or_try_init(py, create_type_object::<T>, T::NAME, T::items_iter())
6060
}
@@ -65,18 +65,18 @@ impl LazyTypeObjectInner {
6565
// so that this code is only instantiated once, instead of for every T
6666
// like the generic LazyTypeObject<T> methods above.
6767
fn get_or_try_init<'py>(
68-
&'py self,
68+
&self,
6969
py: Python<'py>,
7070
init: fn(Python<'py>) -> PyResult<PyClassTypeObject>,
7171
name: &str,
7272
items_iter: PyClassItemsIter,
73-
) -> PyResult<&'py PyType> {
73+
) -> PyResult<&Bound<'py, PyType>> {
7474
(|| -> PyResult<_> {
7575
let type_object = self
7676
.value
7777
.get_or_try_init(py, || init(py))?
7878
.type_object
79-
.as_ref(py);
79+
.bind(py);
8080
self.ensure_init(type_object, name, items_iter)?;
8181
Ok(type_object)
8282
})()
@@ -91,7 +91,7 @@ impl LazyTypeObjectInner {
9191

9292
fn ensure_init(
9393
&self,
94-
type_object: &PyType,
94+
type_object: &Bound<'_, PyType>,
9595
name: &str,
9696
items_iter: PyClassItemsIter,
9797
) -> PyResult<()> {

0 commit comments

Comments
 (0)