Reconciling pyqtProperty and mypy

Florian Bruhin me at the-compiler.org
Wed Aug 19 14:29:19 BST 2020


Hey,

On Tue, Aug 18, 2020 at 02:54:14PM -0400, Ben Green wrote:
> I'm using pyqtProperty a lot, and mypy doesn't seem to play nicely with it.
> When defining the setter, it gives a "name already defined" error. Also,
> since the type is "Callable[..., Any]", instead of the actual type of the
> property, references to that property can give errors.

I dug into the mypy source code and it looks like there's quite some special
casing for properties:

https://github.com/python/mypy/blob/v0.782/mypy/semanal.py#L842-L869
https://github.com/python/mypy/blob/v0.782/mypy/semanal.py#L964-L973

Doesn't look like there's a way to customize it. Perhaps it'd be possible to
write a mypy plugin:

https://mypy.readthedocs.io/en/stable/extending_mypy.html#extending-mypy-using-plugins

But I have no idea if it's possible at all.

On Wed, Aug 19, 2020 at 12:15:38PM +0300, Dmitri Bogomolov wrote:
> Shouldn't the second method have a different name?

Not for properties usually - see the examples:

https://www.riverbankcomputing.com/static/Docs/PyQt5/qt_properties.html
https://docs.python.org/3/library/functions.html#property

Florian

-- 
me at the-compiler.org (Mail/XMPP) | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       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/20200819/50481782/attachment.sig>


More information about the PyQt mailing list