python-qt-tools / PyQt5-stubs

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

Fix return type of QTableWidget.cellWidget #198

Closed mkrieger1 closed 1 year ago

mkrieger1 commented 1 year 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 1 year ago

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

altendky commented 1 year 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 1 year ago

Sure, thanks!

bluebird75 commented 1 year 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 1 year ago

I will look into it.