I have a class that subclasses QObject. Everyting works fine but when I run mypy on it I get the error:
"error: Class cannot subclass 'QObject' (has type 'Any')"
At the moment I am totally stuck. I Have been reading the mypy docs but couldn't find where the error was.
Here the code:
from PyQt5.QtCore import QObject
class ServiceLocator(QObject):
def __init__(self) -> None:
super().__init__()
...
Cheers.
This error occurs when mypy doesn't have type information for a class (in your case due to a lack of stubs) and you have --disallow-subclassing-any
turned on. You can either disable this flag, add typing information, or, as you pointed out, put a # type: ignore
to silence the error.
In order to leave a record on how I get around this I will answer my own question.
As the previous comment suggests, the error arise because mypy
doesn't have information about QObject
. I tried to add the .pyi
files to mypy
in the third-party folder from here or you can try building from sources PyQt5
.
Everything worked but a lot of other errors arose so I finally decided to use:
#type: ignore
on this lines and get rid of the error until type hinting is better supported for this lib.
Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With