10000 type stubs for pyimgui · Issue #364 · pyimgui/pyimgui · GitHub
[go: up one dir, main page]

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 stubs for pyimgui #364

Open
denballakh opened this issue Nov 20, 2023 · 8 comments
Open

type stubs for pyimgui #364

denballakh opened this issue Nov 20, 2023 · 8 comments

Comments

@denballakh
Copy link
denballakh commented Nov 20, 2023

Are there any up-to-date type stubs for pyimgui?
Is there a way to autogenerate them from some source?

@denballakh denballakh changed the title stubs for pyimgui type stubs for pyimgui Nov 20, 2023
@denballakh
Copy link
Author

I managed to run this generator on latest core.pyx, manually edited some things that werent able to be parsed and added constants.
Resulting imgui.pyi file is available in this repo: https://github.com/denballakh/pyimgui-stubs
It is not perfect, there are a lot of errors and i'm not sure if i got all types of constants correct, but i think it is a good starting point.

@heyheyjc
Copy link

I'd like to reinforce the importance of this issue. It's a significant barrier to entry for a system that is meant to be simpler to implement, and has iffy documentation elsewhere. More new (capable) users means more contributors.

There are several .pyi generation tools that could be incorporated into the build process.
I know that not every Python programmer uses an IDE with autocompletion but 89% do:
https://lp.jetbrains.com/python-developers-survey-2021/#:~:text=Number%20of%20IDEs%2FEditors%20used&text=VS%20Code%2C%20Jupyter%20Notebook%2C%20and,than%2020%25%20of%20Python%20developers.

The "cost rule of ten" can be extended to the IDE:
$100 if the customer finds the bug
$10 if QA finds the bug
$1 if the programmer finds the bug
$0.10 (or even $0.01) if the IDE prevents the bug

@tayler6000
Copy link
Collaborator

I agree that this is an important issue. Not only for code completion as @heyheyjc mentioned, but also for type validation CI/CD for dependent projects (e.g. mypy).

I would be more than willing to take this up if @denballakh (or anyone else) does not want to do this.

@denballakh
Copy link
Author

I have a repo with single-file stub for imgui. It is in very early stage, I dont have time to go through all functions and annotate them, I only annotate the stuff I am using.
If you want - you can take it and make something useful of it.

There are also tools that can generate stubs using runtime information.
I imagine they work like this: you setup the tool, run a lot of code (test suite, for example), tool gathers all types that were passed to all functions, then generates stub using this information.

@phistep
Copy link
phistep commented Oct 3, 2024

@denballakh Would you mind publishing this to pypi.org as a stub-only package, so that can be used before (or despite not) being integrated fully into the main package? See https://peps.python.org/pep-0561/#stub-only-packages and https://typing.readthedocs.io/en/latest/spec/distributing.html#stub-only-packages

For package maintainers wishing to ship stub files containing all of their type information, it is preferred that the *.pyi stubs are alongside the corresponding *.py files. However, the stubs can also be put in a separate package and distributed separately. Third parties can also find this method useful if they wish to distribute stub files. The name of the stub package MUST follow the scheme foopkg-stubs for type stubs for the package named foopkg.

[...]

Third parties seeking to distribute stub files are encouraged to contact the maintainer of the package about distribution alongside the package. If the maintainer does not wish to maintain or package stub files or type information inline, then a third party stub-only package can be created.

(emphasis mine)

I think at least for the time being, since this issue has been stalled for a while, this seems like a viable solution. If you don't want to do it, I would be willing to do it.

@denballakh
Copy link
Author

Ok.
That is new for me, I will learn about publishing to pypi in a couple of days and will notify you here about my progress.

@denballakh
Copy link
Author

@phistep I did it.
Repository is the same: https://github.com/denballakh/pyimgui-stubs
PyPI page: https://pypi.org/project/pyimgui-stubs/
Installable through pip install pyimgui-stubs

I tested it locally, both mypy and pyright managed to find these stubs (and complained about errors in them).
So it technically works, but needs a lot of polishing. Contributions are welcome.

@phistep
Copy link
phistep commented Oct 8, 2024

@denballakh It works very well for me and is much more flexible than storing the .pyi file alongside with it. Thank you very much! If I find any issues, I will report/contribute for sure!

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

No branches or pull requests

4 participants
0