mwerezak / DearPyGui-Obj

An object-oriented wrapper around DearPyGui
MIT License
45 stars 3 forks source link

ItemWidget, ValueWidget type annotation #24

Closed mwerezak closed 3 years ago

mwerezak commented 3 years ago

ItemWidget is a mixin, which causes issues with some type checkers when it is annotated as the return type of a function.

Really what needs to happen is that those functions need to be annotated that they return an object that has multiple inheritance: Widget+ItemWidget

Apparently, the correct way to deal with this is to use Protocols that inherit both types?

How do you annotate multiple inheritance? Is there an Intersection type annotation?

This way the ItemWidget-specific functionality remains separate (no need to turn Widget back into a kitchen sink). But type checkers will correctly infer that ItemWidgets have both Widget and ItemWidgetMixin methods.

This issue is a reminder for me to implement the above for all the widget mixin types. Should be mostly just a bunch of renames.

mwerezak commented 3 years ago

Apparently there is no Intersection type annotation in Python, so the only solution is to use Union as a workaround. https://github.com/python/typing/issues/213