python-qt-tools / PyQt5-stubs

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

Connecting to a slot that returns something. #131

Closed TilmanK closed 3 years ago

TilmanK commented 3 years ago

Mypy complains when connecting any signal to a slot, that would actually return something other than None/void.

A good example is QWidget.close() which returns a bool. When connecting a signal to this slot, mypy complains:

Argument 1 to "connect" of "pyqtSignal" has incompatible type "Callable[[], bool]"; expected "Union[Callable[..., None], pyqtBoundSignal]"

I guess return value should accept Callable[[], Any], no?

BryceBeagle commented 3 years ago

Seems reasonable to me :+1:

altendky commented 3 years ago

https://github.com/python-qt-tools/PyQt5-stubs/commit/fba0ed6a00bb1f43b94bcffb06682eef0d85b53f https://github.com/python-qt-tools/PyQt5-stubs/blob/2a97b494ce7b5a7bed0087c27b89758399e6a7ae/PyQt5-stubs/QtCore.pyi#L58

The callable's return type is presently set to object. This should accept any type. Unlike Any, this doesn't allow code to presume any attribute exists on the returned object.

altendky commented 3 years ago

(sorry we haven't gotten a release out, maybe 'soon'...)

TilmanK commented 3 years ago

Yeah, I really hope to see a release soon. Can't wait to remove a lot of # type: ignore ;),