Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 stubs files

I've just started a PyQt5 project that is currently running in a virtualenv. PyQt5 was installed using a classic pip install pyqt5.

I want to type check my application using mypy. But when I run it, I get an error telling me that there are no stubs file for PyQt5.

myapp/__main__.py:3: error: No library stub file for module 'PyQt5.QtWidgets

I've checked the site-package of my virtualenv, and indeed, there aren't any .pyi file in it.

Checking the documentation, I see that if compiled, stub files can be generated (and could at least exists beginning with PyQt5.6, I'm using 5.10).

Is there a way to obtain those file without the need to manually compile the library ?

like image 524
Nicolas Appriou Avatar asked Jun 27 '18 10:06

Nicolas Appriou


2 Answers

I had the same problem with PyQt5. So I decided to put up PyQt5-stubs which contains the stub files for the main PyQt5 modules.

You can install it with pip:

$ pip install pyqt5-stubs

Another solution for you would be to change to Qt for Python (PySide2). They provide proper type annotations.

like image 95
MrLeeh Avatar answered Sep 28 '22 11:09

MrLeeh


Not currently.

PEP 561, which specifies how packages should indicate they supply type information, was recently accepted. (Full disclosure, I am the author).

PyQt5 will need to become compliant with the PEP, and then as long as you are using mypy >=0.600, everything should work as expected.

like image 36
ethanhs Avatar answered Sep 28 '22 12:09

ethanhs