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: Unresolved
    • P4: Low
    • None
    • 6.5.3
    • Type hints
    • None
    • All

    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:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes