-
Notifications
You must be signed in to change notification settings - Fork 31
self.central_widget.findChildren() has inaccurate output type #216
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
Comments
It does indeed appear that this could be made more aware potentially. I'm not exactly sure offhand how to express this without as many typevars being defined as we want to support, but maybe there's a way. That said, I'm not betting that I personally will get this improved. But who knows, maybe someone, or I, will. Thanks for pointing it out. PyQt5-stubs/PyQt5-stubs/QtCore.pyi Lines 3361 to 3376 in 5047549
|
I moved to PyQt6. It has less type errors. |
if I install the stubs the returned type seems incorrect. For instance, given the code below:
pylance shows: (variable) input_widgets: List[QObject] and I see this error:
Cannot access attribute "setEnabled" for class "QObject"
Attribute "setEnabled" is unknown
while without stubs,
pylance says: (variable) input_widgets: List[QPushButton | QSlider | QLineEdit | QComboBox] and I can autocomplete setEnabled()
I had to install PyQt5-stubs because I noticed that if I inherit from QMainWindow and and use it later like this:
pylance cannot see
main
inSubWindow
properly without stubs so you cannot autocomplete attr1 for instance. I tested definingSubwindow
regularly withoutdataclass
but it didn't help. The problem will be fixed only if I removeQMainWindow
. I don't know why!But installing stubs fixes the later issue. Yet it causes the former issue of getting objects from children and not the exact queries.
I tested the same code with PyQt6 without stubs, and it worked.
The text was updated successfully, but these errors were encountered: