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

List:       pykde
Subject:    Re: PyQt6 Signals are not correctly typed
From:       Philippe Fremy <phil () freehackers ! org>
Date:       2022-11-26 9:58:16
Message-ID: 04c59987-20cf-2593-12dc-6aa4dfe4c533 () freehackers ! org
[Download RAW message or body]

Hi Jakub,

The PyQt5/6 default stubs are not suitable for type verification with 
mypy. This is known and this is why we have created external stubs .

Currently, there are official stubs released for PyQt5 and PySide2. 
Stubs for PySide6 and PyQt6 are coming but quite slowly.

As Kyle mentionned, you can already benefit from PyQt6 stubs by using 
the git version. I recreated your example and it type-checks correctly 
with PyQt6-stubs on git :


So, I suggest you do just that.

And don't hesitate to open issues on the GitHub PyQt6-stubs if you see 
something not correctly typed.

Cheers,

Philippe

Le 16/11/2022 à 15:33, Kyle Altendorf a écrit :
> mm, shortcuts that send the email early...
> 
> https://github.com/python-qt-tools/PyQt6-stubs/blob/f623a641cd5cdff53342177e4fbbf9cae8172336/PyQt6-stubs/QtCore.pyi#L29-L52
>  
> The PyQt6-stubs haven't made it to PyPI yet so you'll have to install 
> via `pyqt6-stubs @ git+https://github.com/python-qt-tools/pyqt6-stubs` 
> or similar.
> 
> On Wed, Nov 16, 2022, at 09:31, Kyle Altendorf wrote:
> > The PyQt (and PySide for that matter) official hints need a good bit 
> > of help.  The pyqt5-stubs and pyqt6-stubs are attempts to 1) offer 
> > better hints to users and 2) offer a reference for Phil to work from 
> > to fix the official hints.  I spent a couple years working on PyQt5 
> > stuff but presently have moved on.  There's some other interest in 
> > maintenance, but not a lot of active work (maybe my fault).
> > 
> > For signals, well, we don't have a complete solution but we at least 
> > have something a lot better.
> > 
> > 
> > On Wed, Nov 16, 2022, at 09:24, JakobDev wrote:
> > > I demonstrate it with the attached example. It's a very simple Program
> > > that just shows a Button. If you click the Button, it prints Hello
> > > World. So pretty normal. Now let's run mypy on this. It gives you this
> > > error:
> > > 
> > > testtype.py:13: error: "Callable[[], None]" has no attribute "connect"
> > > Found 1 error in 1 file (checked 1 source file)
> > > 
> > > Now let's open this in PyCharm. PyCharm also shows a error here. Signals
> > > are not correctly typed. It looks like they are typed as function. To be
> > > clear: This here is just a example. It happens with every Signals, which
> > > is annoying if you work on a bigger Project in PyCharm.
> > > 
> > > What makes this these even worse, is that PyQt6 comes with a py.typed
> > > (see PEP561). It basically means, that this package can be considered as
> > > statically and correctly typed.
> > > 
> > > 
> > > *Attachments:*
> > > 
> > > * testtype.py
> > > * PyCharm.png
> > > 
> > 
> 


[Attachment #3 (multipart/related)]

[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Hi Jakub,</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">The PyQt5/6 default stubs are not
      suitable for type verification with mypy. This is known and this
      is why we have created external stubs .</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Currently, there are official stubs
      released for PyQt5 and PySide2. Stubs for PySide6 and PyQt6 are
      coming but quite slowly.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">As Kyle mentionned, you can already
      benefit from PyQt6 stubs by using the git version. I recreated
      your example and it type-checks correctly with PyQt6-stubs on git
      : <br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">
      <blockquote><font face="monospace"><img
            src="cid:part1.B1aQf7DE.BMiRKDmv@freehackers.org" \
alt=""></font></blockquote>  <br>
    </div>
    <div class="moz-cite-prefix">So, I suggest you do just that.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">And don't hesitate to open issues on
      the GitHub PyQt6-stubs if you see something not correctly typed.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Cheers,</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Philippe</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Le 16/11/2022 à 15:33, Kyle Altendorf a
      écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:38c491d6-2ba7-4066-a0d5-e139c86595e1@app.fastmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title></title>
      <style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style>
      <div>mm, shortcuts that send the email early...</div>
      <div><br>
      </div>
      <div><a
href="https://github.com/python-qt-tools/PyQt6-stubs/blob/f623a641cd5cdff53342177e4fbbf9cae8172336/PyQt6-stubs/QtCore.pyi#L29-L52"
  moz-do-not-send="true" \
class="moz-txt-link-freetext">https://github.com/python-qt-tools/PyQt6-stubs/blob/f623a641cd5cdff53342177e4fbbf9cae8172336/PyQt6-stubs/QtCore.pyi#L29-L52</a><br>
  </div>
      <div><br>
      </div>
      <div>The PyQt6-stubs haven't made it to PyPI yet so you'll have to
        install via `pyqt6-stubs @ git+<a
          href="https://github.com/python-qt-tools/pyqt6-stubs"
          moz-do-not-send="true" \
class="moz-txt-link-freetext">https://github.com/python-qt-tools/pyqt6-stubs</a>`  or \
similar.</div>  <div><br>
      </div>
      <div>On Wed, Nov 16, 2022, at 09:31, Kyle Altendorf wrote:<br>
      </div>
      <blockquote type="cite" id="qt" style="">
        <div>The PyQt (and PySide for that matter) official hints need a
          good bit of help.  The pyqt5-stubs and pyqt6-stubs are
          attempts to 1) offer better hints to users and 2) offer a
          reference for Phil to work from to fix the official hints.  I
          spent a couple years working on PyQt5 stuff but presently have
          moved on.  There's some other interest in maintenance, but not
          a lot of active work (maybe my fault).<br>
        </div>
        <div><br>
        </div>
        <div>For signals, well, we don't have a complete solution but we
          at least have something a lot better.<br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>On Wed, Nov 16, 2022, at 09:24, JakobDev wrote:<br>
        </div>
        <blockquote type="cite" id="qt-qt" style="">
          <div>I demonstrate it with the attached example. It's a very
            simple Program<br>
          </div>
          <div>that just shows a Button. If you click the Button, it
            prints Hello<br>
          </div>
          <div>World. So pretty normal. Now let's run mypy on this. It
            gives you this<br>
          </div>
          <div>error:<br>
          </div>
          <div><br>
          </div>
          <div>testtype.py:13: error: "Callable[[], None]" has no
            attribute "connect"<br>
          </div>
          <div>Found 1 error in 1 file (checked 1 source file)<br>
          </div>
          <div><br>
          </div>
          <div>Now let's open this in PyCharm. PyCharm also shows a
            error here. Signals<br>
          </div>
          <div>are not correctly typed. It looks like they are typed as
            function. To be<br>
          </div>
          <div>clear: This here is just a example. It happens with every
            Signals, which<br>
          </div>
          <div>is annoying if you work on a bigger Project in PyCharm.<br>
          </div>
          <div><br>
          </div>
          <div>What makes this these even worse, is that PyQt6 comes
            with a py.typed<br>
          </div>
          <div>(see PEP561). It basically means, that this package can
            be considered as<br>
          </div>
          <div>statically and correctly typed.<br>
          </div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div><b>Attachments:</b><br>
          </div>
          <ul>
            <li>testtype.py<br>
            </li>
            <li>PyCharm.png<br>
            </li>
          </ul>
        </blockquote>
        <div><br>
        </div>
      </blockquote>
      <div><br>
      </div>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>


["e5KTkvcYd1QhSidI.png" (image/png)]

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

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