Skip to content
Discussion options

You must be logged in to vote

So the cause here is that PyO3 still adds some extra space to struct A's Python layout to do our refcell tracking. You can turn this off with #[pyclass(frozen)]. (We've discussed making frozen the default in the past.)

Testing locally, I indeed find this works:

#[pyclass(subclass, frozen)] // <--- frozen added here
#[derive(Clone, Debug)]
struct A {}

#[pymodule]
fn my_module(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_class::<A>()?;
    Ok(())
}

Note that if you make A non-empty then again you'll have a conflict. That's just a limitation of Python multiple inheritance, there's not much that can be done about that.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aminalaee
Comment options

Answer selected by aminalaee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants