python-qt-tools / PyQt5-stubs

Stubs for PyQt5
GNU General Public License v3.0
68 stars 31 forks source link

Fix return type of QTableWidget.cellWidget #198

Closed mkrieger1 closed 2 years ago

mkrieger1 commented 2 years ago

cellWidget returns a QWidget if it exists, or None if it doesn't exist.

Confirmed by this short script:

from PyQt5 import QtCore, QtWidgets

print(f'Qt {QtCore.QT_VERSION_STR}')
print(f'PyQt {QtCore.PYQT_VERSION_STR}')

app = QtWidgets.QApplication(['foo'])
table = QtWidgets.QTableWidget(1, 1)

# empty cell inside table
print(table.cellWidget(0, 0))

# filled cell inside table
table.setCellWidget(0, 0, QtWidgets.QWidget())
print(table.cellWidget(0, 0))

# cell outside table
print(table.cellWidget(99, 99))

Output:

Qt 5.15.2
PyQt 5.15.6
None
<PyQt5.QtWidgets.QWidget object at 0x7fa13208bca0>
None
altendky commented 2 years ago

Looking at fixing main CI in https://github.com/python-qt-tools/PyQt5-stubs/pull/199.

altendky commented 2 years ago

I hope you don't mind me jumping in and pushing a few details here. Just saves the back and forth which can be long when I know I haven't been particularly responsive.

But, thanks for the correction!

mkrieger1 commented 2 years ago

Sure, thanks!

bluebird75 commented 2 years ago

If you can add a test for this, that would be even better. The spirit of the tests is to run very small code snippets and make sure they typecheck correctly.

mkrieger1 commented 2 years ago

I will look into it.