You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please note, am I generally unfamiliar with the Python C ffi layer, so please excuse any errors or weird assumptions.
I am prototyping a library in pyo3 that introspects type hierarchy when defining new types. In pure Python, i would do this through either __bases__ or __mro__ (and in some rarer cases, __subclasses__()).
Since these all exist within the slots of the PyTypeObject, I wanted to be able to access these directly. Instead, it appears I need to call (for example) cls.getattr("__bases__") and then downcast to a tuple for safe code. Alternatively, I can use as_type_ptr() but end up with unsafe code (and I'm still not sure this is a good idea).
Ideally, it would be nice to have PyType::bases (accessing tp_bases), PyType::mro (accessing tp_mro), and PyType::subclasses (accessing tp_subclasses) available as higher-level APIs.
The text was updated successfully, but these errors were encountered:
Hooksie
changed the title
[Feature request] Directly expose tp_bases, tp_mro, and tp_subclasses on PyType
[Feature request] Directly expose tp_bases, tp_mro, and tp_subclasses on PyType in high-level APIs
May 17, 2024
Hooksie
changed the title
[Feature request] Directly expose tp_bases, tp_mro, and tp_subclasses on PyType in high-level APIs
[Feature request] Directly expose tp_bases, tp_mro, and tp_subclasses on PyType in high-level API
May 17, 2024
@Cheukting I was reading the docs, and noticed the same as well. I think exposing tp_subclasses probably doesnt fall into the same category as the other two here. I think it's reasonable to disregard for now
Please note, am I generally unfamiliar with the Python C ffi layer, so please excuse any errors or weird assumptions.
I am prototyping a library in pyo3 that introspects type hierarchy when defining new types. In pure Python, i would do this through either
__bases__
or__mro__
(and in some rarer cases,__subclasses__()
).Since these all exist within the slots of the PyTypeObject, I wanted to be able to access these directly. Instead, it appears I need to call (for example)
cls.getattr("__bases__")
and then downcast to a tuple for safe code. Alternatively, I can useas_type_ptr()
but end up with unsafe code (and I'm still not sure this is a good idea).Ideally, it would be nice to have
PyType::bases
(accessingtp_bases
),PyType::mro
(accessingtp_mro
), andPyType::subclasses
(accessingtp_subclasses
) available as higher-level APIs.The text was updated successfully, but these errors were encountered: