Skip to content

Commit f275f96

Browse files
Update pyo3
1 parent 2755f1b commit f275f96

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

‎Cargo.lock‎

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/capi/src/object/pytype.rs‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ pub unsafe extern "C" fn PyObject_GetTypeData(
323323
}
324324
}
325325

326+
#[unsafe(no_mangle)]
327+
pub unsafe extern "C" fn PyObject_GetTypeData_DuringGC(
328+
obj: *mut PyObject,
329+
cls: *mut PyTypeObject,
330+
) -> *mut c_void {
331+
unsafe { PyObject_GetTypeData(obj, cls) }
332+
}
333+
326334
#[unsafe(no_mangle)]
327335
pub extern "C" fn PyType_Freeze(_ty: *mut PyTypeObject) -> c_int {
328336
0
@@ -332,7 +340,7 @@ pub extern "C" fn PyType_Freeze(_ty: *mut PyTypeObject) -> c_int {
332340
mod tests {
333341
use pyo3::IntoPyObjectExt;
334342
use pyo3::prelude::*;
335-
use pyo3::types::{PyDict, PyInt, PyString, PyType, PyTypeMethods};
343+
use pyo3::types::{PyDict, PyInt, PyList, PyString, PyType, PyTypeMethods};
336344

337345
#[test]
338346
fn type_name() {
@@ -485,4 +493,37 @@ mod tests {
485493
);
486494
});
487495
}
496+
497+
#[test]
498+
fn subclass_with_property() {
499+
#[pyclass(frozen, extends=PyList)]
500+
struct MyList {}
501+
502+
#[pymethods]
503+
impl MyList {
504+
#[new]
505+
fn new() -> Self {
506+
Self {}
507+
}
508+
509+
#[getter]
510+
fn name(&self) -> &'static str {
511+
"Some list"
512+
}
513+
}
514+
515+
Python::attach(|py| {
516+
let obj = Bound::new(py, MyList {}).unwrap();
517+
518+
assert!(obj.is_instance_of::<PyList>());
519+
520+
assert_eq!(
521+
obj.getattr("name")
522+
.unwrap()
523+
.cast_into::<PyString>()
524+
.unwrap(),
525+
"Some list"
526+
);
527+
});
528+
}
488529
}

0 commit comments

Comments
 (0)