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 signature doesn't match. #214

Open
th3w1zard1 opened this issue Apr 15, 2024 · 1 comment
Open

QMessageBox signature doesn't match. #214

th3w1zard1 opened this issue Apr 15, 2024 · 1 comment

Comments

@th3w1zard1
Copy link

Attempting to send certain kwargs to QMessageBox will exception, while the stubs say it does support it. For example:

filepath_str, _filter = QFileDialog.getSaveFileName(self, "Save As", "", self._saveFilter, "")
if not filepath_str or not filepath_str.strip() or not os.path.exists(filepath_str):
  QMessageBox(
      icon=QMessageBox.Critical,
      title="Failed to add resource",
      text=f"Could not add resource at {filepath_str}: Choose a valid file.",
      parent=None,
      flags=Qt.Window | Qt.Dialog | Qt.WindowStaysOnTopHint,
  ).exec_()

The above code fails on PyQt5 but mypy does not catch it. The following works however:

filepath_str, _filter = QFileDialog.getSaveFileName(self, "Save As", "", self._saveFilter, "")
if not filepath_str or not filepath_str.strip() or not os.path.exists(filepath_str):
  QMessageBox(
      QMessageBox.Critical,
      "Failed to add resource",
      f"Could not add resource at {filepath_str}: Choose a valid file.",
      parent=None,
      flags=Qt.Window | Qt.Dialog | Qt.WindowStaysOnTopHint,
  ).exec_()
@th3w1zard1
Copy link
Author

th3w1zard1 commented Apr 15, 2024

Python 3.8 supports function sigs like this:


def my_function(arg1, arg2, /, arg3): ...

if you need to support older Python versions, just use a sys.version_info check for < 3.8, and just prefix the title and text args with __

Probably a better way to do this but that's just off the top of my head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant