Discussion:
[PyQt] Type annotations for pyqtSignals
Florian Bruhin
2018-11-26 20:44:56 UTC
Permalink
Hi,

(last one... for today :D)

Where Qt has signals, PyQt's type annotations seem to say it's a normal
function - like with QTimer.timeout:

class QTimer(QObject):

[...]

def timeout(self) -> None: ...

Shouldn't signals rather be defined like "timeout: QtCore.pyqtSignal",
which presumably also would make PyCharm suggest their
.connect/.disconnect method properly?

Florian
--
https://www.qutebrowser.org | ***@the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
Phil Thompson
2018-11-26 22:03:12 UTC
Permalink
Post by Florian Bruhin
Hi,
(last one... for today :D)
Where Qt has signals, PyQt's type annotations seem to say it's a normal
[...]
def timeout(self) -> None: ...
Shouldn't signals rather be defined like "timeout: QtCore.pyqtSignal",
which presumably also would make PyCharm suggest their
.connect/.disconnect method properly?
Happy to change it if the behaviour is better (you tell me).

However there are cases where a a signal has the same name (but different signature obviously) as an ordinary method. Would that also work?

Phil
_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
http
Florian Bruhin
2018-11-27 10:46:55 UTC
Permalink
Post by Phil Thompson
Post by Florian Bruhin
Hi,
(last one... for today :D)
Where Qt has signals, PyQt's type annotations seem to say it's a normal
[...]
def timeout(self) -> None: ...
Shouldn't signals rather be defined like "timeout: QtCore.pyqtSignal",
which presumably also would make PyCharm suggest their
.connect/.disconnect method properly?
Happy to change it if the behaviour is better (you tell me).
For mypy it'd certainly be - I haven't tried with PyCharm yet. Is there
someone using PyCharm here who can explain what currently happens with
PyCharm's autocompletion/errors when trying to connect to a signal?
Post by Phil Thompson
However there are cases where a a signal has the same name (but
different signature obviously) as an ordinary method. Would that also
work?
I suppose sip knows which signals behave that way? I guess those could
be defined as:

signalname: Union[QtCore.pyqtSignal, Callable[[args], ret]]

(with args/ret mirroring the signature of the function)

Florian
--
https://www.qutebrowser.org | ***@the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
Loading...