Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
6.5.3
-
None
-
-
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
For Gerrit Dashboard: PYSIDE-2517 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
582249,5 | pyi: improve findChild/findChildren type hints | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
583530,2 | pyi: improve findChild/findChildren type hints | 6.7 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
583595,3 | pyi: improve findChild/findChildren type hints | tqtc/lts-6.5 | pyside/tqtc-pyside-setup | Status: MERGED | -1 | 0 |