[PyQt] Type annotations for pyqtSignals

Florian Bruhin me at the-compiler.org
Tue Nov 27 10:46:55 GMT 2018


On Mon, Nov 26, 2018 at 10:03:12PM +0000, Phil Thompson wrote:
> On 26 Nov 2018, at 8:44 pm, Florian Bruhin <me at the-compiler.org> wrote:
> > 
> > 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?
> 
> 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?

> 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 | me at 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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181127/f330471e/attachment-0001.sig>


More information about the PyQt mailing list