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
Currently, stub files are not generated for modules without any function/class, even if it has submodules.
This prevents pyright and mypy to retrieve information of modules qualified with partially imported module.
Steps to reproduce
Consider the following library definition:
use pyo3::prelude::*;use pyo3_stub_gen::{define_stub_info_gatherer, derive::*};#[gen_stub_pyfunction(module = "empty_super_module.sub_mod")]#[pyfunction(name = "greet")]pubfngreet(){println!("Hello from sub_mod!")}#[pymodule]fnmain_mod(m:&Bound<PyModule>) -> PyResult<()>{sub_mod(m)?;Ok(())}fnsub_mod(parent:&Bound<PyModule>) -> PyResult<()>{let py = parent.py();let sub = PyModule::new_bound(py,"sub_mod")?;
sub.add_function(wrap_pyfunction!(greet,&sub)?)?;
parent.add_submodule(&sub)?;Ok(())}define_stub_info_gatherer!(stub_info);/// Test of unit test for testing link problem#[cfg(test)]mod test {#[test]fntest(){assert_eq!(2 + 2,4);}}
Running appropriate gen_stub with this, pyo3-stub-gen generates the following stub file:
python/empty_super_module/sub_mod.pyi:
# This file is automatically generated by pyo3_stub_gen# ruff: noqa: E501, F401defgreet() ->None:
...
Note that there is no python/empty_super_module/__init__.py. Consider the following test function:
All of pytest, mypy, and pyright should work fine.
Actual Behaviour
Pytest passes, but mypy warns that Cannot find implementation or library stub for module named "empty_super_module" and pyright fails with the following error:
/path/to/tests/test_empty_super_module.py
/path/to/tests/test_empty_super_module.py:5:24 - error: "sub_mod" is not a known attribute of module "empty_super_module" (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
Possible solutions
Taking submodules into account when generating stub files.
Unconditionally generating stub files even for empty modules.
The text was updated successfully, but these errors were encountered:
Summary
Currently, stub files are not generated for modules without any function/class, even if it has submodules.
This prevents pyright and mypy to retrieve information of modules qualified with partially imported module.
Steps to reproduce
Consider the following library definition:
Running appropriate
gen_stub
with this,pyo3-stub-gen
generates the following stub file:python/empty_super_module/sub_mod.pyi
:Note that there is no
python/empty_super_module/__init__.py
. Consider the following test function:Expected Behaviour
All of pytest, mypy, and pyright should work fine.
Actual Behaviour
Pytest passes, but mypy warns that
Cannot find implementation or library stub for module named "empty_super_module"
and pyright fails with the following error:Possible solutions
The text was updated successfully, but these errors were encountered: