Replies: 6 comments 11 replies
-
Hi @longqzh Type annotations would be a great thing to add to the library. I believe there are a few places in the code-base that use them already. While I think type-annotating the whole library would be way too large of an effort, but starting to annotate some of the higher use methods/functions would certainly be a good start. I would ask that any PR that includes a substantial amount of type annotations includes a mechanism to verify the type-annotations are correct. This can be tricky to do, but there is a blog post from the urllib3 devs on how they incrementally added type annotations to their library and I suspect something like that would be the way to go in our case: |
Beta Was this translation helpful? Give feedback.
-
Inline annotations would be preferred due to comparability with
pylance/pyright.
…On Thu, Oct 12, 2023 at 18:12 Kyle Sunden ***@***.***> wrote:
I have machinery from matplotlib for e.g. testing stubs against
implementation (it is mostly mypy's stubtest, but with CI configs etc.)
if we choose to go the route of stub files rather than inline type hints.
In general, I prefer inline, but stub files do help avoid risks of
changing runtime behavior unintentionally, so that is why we went that
route on mpl.
—
Reply to this email directly, view it on GitHub
<#2833 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE5Z7WYTBLU5TMYK3ULVXLX7CIOPANCNFSM6AAAAAA5OD3W2M>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hmmm; I wouldn’t be opposed to having the signal file and adding it to
.gitignore so it doesn’t get committed if pylance/pyright can use those
stubs and we get linting inside the editor. Could even add the file as part
of a CI check.
I didn’t think mypy supported verifying the codebase types are correct
against stubs of the same library tho.
…On Fri, Oct 13, 2023 at 09:18 Kyle Sunden ***@***.***> wrote:
I mean, you need to add the py.typed signal file, (and if incomplete may
get complaints from people running eg mypy --strict because of untyped
things)
—
Reply to this email directly, view it on GitHub
<#2833 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE5Z7XU3HTIWVB4Q6G3K2TX7FSVJANCNFSM6AAAAAA5OD3W2M>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
@j9ac9k , @ksunden |
Beta Was this translation helpful? Give feedback.
-
Hello! I think type hints can be really helpful for understanding the structure of a complex codebase, as well as for developing new code. Of course, with editor tools such as PyCharm, VS Code and even Elpy (for Emacs) as well as shell tools such as IPython and qtconsole, type hints can help with code completion on input. Towards understanding the syntax and structure of a framework, type hints can also help with finding the source location for a definition of a type or a function. I think it's not too daunting to add type hints to class and function definitions in pyqtgraph. There might be a number of possible approaches, however? pytgraph is already using Of course, there's also the variety of Qt frameworks - any single one of which may be in use in an application. For this concern, I wonder if there may be any thoughts about integrating with support for qtpy? Perhaps it could be of interest for integrating with applications such as qtconslole (jupyter-qtconsole) which is using qtpy for Qt support. Albeit, Jupyter Kernel integration could introduce a whole other range of complex concerns to a project, but there's the GUI side though? If it might contribute to the codebase to support qtpy in pyqtgraph, beside the support for integrating with external applications, qtpy might also help to provide type hints for the Qt framework. Editor tools might even be able to detect - to some extent - what Qt framework is in use, from what's installed in a virtual environment. For what it's worth, I've managed to hack out a sort of a patch that pulls in qtpy without overriding the Qt library shims in pyqtgraph. It uses the pyqtgraph Qt support first, then some additional patching to ensure qtpy should load the right Qt framework from what was selected in pyqtgraph. It then pulls in the Qt library definitions and type hints, via qtpy, under During the tests here, candidly I've seen some floating-point weirdness at a certain QPointF comparison in one of the tests, using pyqt5 and pyqt6 in a certain development environment, otherwise the patched thing, it passes the tests tho, tested with If it could sound like a plausible idea to add support for qtpy, I'll try to clean up the patch and publish it to a patch branch. Outside of the single QPointF thing the tests passed in the patched code, testing with Python 3.12 (edge??) and Python 3.11 with both of each of the Qt 5 and Qt 6 frameworks on an openSuSE LEAP 15.5 machine. Of course, it would probably need further testing tho |
Beta Was this translation helpful? Give feedback.
-
Published a patch for qtpy integration and type hints via qtpy for feedback/source review. Tested on openSUSE 15.5 and with a local PyQt6 build on FreeBSD 13.2. Open for feedback about the particulars lol |
Beta Was this translation helpful? Give feedback.
-
Hi,
I noticed that there is no type hint in PyQtGraph.
The type hint give us the huge help to avoid typo and improve the development speed in IDE
how about adding the type hint?
If this suggestion is accepted, I will send a PR about it :)
Any suggestion is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions