-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reportMissingModuleSource warnings when importing submodules from extension modules (pybind11) #5950
Comments
@heejaechang , IIRC, you initially implemented the code for |
@tonywu6 this is happening since we don't know if you had you probably need |
Is there a way to disable this warning in type stubs? (I'm only starting to use type checking, maybe the answer is obvious). I have a similar configuration as OP and I'd like to package my python library together with stubs. |
@wojdyr, I'm a bit unclear on your situation. Are you running pyright on your Is your library written in Python? If so, I recommend putting type information directly in your Python code rather than shipping parallel ".pyi" files. If you keep the type information separate, it's much tougher to maintain because the type information will inevitably diverge from the implementation over time. If your library (or parts of your library) are written in another language, like the OP, then ".pyi" files are the recommended approach for those submodules. Which submodules are you importing from your type stubs? Are they part of your library? Are those submodules written in Python or some other language? If it's the latter, do you have ".pyi" files for those submodules as well? |
Thanks for quick response. To clarify, I have the same setup as OP. Python extension module is written entirely in C/C++. Python C API allows to have submodules in a single python extension file (.so/.pyd). The layout is (copying from OP):
The extension (which including submodules) is in one file example.so, but pyi files are separate. When a user of this library writes a program and imports the submodule: import example.submodule such a warnings is printed:
The user may add |
You will need to change the structure of your package to conform to PEP 561 if you want this to work with static type checkers. PEP 561 (which introduced the concept of a "py.typed" marker file) requires that the package be in a directory — in your case, the top-level directory named |
The authors of this PEP didn't think much about extension modules at that time. Having intermediary |
FTR, PEP 561 won't be updated to clarify the structure of extension packages, because it's already accepted, but having extension module (.so) directly in site-packages is considered correct: python/peps#2318 |
Describe the bug
I have a Python package with a C extension module (built with pybind11) that also declares a submodule. I also have the corresponding type stubs (generated with mypy). Assuming the following layout after installed:
I attempt to import from the submodule, and then type-check with Pyright, assuming default configuration, and that the stubs are correct:
Expected result
Pyright reports no warnings. (MyPy doesn't)
Actual result
Pyright warns about
Import "example.submodule" could not be resolved from source
(but also finds the type stubs correctly).Verbose output
Reproducible example
https://github.com/tonywu6/pyright-pybind11
(Just started learning about bindings stuff so it probably looks like a mess)
Environment
The extension module was built with:
The text was updated successfully, but these errors were encountered: