-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyTypeObject.ob_type
is not available in cpython
#2905
Comments
So the CPython doc you link is actually for PyPy before 3.9 was not PEP 3123 compliant (and still isn't on 3.9 windows, I'm not sure what's going on there), so the source line you link to is just to support old pypy versions. So in summary, this is working as intended |
I think the following can work to get the metaclass safely (on my phone, so haven't tested): let value: &PyAny = ...
let type_ = value.get_type();
let meta_type = type_.get_type(); |
Thanks, |
For illustration, an instance of a custom Python class' layout looks something like this: PyObject @ 0x14e93a9ed40 {
ob_refcnt: 1,
ob_type: PyTypeObject @ 0x14e9334b2b0 {
ob_base: PyVarObject @ 0x14e9334b2b0 {
ob_base: PyObject @ 0x14e9334b2b0 {
ob_refcnt: 5,
// 'object'
ob_type: PyType_Type @ 0x7ffe3789b920 {
// all the fluff inside `object`
}
},
ob_size: 0,
},
tp_name: "MyClass" @ 0x14e93a73660,
tp_basicsize: 32,
tp_itemsize: 0,
// etc |
Bug Description
I'm trying to access
PyTypeObject.ob_type
, but it doesn't seem to be available on cpython:pyo3/pyo3-ffi/src/cpython/object.rs
Lines 221 to 222 in 18081ba
I believe it should be available, especially since
value.get_type().get_type_ptr()
works fine.According to the cpython api docs I think it should be available.
Steps to Reproduce
I would expect the following to pass, but it fails to compile
! Note, I've tried this with pypy 3.8 and it passes.
Backtrace
No response
Your operating system and version
Ubuntu
Your Python version (
python --version
)Python 3.10.4
Your Rust version (
rustc --version
)cargo 1.68.0-nightly (2381cbdb4 2022-12-23)
Your PyO3 version
v0.18.0
How did you install python? Did you use a virtualenv?
pyenv
Additional Info
No response
The text was updated successfully, but these errors were encountered: