Skip to content

Add stubs for Qt modules#2972

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
maflAT:qt_module_stubs
Apr 18, 2024
Merged

Add stubs for Qt modules#2972
j9ac9k merged 1 commit intopyqtgraph:masterfrom
maflAT:qt_module_stubs

Conversation

@maflAT
Copy link
Copy Markdown
Contributor

@maflAT maflAT commented Mar 27, 2024

Enables editor and type checker support for Qt classes.

This change provides type information to editors and type checkers.

VSCode / Pylance will still report the import statements in the new stubs as missing imports if the given package is not installed. Nevertheless, if at least one of the packages is installed, you can import and use those classes with full auto-complete support.

It would be nice if someone could test if this also works in PyCharm or other editors / type checkers. Unfortunately I'm not able to do so.

Other Tasks

  • Check interaction with VSCode / Pylance
  • Check interaction with PyCharm

Enables editor and type checker support for Qt classes.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 18, 2024

Hi @maflAT

My apologies for not chiming in earlier... thanks for the PR!

This issue has admittedly been a sore point for us for some time... I will test this out right now on both vscode and pycharm 👍🏻

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 18, 2024

Can confirm works on vscode:
image

Can confirm working on pycharm

image

Testing on not PyQt6 also works, thanks so much for this PR @maflAT !!!

@j9ac9k j9ac9k merged commit 086024a into pyqtgraph:master Apr 18, 2024
@maflAT
Copy link
Copy Markdown
Contributor Author

maflAT commented Apr 18, 2024

@j9ac9k my pleasure, thanks for the help with checking!

@maflAT maflAT deleted the qt_module_stubs branch April 18, 2024 08:14
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 25, 2024

Hi @maflAT just a follow up on this, do you know if there is a limitation of reading stubs from relative paths?

pyqtgraph internally uses relative paths, but seems like pyright is not reading the stubs.

example:

Import statement:

from ..Qt import QtCore, QtGui, QtWidgets

Usage of one of the modules:

image

@maflAT
Copy link
Copy Markdown
Contributor Author

maflAT commented May 25, 2024

@j9ac9k I'm not aware of any specific limitations.
However, when I tried to reproduce this, Pylance was acting up for me too.
In one of my virtualenvs it didn't recognize PySide6 at all, even when directly importing PySide6.
In another environment, it works as expected:
grafik

This is with Pylance v2024.5.102 and PySide6 installed (no other Qt bindings).

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 25, 2024

Weird!!! In my case I'm using PyQt6, but I'll try and experiment with more bindings and combinations of dependencies.

Other potential oddity is that I have PyQtGraph installed as an editable install; maybe that behaves differently vs a regular install.

I'll try and tinker with it more when I'm on my computer next.

EDIT: I reinstalled pyqtgraph in my virtual environment w/o using editable install and it worked. Then I uninsrtalled and reinstalled in as an editable install, and the type annotations are working.

I've had this virtualenv around for a while, I'm now wondering if the issue was when I did run pip install -e . it was before the .pyi stubs you included were merged (and if that would matter). Anyway, I'm going to carry on like nothing is wrong and if I see this again, I'll re-install pyqtgraph into that virtualenv.

Thanks for testing locally yourself and following up ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants