python-qt-tools / PyQt5-stubs

Stubs for PyQt5
GNU General Public License v3.0
66 stars 31 forks source link

`QMessageBox.StandardButtons.__init__` issues #128

Closed BryceBeagle closed 2 years ago

BryceBeagle commented 3 years ago

https://github.com/stlehmann/PyQt5-stubs/blob/a3b2eeba10cbd9db4a2840a3b2a53c15d31039c2/PyQt5-stubs/QtWidgets.pyi#L6575-L6580

There are a couple issues with the QMessageBox.StandardButtons constructor annotations.

Firstly, the second and third annotations are redundant; other than the args names, which I presume are both auto-generated and inaccurate. Neither are valid kwargs.

Secondly, it can also be constructed using int objects. As QMessageBox.StandardButton extends int, this annotation should just be replaced with using int objects.

>>> QtWidgets.QMessageBox.StandardButtons(0)
<PyQt5.QtWidgets.QMessageBox.StandardButtons object at 0x7f56c949dd60>
TilmanK commented 3 years ago

I guess that issue exists in various places and whoever is able to solve this receives my eternal gratitude.

        progress = QProgressDialog(
            "Wait...", "Cancel", 0, 0, self
        )
        flags = progress.windowFlags()
        progress.setWindowFlags(
            flags
            & ~Qt.WindowCloseButtonHint
            & ~Qt.WindowContextHelpButtonHint
            | Qt.MSWindowsFixedSizeDialogHint
        )

Mypy output:

error: Unsupported operand types for & ("WindowFlags" and "int")
error: Argument 1 to "setWindowFlags" of "QWidget" has incompatible type "int"; expected "Union[WindowFlags, WindowType]"

Current possible solution: cast flags to int and then cast the complete statement inside setWindowFlags to Qt.WindowFlags. It's a bloodbath IMHO...

bluebird75 commented 3 years ago

I am working on a solution for all QFlags based classes

swehba commented 2 years ago

The stubs for QMessageBox.critical(), .information(), etc. show the buttons parameter as non-optional. That causes PyCharm to generate a warning.

bluebird75 commented 2 years ago

You are right. I'll work on a simple fix.

bluebird75 commented 2 years ago

I just checked, pyqt-stubs describes a default valuefor the buttons parameter, making them effectively optional when calling critical() . I checked with PyCharm, it correctly handles this. I tested with the git version of pyqt5-stubs. Which version did you use on your side ?

bluebird75 commented 2 years ago

StandardButtons constructor accepting int has been added as part of #153

bluebird75 commented 2 years ago

Redundant constructor removed as part of #186

All remarks have been implemented.