Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QMessageBox.StandardButtons.__init__ issues #128

Closed
BryceBeagle opened this issue Jan 4, 2021 · 7 comments
Closed

QMessageBox.StandardButtons.__init__ issues #128

BryceBeagle opened this issue Jan 4, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@BryceBeagle
Copy link
Collaborator

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>
@BryceBeagle BryceBeagle added the bug Something isn't working label Jan 4, 2021
@TilmanK
Copy link
Contributor

TilmanK commented Feb 25, 2021

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
Copy link
Collaborator

I am working on a solution for all QFlags based classes

@swehba
Copy link

swehba commented Oct 14, 2021

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

@bluebird75
Copy link
Collaborator

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

@bluebird75
Copy link
Collaborator

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
Copy link
Collaborator

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

@bluebird75
Copy link
Collaborator

Redundant constructor removed as part of #186

All remarks have been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants