-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Pick up Type Annotations From .pyi Stub Files (PEP-561) #239
Comments
My initial reaction reading this was that this should just be solved by extension modules supporting Some observations:
I think a reasonable way to implement this would be to override PRs are welcome, I'm happy to help if you get stuck somewhere! 😃 |
I'll have a look at it, thought it would probably take a while... I don't actually program in Python, except for writing some trivial unit tests, so my Python language knowledge is superficial at best. |
An update on my previous comment: It seems like |
Update: pdoc now picks up
async def start_server(
host: str,
port: int,
private_key: str,
peer_public_keys: list[str],
handle_connection: Callable[[asyncio.StreamReader, asyncio.StreamWriter], Awaitable[None]],
receive_datagram: Callable[[bytes, tuple[str, int], tuple[str, int]], None],
) -> WireguardServer: ...
/// Start a WireGuard server.
#[pyfunction]
fn start_server(
py: Python<'_>,
host: String,
port: u16,
private_key: String,
peer_public_keys: Vec<String>,
handle_connection: PyObject,
receive_datagram: PyObject,
) -> PyResult<&PyAny> {
/* ... */
} ⬇️ One very nice aspect about this is that you don't need to add |
Thanks! |
Problem Description
I'm building a native code Python extension module in Rust with PyO3.
It can attach docstrings and function signatures to the module items,
but AFAIK currently there is no way to add Python type information to the extension modules.
PEP-561 was created to help to solve this issue.
It defines type information "stubs" (
.pyi
files), which only carry type hints and signatures,but not the implementation or docstrings.
I've created a PEP-561 compliant stubs package
foo-stubs
for my extension modulefoo
,which contains the module type hints in its only
__init__.pyi
source file.This scheme was needed because PEP-561 does not support distributing type information
as a part of module-only distributions.
I have also verified that both mypy and PyCharm are able to extract and use type information
distributed in this manner.
Proposal
pdoc is currently able to extract inline type hints from conventional
.py
sources.It would be great if pdoc was also able to pull the type information from
.pyi
stubs that are distributed alongside with the Python package sources or
as a separate "-stubs" package.
Alternatives
The native code extension modules may gain the ability to encode the required type information
at some point in the future, making
.pyi
type stubs obsolete.Additional context
PyCharm is able to combine the docstrings and function signatures extracted from the extension module
via introspection with the type hints extracted from the separately distributed
.pyi
files.The text was updated successfully, but these errors were encountered: