typing: Slots can return non-None

Florian Bruhin me at the-compiler.org
Thu Jun 29 22:53:35 BST 2023


Hey,

In QtCore.pyi, PyQt6 claims that:

    PYQT_SLOT = typing.Union[typing.Callable[..., None], pyqtBoundSignal]

which is the defined as the argument to pyqtBoundSignal.connect().

However, the None there is incorrect and should be Any: Slot functions
can return something, the return value just gets ignored when it's used
as a slot.

See e.g.:

	from PyQt6.QtCore import QTimer, QCoreApplication

	def fun() -> int:
		print("timeout")
		return 42

	app = QCoreApplication([])
	t = QTimer()
	t.setInterval(1000)
	t.timeout.connect(fun)
	t.start()
	app.exec()

which works fine but fails mypy on "t.timeout.connect(fun)" with:

    error: Argument 1 to "connect" of "pyqtBoundSignal" has incompatible
    type "Callable[[], int]"; expected "Union[Callable[..., None],
    pyqtBoundSignal]"  [arg-type]

Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230629/6c6115c6/attachment.sig>


More information about the PyQt mailing list