[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    typing: Slots can return non-None
From:       Florian Bruhin <me () the-compiler ! org>
Date:       2023-06-29 21:53:35
Message-ID: 168807561503.488012.17570486209054715852 () aragog ! localdomain
[Download RAW message or body]


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

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic