Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add stubs for pyimgui - Dear ImGui bindings #14317

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

m4reQ
Copy link

@m4reQ m4reQ commented Jun 21, 2025

No description provided.

This comment has been minimized.

This comment has been minimized.

Comment on lines 9 to 14
Condition = typing.NewType("Condition", enum.IntFlag)
NONE = typing.cast(Condition, ...)
ALWAYS = typing.cast(Condition, ...)
ONCE = typing.cast(Condition, ...)
FIRST_USE_EVER = typing.cast(Condition, ...)
APPEARING = typing.cast(Condition, ...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cython represents these using plain ints at runtime. IntFlag operations won't work (e.g. NONE.name would raise).

I'd suggest typing these as Final ints. If the values are stable, you can include them in the stubs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to enforce usage of correct enums in certain contexts i.e. using values that fall under the WindowFlags category in places when such are expected. Using plain ints then will result in typechecker errors, when user tries to use combination of those flags (with | operator) (because it expects concrete value).

@m4reQ m4reQ marked this pull request as draft June 21, 2025 17:56
@brianschubert
Copy link
Member

brianschubert commented Jun 21, 2025

It appears imgui only supports Python <=3.11. That could be problem for stubtest, which currently runs on Python 3.13 in the CI

m4reQ added 3 commits June 21, 2025 20:40
Use `typing_extensions.Self` instead of `typing.Self`
Use `ABC`s from `collections.abc` module
Use `Final[int]` for int constants inside `__init__.pyi`
Use named imports
@m4reQ
Copy link
Author

m4reQ commented Jun 21, 2025

It appears imgui only supports Python <=3.11. That could be problem for stubtest, which currently runs on Python 3.13 in the CI

I personally used imgui mainly with Python 3.12.3 and it worked fine then. I cannot install it on 3.13 and above tho.

m4reQ and others added 3 commits June 22, 2025 16:51
Use custom `_IntFlag` instead of `enum.IntFlag`
Use `Final` for constants instead of assignment with `cast` function
Use `Callable` from `collections.abc` instead of `typing` module

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@m4reQ
Copy link
Author

m4reQ commented Jun 22, 2025

Additionally flake8 fails with Y011 Only simple default values allowed for typed arguments for functions with defaults that use previously defined enum values. I believe they should be treated as simple literals as they are just Final constants. I think removing the defaults takes away useful insight about the function usage. Is there any way to convince flake to allow for such construct or can we just silence that warning in this case?

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

Successfully merging this pull request may close these issues.

3 participants