Skip to content

Commit 620ba6f

Browse files
committed
Fix QObject findChildren and findChild signature
1 parent a889e0b commit 620ba6f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

PySide6-stubs/QtCore.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,11 +5947,11 @@ class QObject(Shiboken.Object):
59475947
def emit(self, arg__1: Union[bytes, bytearray, memoryview], *args: None) -> bool: ...
59485948
def event(self, event: PySide6.QtCore.QEvent) -> bool: ...
59495949
def eventFilter(self, watched: PySide6.QtCore.QObject, event: PySide6.QtCore.QEvent) -> bool: ...
5950-
def findChild(self, type: type, name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...) -> Optional[PlaceHolderType]: ...
5950+
def findChild(self, type: Type[PlaceHolderType], name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...) -> Optional[PlaceHolderType]: ...
59515951
@overload
5952-
def findChildren(self, type: type, name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...) -> Iterable[PlaceHolderType]: ...
5952+
def findChildren(self, type: Type[PlaceHolderType], name: str = ..., options: PySide6.QtCore.Qt.FindChildOption = ...) -> List[PlaceHolderType]: ...
59535953
@overload
5954-
def findChildren(self, type: type, pattern: Union[PySide6.QtCore.QRegularExpression, str], options: PySide6.QtCore.Qt.FindChildOption = ...) -> Iterable[PlaceHolderType]: ...
5954+
def findChildren(self, type: Type[PlaceHolderType], pattern: Union[PySide6.QtCore.QRegularExpression, str], options: PySide6.QtCore.Qt.FindChildOption = ...) -> List[PlaceHolderType]: ...
59555955
def inherits(self, classname: str) -> bool: ...
59565956
def installEventFilter(self, filterObj: PySide6.QtCore.QObject) -> None: ...
59575957
def isQuickItemType(self) -> bool: ...

tests/qobject.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Iterable
1+
from typing import List, Iterable, Optional
22

33
from PySide6.QtCore import QObject
44
from PySide6.QtWidgets import QWidget, QApplication
@@ -7,9 +7,11 @@
77
app = QApplication([])
88

99
o1 = QWidget()
10-
o2 = QWidget(o1)
10+
w2 = QWidget(o1)
1111
o3 = QObject(o1)
1212

13+
### QObject.findChildren()
14+
1315
a: List[QObject]
1416
a = o1.findChildren(QObject)
1517
assert type(a) == list
@@ -22,12 +24,23 @@
2224

2325
# incorrect here, correctly detected by mypy
2426
c: List[QWidget]
25-
c = o1.findChildren(QObject, '')
27+
c = o1.findChildren(QObject, '') # type: ignore[arg-type]
2628

2729
# cast works, List[QWidget] is a List[QObject]
2830
d: List[QObject]
2931
d = o1.findChildren(QWidget, '')
3032

33+
34+
### QObject.findChild()
35+
w3: Optional[QWidget] = None
36+
w3 = o1.findChild(QWidget)
37+
38+
# incorrect here, correctly detected by mypy
39+
w3 = o1.findChild(QObject) # type: ignore[assignment]
40+
41+
42+
### inherits and other methods
43+
3144
o1.inherits('toto')
3245
try:
3346
o1.inherits(b'toto') # type: ignore[arg-type]

0 commit comments

Comments
 (0)