Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2147

mypy cannot find public Qt signals at all

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • all
    • PySide
    • None
    • Windows
    • All

    Description

      This is not an issue report per se (as there's probably nothing wrong with PySide), but an issue with mypy and how it can't find public Qt signals if using composition. Let me explain.

      Okay, let's look at an example:

      from PySide6 import QtCore, QtWidgets
      
      class ChessClock(QtWidgets.QLCDNumber):
       """A chess clock widget that displays the remaining time of a chess game."""
      
          def __init__(self) -> None:
              super().__init__()
      
              self._timer: QtCore.QTimer = QtCore.QTimer()
              self._timer.timeout.connect(self.update_time)
      
          def update_time(self):
              pass
      

      In this case, mypy nags with

      mypy: error
      attr-defined - "QTimer" has no attribute "timeout"
      

      But if I define a separate class that inherits from QtCore.QTimer, then mypy successfully finds the timeout signal and doesn't nag (so, inheritance seems to be okay for mypy).

      However, mypy can't find the timeout signal if QtCore.QTimer() is inserted as a component class in a composite class such as in the example above. Therefore, composition seems to be a struggle for mypy, but inheritance is perfectly fine for it. Strange, huh?

      Is this a limitation of mypy or is PySide's overall design (heavy inheritance) the cause for this?

      Is composition even reasonable in PySide, given the fact that the overall class design in PySide is just one big inheritance?

      Please advise what I should do for mypy to find public Qt signals, even though composition is used, as in the example above.

      Thank you in advance.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ctismer Christian Tismer
              pedantichacker BoĊĦtjan Mejak
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes