Skip to content

experimental-inspect: write nested package stubs into their own directory - #6365

Merged
Tpt merged 2 commits into
PyO3:mainfrom
jonasdedden:introspection-nested-package-path
Aug 28, 2026
Merged

experimental-inspect: write nested package stubs into their own directory#6365
Tpt merged 2 commits into
PyO3:mainfrom
jonasdedden:introspection-nested-package-path

Conversation

@jonasdedden

Copy link
Copy Markdown
Contributor

What was wrong

add_module_stub_files used a single module_path: &[&str] argument for two different things: the output directory and the list of parent module names. The recursive call passed [...ancestors, parent_name], which is right as parents and wrong as a directory. A package nested inside a package wrote its __init__.pyi under a directory named after its parent, its own name disappeared from the tree, and its leaf submodules landed one level too shallow.

pytests has no nested package, so nothing in the test suite exercised it.

Reproduction

#[pymodule]
pub mod grandchild {
    #[pyclass]
    pub struct Deep;
}

#[pymodule]
pub mod child {
    #[pymodule_export]
    use super::grandchild;
    #[pyclass]
    pub struct Mid;
}

#[pymodule]
mod slotrepro {
    #[pymodule_export]
    use super::child;
    #[pyclass]
    pub struct Top;
}
before                      after
__init__.pyi                __init__.pyi
slotrepro/__init__.pyi      child/__init__.pyi
slotrepro/grandchild.pyi    child/grandchild.pyi

The fix

Split the argument into directory: &Path and parents: &[&str]. The directory descends by the submodule's own name; parents accumulates module names exactly as before, so module_stubs and make_module_path_relative are unchanged in behaviour.

@jonasdedden jonasdedden changed the title experimental-inspect`: write nested package stubs into their own directory experimental-inspect: write nested package stubs into their own directory Aug 28, 2026

@Tpt Tpt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Thanks!

@Tpt
Tpt added this pull request to the merge queue Aug 28, 2026
Merged via the queue into PyO3:main with commit 4c1bc78 Aug 28, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants