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

[Type Hints] Enhance typing of findChild/findChildren

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.8.0, 6.7.3
    • 6.5.3
    • Type hints
    • None
    • All
    • 141d596d1 (dev), 32c6c4e0e (6.7), f0b88e6a3 (tqtc/lts-6.5)

    Description

      The typing of QObject.findChild and QObject.findChildren can be extended so that it returns objects of the type supplied. Current code:

      def findChild(self, type: type, name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...) 
         -> object: ...
      @overload
      def findChildren(self, type: type, name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...)
          -> Iterable: ...
      @overload
      def findChildren(self, type: type, pattern: Union[PySide6.QtCore.QRegularExpression, str], 
            options: PySide6.QtCore.Qt.FindChildOption = ...)
           -> Iterable: ...

      A type variable could be used to dynamically annotate the returned type. Expected:

      ObjectT = TypeVar("ObjectT", bound=QObject)
      def findChild(self, type: type[ObjectT], name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...)
             -> ObjectT: ...
      @overload
      def findChildren(self, type: type[ObjectT], name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...)
          -> Iterable[ObjectT]: ...
      @overload
      def findChildren(self, type: type[ObjectT], pattern: Union[PySide6.QtCore.QRegularExpression, str], options: PySide6.QtCore.Qt.FindChildOption = ...) 
          -> Iterable[ObjectT]: ...

      AFAIK, the returned object for findChildren is always a list.

      Also, the returned object for findChild can be None, so it should be optional?

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            tilmankrummeck Tilman Krummeck
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes