PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Apache License 2.0
12.05k stars 745 forks source link

Declarative modules don't set item's module properly #4070

Open wyfo opened 5 months ago

wyfo commented 5 months ago

Using this code

use pyo3::prelude::*;

#[pymodule]
mod my_extension {
    #[pymodule]
    mod submodule {
        #[pyfunction]
        fn foo() {}
    }
}

my_extension.submodule.foo.__module__ returns submodule instead of my_extension.submodule, as it would be expected for pure Python modules.

Relates to #3900

davidhewitt commented 5 months ago

Agreed this could be much better. There's additional runtime complexity because my_extension might itself be a submodule to a pure python root e.g. my_package.my_native_code_extension.submodule

Tpt commented 4 months ago

I have opened #4213 that should fix it