-
Notifications
You must be signed in to change notification settings - Fork 765
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
Feature request: Generate stub files along during compile #510
Comments
I think this is a good idea in general, but to me this feels like actually a big project. Does it need to be in PyO3 itself, or could it be done as a third-party extension? |
It could certainly be a 3rd-party extension. I'm afraid I don't know enough about pyo3's internals even to judge how big a job it would be - it seemed to me like pyo3 knows which types can interconvert, and rust knows what types its functions support, so it would be a case of formatting existing data rather than trying to generate it in the first place, but I fully accept that that's probably wrong. |
Sounds interesting, thanks. |
I've already done a bit of research on the topic, which resulted in #305 and #310. By default, there are tools that can open native (and pure python) modules and generate stubs from them. Pycharm for example automatically generates stubs for all installed modules; I've added the stub for the word-count example below. Python 3 has additionally introduced A simple way to get at least the names and positions of the arguments is generating a text signature (#310), as e.g. orjson currently does manually. I think that that should be done first. If we want more advanced annotations, we'd need to create our own metadata format. See e.g. wasm-bingen's approach with
They are just normal python files with the implementation replaced by
|
hey, thanks for working on this library. I've been looking around about this, so here are my notes, which you might find useful Looks like mypy solves it by reusing the python parser module to re-parse each module and create an AST. Then it creates Stubs for AST nodes. https://github.com/python/mypy/blob/master/mypy/stubgen.py It might be too big a problem to solve inside pyo3, at least mypy shows how one could do it. |
Yeah but we need here is just type hints for |
by manually adding the signatures to the docstrings, pyls can autocomplete all the methods. See #310 (comment) for a proposal |
Does that include type annotations or is that too much to ask? 😉 My only concern is that if we're writing explicit header stubs anyway, we may as well just write a full pyi stub file and at least gain access to the tooling around that. |
From what I understand, type annotations don't work at all for return types (CPython doesn't recognize the signature and put it in
I think having signatures is useful for those cases when you need |
I'd also find this feature really useful. Ideally what I'd like is that PyO3 produces a |
Here is how napi-rs does typescript |
In case someone else finds this thread, the tracking issue is #2454. |
Hi, is there any updates? Thanks |
Not sure how possible this would be, but it would be awesome if we could give our IDEs an idea of what's going on inside a pyo3 function/class with
.pyi
stub files. Pyo3 already knows what rust and python types can interconvert: expressing this information for the pyo3 objects in a stub file would really help to bridge the gap.The text was updated successfully, but these errors were encountered: