Skip to content

Commit 8b0df0d

Browse files
authored
Merge pull request #14 from mmdanggg2/main
Misc type fixes
2 parents 70dd77b + 1d4a508 commit 8b0df0d

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

PySide6-stubs/QtGui.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6112,9 +6112,9 @@ class QPixmap(PySide6.QtGui.QPaintDevice):
61126112
def isQBitmap(self) -> bool: ...
61136113
def load(self, fileName: str, format: Union[bytes, bytearray, memoryview, NoneType] = ..., flags: PySide6.QtCore.Qt.ImageConversionFlag = ...) -> bool: ...
61146114
@overload
6115-
def loadFromData(self, buf: Union[bytes, bytearray, memoryview], format: Union[bytes, bytearray, memoryview, NoneType] = ..., flags: PySide6.QtCore.Qt.ImageConversionFlag = ...) -> bool: ...
6115+
def loadFromData(self, buf: Union[bytes, bytearray, memoryview], format: Union[bytes, bytearray, memoryview, str, NoneType] = ..., flags: PySide6.QtCore.Qt.ImageConversionFlag = ...) -> bool: ...
61166116
@overload
6117-
def loadFromData(self, data: Union[PySide6.QtCore.QByteArray, bytes, bytearray, memoryview], format: Union[bytes, bytearray, memoryview, NoneType] = ..., flags: PySide6.QtCore.Qt.ImageConversionFlag = ...) -> bool: ...
6117+
def loadFromData(self, data: Union[PySide6.QtCore.QByteArray, bytes, bytearray, memoryview], format: Union[bytes, bytearray, memoryview, str, NoneType] = ..., flags: PySide6.QtCore.Qt.ImageConversionFlag = ...) -> bool: ...
61186118
def mask(self) -> PySide6.QtGui.QBitmap: ...
61196119
def metric(self, arg__1: PySide6.QtGui.QPaintDevice.PaintDeviceMetric) -> int: ...
61206120
def paintEngine(self) -> PySide6.QtGui.QPaintEngine: ...
@@ -6796,7 +6796,7 @@ class QRegularExpressionValidator(PySide6.QtGui.QValidator):
67966796

67976797
def regularExpression(self) -> PySide6.QtCore.QRegularExpression: ...
67986798
def setRegularExpression(self, re: Union[PySide6.QtCore.QRegularExpression, str]) -> None: ...
6799-
def validate(self, input: str, pos: int) -> object: ...
6799+
def validate(self, input: str, pos: int) -> tuple[PySide6.QtGui.QValidator.State, str, int]: ...
68006800

68016801

68026802
class QResizeEvent(PySide6.QtCore.QEvent):

PySide6-stubs/QtWidgets.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,7 +4349,7 @@ class QLayout(PySide6.QtCore.QObject, PySide6.QtWidgets.QLayoutItem):
43494349
def invalidate(self) -> None: ...
43504350
def isEmpty(self) -> bool: ...
43514351
def isEnabled(self) -> bool: ...
4352-
def itemAt(self, index: int) -> PySide6.QtWidgets.QLayoutItem: ...
4352+
def itemAt(self, index: int) -> Optional[PySide6.QtWidgets.QLayoutItem]: ...
43534353
def layout(self) -> PySide6.QtWidgets.QLayout: ...
43544354
def maximumSize(self) -> PySide6.QtCore.QSize: ...
43554355
def menuBar(self) -> PySide6.QtWidgets.QWidget: ...
@@ -4375,7 +4375,7 @@ class QLayout(PySide6.QtCore.QObject, PySide6.QtWidgets.QLayoutItem):
43754375
def setSpacing(self, arg__1: int) -> None: ...
43764376
def sizeConstraint(self) -> PySide6.QtWidgets.QLayout.SizeConstraint: ...
43774377
def spacing(self) -> int: ...
4378-
def takeAt(self, index: int) -> PySide6.QtWidgets.QLayoutItem: ...
4378+
def takeAt(self, index: int) -> Optional[PySide6.QtWidgets.QLayoutItem]: ...
43794379
def totalHeightForWidth(self, w: int) -> int: ...
43804380
def totalMaximumSize(self) -> PySide6.QtCore.QSize: ...
43814381
def totalMinimumHeightForWidth(self, w: int) -> int: ...
@@ -4718,9 +4718,9 @@ class QListWidget(PySide6.QtWidgets.QListView):
47184718
def scrollToItem(self, item: PySide6.QtWidgets.QListWidgetItem, hint: PySide6.QtWidgets.QAbstractItemView.ScrollHint = ...) -> None: ...
47194719
def selectedItems(self) -> List[PySide6.QtWidgets.QListWidgetItem]: ...
47204720
@overload
4721-
def setCurrentItem(self, item: PySide6.QtWidgets.QListWidgetItem) -> None: ...
4721+
def setCurrentItem(self, item: Optional[PySide6.QtWidgets.QListWidgetItem]) -> None: ...
47224722
@overload
4723-
def setCurrentItem(self, item: PySide6.QtWidgets.QListWidgetItem, command: PySide6.QtCore.QItemSelectionModel.SelectionFlag) -> None: ...
4723+
def setCurrentItem(self, item: Optional[PySide6.QtWidgets.QListWidgetItem], command: PySide6.QtCore.QItemSelectionModel.SelectionFlag) -> None: ...
47244724
@overload
47254725
def setCurrentRow(self, row: int) -> None: ...
47264726
@overload
@@ -8940,7 +8940,7 @@ class QTreeWidget(PySide6.QtWidgets.QTreeView):
89408940
def collapseItem(self, item: PySide6.QtWidgets.QTreeWidgetItem) -> None: ...
89418941
def columnCount(self) -> int: ...
89428942
def currentColumn(self) -> int: ...
8943-
def currentItem(self) -> PySide6.QtWidgets.QTreeWidgetItem: ...
8943+
def currentItem(self) -> Optional[PySide6.QtWidgets.QTreeWidgetItem]: ...
89448944
def dropEvent(self, event: PySide6.QtGui.QDropEvent) -> None: ...
89458945
def dropMimeData(self, parent: PySide6.QtWidgets.QTreeWidgetItem, index: int, data: PySide6.QtCore.QMimeData, action: PySide6.QtCore.Qt.DropAction) -> bool: ...
89468946
def editItem(self, item: PySide6.QtWidgets.QTreeWidgetItem, column: int = ...) -> None: ...
@@ -8970,9 +8970,9 @@ class QTreeWidget(PySide6.QtWidgets.QTreeView):
89708970
def selectedItems(self) -> List[PySide6.QtWidgets.QTreeWidgetItem]: ...
89718971
def setColumnCount(self, columns: int) -> None: ...
89728972
@overload
8973-
def setCurrentItem(self, item: PySide6.QtWidgets.QTreeWidgetItem) -> None: ...
8973+
def setCurrentItem(self, item: Optional[PySide6.QtWidgets.QTreeWidgetItem]) -> None: ...
89748974
@overload
8975-
def setCurrentItem(self, item: PySide6.QtWidgets.QTreeWidgetItem, column: int) -> None: ...
8975+
def setCurrentItem(self, item: Optional[PySide6.QtWidgets.QTreeWidgetItem], column: int) -> None: ...
89768976
@overload
89778977
def setCurrentItem(self, item: PySide6.QtWidgets.QTreeWidgetItem, column: int, command: PySide6.QtCore.QItemSelectionModel.SelectionFlag) -> None: ...
89788978
def setHeaderItem(self, item: PySide6.QtWidgets.QTreeWidgetItem) -> None: ...
@@ -9048,7 +9048,7 @@ class QTreeWidgetItem(Shiboken.Object):
90489048
def isFirstColumnSpanned(self) -> bool: ...
90499049
def isHidden(self) -> bool: ...
90509050
def isSelected(self) -> bool: ...
9051-
def parent(self) -> PySide6.QtWidgets.QTreeWidgetItem: ...
9051+
def parent(self) -> Optional[PySide6.QtWidgets.QTreeWidgetItem]: ...
90529052
def read(self, in_: PySide6.QtCore.QDataStream) -> None: ...
90539053
def removeChild(self, child: PySide6.QtWidgets.QTreeWidgetItem) -> None: ...
90549054
def setBackground(self, column: int, brush: Union[PySide6.QtGui.QBrush, PySide6.QtCore.Qt.BrushStyle, PySide6.QtCore.Qt.GlobalColor, PySide6.QtGui.QColor, PySide6.QtGui.QGradient, PySide6.QtGui.QImage, PySide6.QtGui.QPixmap]) -> None: ...

tests/qlayout.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
from PySide6.QtWidgets import QGridLayout, QHBoxLayout, QVBoxLayout, QLayout
1+
from typing_extensions import override
2+
from PySide6.QtWidgets import QGridLayout, QHBoxLayout, QVBoxLayout, QLayout, QLayoutItem
23

34
a = QGridLayout(parent=None)
45
b = QHBoxLayout(parent=None)
56
c = QVBoxLayout(parent=None)
7+
8+
class TestLayout(QLayout):
9+
# These can return None
10+
@override
11+
def itemAt(self, index: int) -> 'QLayoutItem | None':
12+
return super().itemAt(index)
13+
14+
@override
15+
def takeAt(self, index: int) -> 'QLayoutItem | None':
16+
return super().takeAt(index)
17+
18+
assert a.itemAt(0) is None
19+
assert a.takeAt(0) is None

tests/qpixmap.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
from PySide6.QtCore import Qt
1+
from PySide6.QtCore import QByteArray, Qt
22
from PySide6.QtGui import QPixmap
33

44
emptyPixmap = QPixmap(16, 16)
55
emptyPixmap.fill(Qt.GlobalColor.transparent)
66
emptyPixmap.fill('white')
77
emptyPixmap.fill(0xFFFFFF)
8+
9+
# Should accept str for format
10+
worlds_smallest_png = QByteArray.fromBase64(b"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg==")
11+
load_pixmap = QPixmap()
12+
load_pixmap.loadFromData(worlds_smallest_png, "PNG")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from PySide6.QtGui import QRegularExpressionValidator, QValidator
2+
3+
4+
v = QRegularExpressionValidator()
5+
6+
valid_info: tuple[QValidator.State, str, int] = v.validate("", 0)
7+
assert isinstance(valid_info, tuple)
8+
assert isinstance(valid_info[0], QValidator.State)
9+
assert isinstance(valid_info[1], str)
10+
assert isinstance(valid_info[2], int)

tests/qtreewidget.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
# default type returned by topLevelItem() should allow None value
1414
topItem = None
1515

16+
t.setCurrentItem(None)
17+
current_item = t.currentItem()
18+
current_item = None

0 commit comments

Comments
 (0)