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
Sorry if this is the intended behavior, I might just be confused here.
Again, I just want griffe / mkdocs to generate documenation for me.
Interestingly, it seems that if a struct is embedded inside a module (not exported with #[pymodule_export], it's __module__ is, by default, the value you put into it's module's module="..." + the name of the module itself.
This is a bit confusing so I'll show code:
#[pymodule]mod mymodule {use pyo3::prelude::*;#[pymodule(module="mymodule.mymodule")]mod submodule {usesuper::*;#[pyclass]/// FooBar is also importantstructFooBar{}/// Hack: workaround for https://github.com/PyO3/pyo3/issues/759#[pymodule_init]fninit(m:&Bound<'_,PyModule>) -> PyResult<()>{Python::with_gil(|py| {
py.import("sys")?
.getattr("modules")?
.set_item("mymodule.submodule", m)})}}}
results in:
>>> from mymodule import submodule
>>> submodule.FooBar.__module__
'mymodule.mymodule.submodule'
>>>
Which is correct.
Now, for griffe to work, I need the module's __module__ to be mymodule.mymodule.submodule (as I posted here).
I can fix griffe by manually setting the __module__ attribute but if this "bug" (I am not sure it one is now :-D) gets fixed I would have to manually set #[pyclass(module="mymodule.mymodule.submodule]" on FooBar.
Bug Description
Correctly sets the
__module__
attribute of the class.The same behavior for other (sub)
pymodule
s is expected.The attribute is needed for tools such as https://github.com/mkdocstrings/griffe to properly find the submodule. See PyO3/maturin#1365.
What seems to happen is the
module
value of the submodule is used to determine themodule
value of the (inlined)pyclass
es.Steps to Reproduce
__module__
attribute`Backtrace
Your operating system and version
Fedora 41
Your Python version (
python --version
)Python 3.13.1
Your Rust version (
rustc --version
)rustc 1.81.0 (eeb90cda1 2024-09-04)
Your PyO3 version
pyo3 v0.23.3 (https://github.com/PyO3/pyo3#5c363b5d)
How did you install python? Did you use a virtualenv?
dnf install python
Additional Info
As a workaround,
__module__
attribute could be set manually:The text was updated successfully, but these errors were encountered: