Skip to content
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

Type hints for python? #263

Closed
Coelhomatias opened this issue Feb 27, 2024 · 4 comments
Closed

Type hints for python? #263

Coelhomatias opened this issue Feb 27, 2024 · 4 comments

Comments

@Coelhomatias
Copy link

I see a lot of type definitions in the code but for some reason type hints in python only show the Unknown type in the tooltip.
If I print type(...) it works and gives me the correct type.
Would love some code completion instead of always running help(...)

@sarlinpe
Copy link
Collaborator

This is most likely due to your IDE or plug-in not relying on or parsing the help output. Maybe it's expecting the function to have a docstring in a given format? We could try to add one as described here and see if this solves your issue. I don't have time for this at the moment, but feel free to give it a try and contribute it back with a PR if it works.

@Coelhomatias
Copy link
Author

I'm sorry I don't have much knowledge in this subject. I use VSCode with Pylance. From my understanding and what I read online. For Pylance to understand the types of the module it is necessary a stub file. This stubfile can be generated with pybind11-stubgen or with mypy's stubgen. Both of them give me errors when trying to generate the stubs because some missing imports.
Despite this, a stub file is indeed generated but I can't get Pylance to know about this.
I am not a C/C++ developer and I don't know how to modify make files, however, I think this can be added to the build process.
I will be working extensively with colmap and pycolmap for the remainder of the year and would be happy to (eventually) contribute, however, I too don't have enough time to learn the necessary skills for now. Maybe in the future I'll submit a PR regarding this issue.

@Phil26AT
Copy link
Collaborator

Hi @Coelhomatias, I just tried generating stubfiles with pybind11-stubgen pycolmap. It will create a file stubs/pycolmap.pyi. You need to move it into the same folder as the pycolmap.cpython*.so file (with a source install you can just put it into the pycolmap folder). Then VSCode gives correct types (where available, arguments with type py::object will show ...) and auto-complete also works.

@Coelhomatias
Copy link
Author

@Phil26AT Thank you very much, you just saved me a lot of time and effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants