Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
6.5.3
-
None
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?