Skip to content

Add a pyi stub file to import best-guess pyqt type hints#2358

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
outofculture:pyi-qt
Jul 12, 2022
Merged

Add a pyi stub file to import best-guess pyqt type hints#2358
j9ac9k merged 3 commits intopyqtgraph:masterfrom
outofculture:pyi-qt

Conversation

@outofculture
Copy link
Copy Markdown
Contributor

This will help most editors with guessing how the Qt objects should behave.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 12, 2022

I should add that pylance does not read in .pyi files, so this seems to only help out when using PyCharm, but still better than nothing!

@j9ac9k j9ac9k merged commit 86b174d into pyqtgraph:master Jul 12, 2022
@ntjess
Copy link
Copy Markdown
Contributor

ntjess commented Aug 23, 2022

Just saw this, neat to know it was accepted :)

I added extra things to my pyi file to fully replicate what is available from the created Qt module. Here is everything after the ImportError matrix:

def mkQApp(name=None) -> QtWidgets.QApplication: ...
def exec_() -> int: ...

QAPP: Optional[QtWidgets.QApplication]
QT_LIB: str

USE_PYSIDE: bool
USE_PYQT4: bool
USE_PYQT5: bool

PYSIDE: str
PYSIDE2: str
PYSIDE6: str
PYQT4: str
PYQT5: str
PYQT6: str

def __getattr__(name) -> Any: ...

Is it worth including these in the pyi
A few things:

  • Note that without __getattr__, accessing any of these extra attributes will be seen by PyCharm as an error.
  • QAPP can be None, so I think Optional is appropriate to add
  • exec_ returns int, not QApplication

j9ac9k added a commit to j9ac9k/pyqtgraph that referenced this pull request Aug 23, 2022
)

* stub file to import best-guess pyqt type hints

* Move file to __init__.pyi

* Raise specific exception so linters do not have a cow.

Co-authored-by: Ognyan Moore <ognyan.moore@gmail.com>
j9ac9k added a commit to j9ac9k/pyqtgraph that referenced this pull request Aug 23, 2022
)

* stub file to import best-guess pyqt type hints

* Move file to __init__.pyi

* Raise specific exception so linters do not have a cow.

Co-authored-by: Ognyan Moore <ognyan.moore@gmail.com>
j9ac9k added a commit to j9ac9k/pyqtgraph that referenced this pull request Aug 23, 2022
)

* stub file to import best-guess pyqt type hints

* Move file to __init__.pyi

* Raise specific exception so linters do not have a cow.

Co-authored-by: Ognyan Moore <ognyan.moore@gmail.com>
j9ac9k added a commit to j9ac9k/pyqtgraph that referenced this pull request Aug 23, 2022
)

* stub file to import best-guess pyqt type hints

* Move file to __init__.pyi

* Raise specific exception so linters do not have a cow.

Co-authored-by: Ognyan Moore <ognyan.moore@gmail.com>
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.

3 participants