New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type is not inferred properly in PyQt5 (Type is Unknown) #4772
Comments
Sorry I couldn't repo. seems to work are you sure you are importing if you right click go to def on
I had to add |
any ideas on why swapping multiple heritance order is affecting member variables repo: from PyQt5.QtWidgets import QMainWindow
class Foo():
pushButton = "button"
class Bar(QMainWindow, Foo):
def __init__(self) -> None:
self.pushButton # type is Unknown
class Bar2(Foo, QMainWindow):
def __init__(self) -> None:
self.pushButton # type is str |
The problem here is that
It looks like many Qt classes ultimately derive from |
I actually checked that there is no static type declaration for PyQt5.sipsimplewrapper.
At least it wasn't a problem when I used it before.
|
If you want to apply a manual fix to your local copy of the library, you can open the from typing import TYPE_CHECKING
if TYPE_CHECKING:
class sipsimplewrapper: ...
|
Wow. I didn't know I could get such a high quality answer. from typing import TYPE_CHECKING
if TYPE_CHECKING:
class sipsimplewrapper: ... The problem was solved by manually adding the code you actually provided to the library file. After reviewing the Pyside6 library code, considering that there is no static type issue like this (sipsimplewrapper does not exist in the first place in Pyside6), I think the library issue is correct. I think all I have to do now is ask the PyQt5 administrator to statically define sipsimplewrapper. (Is it correct?) And I didn't quite understand what you explained in number 3, does the reason why the type is presumed to be Unknown so far means that all type reasoning is broken because the highest class, sipsimplewrapper, was an undefined Any type? |
Environment data
Venv
pip 23.1.2
PyQt5 5.15.9
PyQt5-Qt5 5.15.2
PyQt5-sip 12.12.2
setuptools 65.5.0
//////////////////
pip 23.1.2
PySide6 6.5.2
PySide6-Addons 6.5.2
PySide6-Essentials 6.5.2
setuptools 65.5.0
shiboken6 6.5.2
Code Snippet
PyQt5 example (code in problem situation)
Works fine in PySide6 (weird part)
Expected behavior + Actual behavior
Since Pylance has been updated, the part that inherits the PyQt5 UI does not properly infer the type of the self variable.
For example, in the code above self.pushButton should be inferred as QPushButton . (At least it was in previous versions)
But since Pylance was updated, oddly PyQt5's UI inheritance variable inference doesn't work.
More troubling is that type inference works well in PySide6, which has almost the same implementation as PyQT5.
In the previous pylance version, the uic part of PyQt5 could not be inferred properly, but after the update, the uic part was properly inferred, so I think something has changed in the pylance implementation.
Logs
The text was updated successfully, but these errors were encountered: