pthom / imgui_bundle

Your fast track to powerful GUIs: Dear ImGui Bundle, an extensive toolkit for Python and C++ with immediate mode efficiency.
https://pthom.github.io/imgui_bundle/
MIT License
703 stars 73 forks source link

Many python binding functions are missing default arguments #255

Closed oxysoft closed 1 month ago

oxysoft commented 1 month ago

See for example these bindings from the main imgui API:

def input_text(label, p_str, flags=0, callback, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """ input_text(label: str, str: str, flags: int = 0, callback: Callable[[imgui_bundle._imgui_bundle.imgui.InputTextCallbackData], int] = None, user_data: capsule = None) -> tuple[bool, str] """
    pass

def input_text_with_hint(label, hint, p_str, flags=0, callback, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """ input_text_with_hint(label: str, hint: str, str: str, flags: int = 0, callback: Callable[[imgui_bundle._imgui_bundle.imgui.InputTextCallbackData], int] = None, user_data: capsule = None) -> tuple[bool, str] """
    pass

In this case, it seems like callback should have a default argument such as None

oxysoft commented 1 month ago

Even button appears to be missing a default value for size, so all buttons are flagged with errors in my IDE

def button(label, size, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """
    button(label: str, size: imgui_bundle._imgui_bundle.imgui.ImVec2 = <imgui_bundle._imgui_bundle.imgui.ImVec2 object at 0x7fe9872b76b0>) -> bool

    button
    """
    pass
pthom commented 1 month ago

Hello,

What you are pointing here are likely definitions inferred from you IDE, probably by a tool such as stubgen

The text "NOTE: unreliably restored from doc") is an indication of it.

ImGui Bundle comes with fully typed and documented stubs: look at this for example

https://github.com/pthom/imgui_bundle/blob/564cf51ebeba07e9d3173c62499522c36afbdae3/bindings/imgui_bundle/imgui/__init__.pyi#L11103-L11109

You should look inside your IDE on how to tell it not to use auto-generated stubs but rather the official ones.

oxysoft commented 1 month ago

Hmmm I followed the instructions provided by JetBrains and it's still generating its own stubs no matter what I do.

image

oxysoft commented 1 month ago

Alright so this is some python bullshit. After doing what I showed in the image above, you also have to correct the imports, and pycharm will still never propose the correct import so from now on we have to add the imports manually rather than using the keyboard shortcut.

from imgui_bundle import imgui

But that still wasn't enough, something was utterly broken with my venv and it still wouldn't locate this import. After recreating the venv from scratch and starting with this package, it now works.

oxysoft commented 1 month ago

OK this issue arose again after some other venv management shanenigans and I found out that the issue is most likely that the venv absolutely has to be called .venv or it can lead to issues with PyCharm. venv or anything else could ruin your day. Just noting down in case somebody else ever stumbles upon this.