Various stub improvements and Pyright support #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, this PR contains a number of stub improvements along with support for running tests against Pyright. Additionally, the PR drops support for Python 3.6 and 3.7 as they are now EOL, and newer versions of Pyright don't support them (and older versions seem to have issues type checking the tests properly). Alternatively we could keep Python 3.6 support, but simply not run the tests against Pyright for versions prior to 3.8; let me know which you would prefer.
I also updated the workflows and contributing guidelines to use
pip install -e . --config-settings editable_mode=strict
for installing the stubs in editable mode. This option is a workaround for a change in how recent versions of setuptools do editable installs, see related Mypy issue. (Would there be interest in moving to Poetry instead to not have to deal with this? Poetry would make dealing with development dependencies and juggling multiple Python versions easier too.)Additionally, I removed
PySide2
as a hard dependency, as it's not technically needed for type checking, and the user may have their own PySide2 distribution they'd like to use rather than one fetched from PyPI.The concrete changes to the stubs are as follows:
QtCore.Property
as a descriptor, allowing reading and writing to properties to type check correctlyProperty
is not actually a descriptor; the magic of assigning to and reading from properties happens inQObject
's__getattribute__
and__setattr__
. However, I can't think of a way that we could possibly type hint__getattribute__(self, name)
to say that "if name corresponds to aProperty[T]
, return a value of typeT
".Qt.WindowType
andQt.WindowFlags
qmlRegisterType
arguments to bestr
instead ofbytes
(same issue as withproperty
/setProperty
)QEnum
andQFlag
for use as class decoratorsQObjectT