Skip to content

Conversation

@joegnis
Copy link
Contributor

@joegnis joegnis commented Jul 19, 2025

I am using mypy as the type checker which complains when I am trying to add a tuple to an ImVec2:

demo.py

from imgui_bundle import imgui

ImVec2 = imgui.ImVec2


v = ImVec2(0, 0) + (1, 1)

Run type check:

> mypy demo.py
demo.py:6: error: Unsupported operand types for + ("ImVec2" and "tuple[int, int]")  [operator]
Found 1 error in 1 file (checked 1 source file)

The current implementation uses a generic protocol for both ImVec2 and ImVec4.
It can not express the fact that, for example, we can add a 2-item tuple to ImVec2 but not to ImVec4,
and we can add a 4-item tuple to ImVec4 but not to ImVec2.

By using separate protocols, we can be more precise about the types that those math operators supports

@pthom pthom merged commit c6510fb into pthom:main Jul 25, 2025
@pthom
Copy link
Owner

pthom commented Jul 25, 2025

Nice, thanks a lot!
I just merged your PR.

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.

2 participants