-
-
Notifications
You must be signed in to change notification settings - Fork 66
Typing information for pyosmium #59
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
Conversation
I'm not entirely happy with all the code duplication. Keeping the py and pyi files in sync will be a pain. So I'm not sure how to go forward with this. I'm not against adding typing information but it needs to be maintainable. |
I'm not happy too. Though:
We can also try with this approach: But then we need to add Then we would need to have stub methods for pure C++ functions. |
I've managed to inline all annotations to *py files, where they do exists: For all pure C++ modules I kept the *pyi files. Does it improve situation to manageable level? |
646c6b1
to
4978558
Compare
To follow up on this. I was able to use mypy to verify the completeness of the annotations but only for some definitions of completeness, i.e. only if all arguments and fields in *.pyi files are annotated. There was no signature check and missing or superfluous annotations. I also tried pytype but it fails loading C modules. I've also tried mypy's |
I've just found python/mypy#5814. Looks promising and was merged just 2 days ago. I gave it a try on current (boost_python) version and results are better than before, but still far from perfect (and even acceptable), as all C++ function signatures are guessed as |
Thanks for looking into this. If you want to play with the pybind version, the current state is on branch https://github.com/osmcode/pyosmium/tree/pybind-rewrite. It only works with python3 at the moment and some parts are still missing but it should be enough to play with mypy. You need to put a copy of pybind11 in |
Just to let you know. My current plan to move this forward is:
So this will achieve the goal of not having to think about pyi files when implementing changes. Another approach to consider is to extend pybind11 with the ability to generate pyi files for classes it generates, but this way above my current C++ skills |
Sounds all good to me. And I see that your mypy change got merged already. I couldn't help with pybind11 either, as my C++ skills do not include that level of template magic. |
Using master branch of mypy/stubgenc it is possible now to get almost perfect stubs. The only outstanding broken annotation are in
But I didn't find a way to provide proper types here (like it was possible elsewhere by adding py::import statements). The other outstanding problem is that pybind generates docstring for stl iterators that doesn't give any type information, but that something I hope can by addressed on pybind side. I've added step in I've added PS. We will have to wait for mypy > v0.660 to get functionality from: python/mypy#5975 |
Closing in favour of #211. |
This provides *,pyi files with type annotations. As pyosmium is still supporting Python 2.7 I decided to implement type annotations as separate files.
I found this quite useful and informative when using with PyCharm.
For now, I decided to ship *.pyi files together with *.py files. Python community is working on target solution