IceSpringPySideStubs icon indicating copy to clipboard operation
IceSpringPySideStubs copied to clipboard

BUG: `QtCore.Qt.WindowFlags` and `QtCore.Qt.WindowType` not properly typed

Open adam-grant-hendry opened this issue 3 years ago • 1 comments

Problem

QtCore.Qt.WindowType is typed as a python enum.Enum, however enum.Enums do not support bitwise operations. Piping several options together gives the mypy error:

Operator "|" not supported for types "WindowType" and "WindowType"

Additionally, QtCore.Qt.WindowFlags is typed as an object, which is incorrect.

Solution

Python enum.IntFlags support bitwise operations. From the python docs:

class enum.IntFlag Base class for creating enumerated constants that can be combined using the bitwise operators without losing their IntFlag membership. IntFlag members are also subclasses of int.

Typing QtCore.Qt.WindowType as enum.IntFlag and aliasing QtCore.Qt.WindowFlags to QtCore.Qt.WindowType solves the problem:

WindowFlags = WindowType
...
class WindowType(IntFlag):
    ...

Thanks for the great package!

adam-grant-hendry avatar Jun 18 '22 00:06 adam-grant-hendry