-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
Support PEP-0484 .pyi stub files #839
Comments
Good points. I'm not sure yet where we want to go with them. I'm against just ignoring the
What do you mean by that? By the way, I've almost completely rewritten type inference the dev branch. Just saying in case you have looked at master. |
My initial idea was to separate the definition lookup from type lookup. Type lookup could theoretically parse just the Definition lookup could theoretically reuse completion info to find which module a particular symbol comes from and only re-parse that single file if all completion had was a stub. Tricky stuff happens when completions are needed within the same file. I'm not sure what PyCharm does here: should it assume that the stub is up to date and use that possibly missing a signature for a newly defined function? Should it ignore the stub entirely and rely on the evaluator to give it a correct signature? Should we somehow combine both of these relying on symbol names matching? |
Another question is what to do with type signature comments such as |
Are you planning to implement this feature yourself? I'm happy to help you with those questions, because they are really good. However if you're not planning to add this feature, I'll leave them open for a future discussion. |
I'm happy to work on this as I've already worked on a number of tools using Jedi's API (as contributions to plugins for Sublime, Atom and most recently VSCode). I would obviously need your guidance but in exchange would be happy to contribute more docstrings for Jedi internals. |
Another question: how to store overloaded signatures?
|
You need to give me a bit of time, I need to work out a plan first (after the next release). |
Ok. I suggest we ignore the issue with overload for now. I think that is something that we have to track separately. (Because it may appear in normal files as well?!) There's a check that looks for the pep 484 parameters when Jedi executes functions. I think for return values this is good enough. For params there's a similar check I think. At both of these places we could just try to lookup a file that has the I'm not exactly sure where we would need to search for those files. I think one remaining though would be: It shouldn't slow down Jedi too much. Let me know if you need to know more. |
Any updates on this? |
I've added stubs to pycairo recently (the latest release on pypi): https://github.com/pygobject/pycairo/blob/master/cairo/__init__.pyi if someone needs a package to test with |
@lazka thank you for your GTK documentation. It is amazing. |
Wow! Jedi would support .pyi stubs files? This is insanely wonderful. Edit: there will be a problem as I can understand from OP post with .py files of existing module and .pyi files of stubs. |
Any updates on this? I would greatly benefit from support for .pyi files. I also have the use case where I have folders with only .pyi files. So go to definition would hopefully go to the .pyi files themselves as there is no .py file to go to. |
We're actually pretty far on this. Please try the typeshed branch and let me know if there are still issues with it. Once the typeshed branch is working, we can get stubs working in general, because stdlib stubs are already working on that branch. This means that they should also be working in general, only the lookup is missing on PYTHONPATH. So I would say this is 80% done, just needs a bit more effort and a merge to master. |
@davidhalter, I verified that I am able to go to definition to I used a simple script.
If I go-to-definition on the Is this expected behavior or should the go-to-definition on Thanks so much! Let me know if I can do anything to add support for general stubs as that is my primary use case. |
In fact, I would appreciate a code pointer for adding support for general stubs. |
IMO stubs are not there to get you to the stubs (for goto/completions), but to assist type inference and for builtins. So with that branch you should be able to goto the stub of It might at the moment not be possible to use goto properly in all Jedi plugins with the typeshed branch. I have therefore started davidhalter/jedi-vim#915. If you want to test stubs you can checkout the typeshed branch and copy your stubs to |
Sorry, I confused declaration with type definition. Typescript extension actually provides those two where "go to definition" opens a I guess declaration/definition distinction is useful for languages with either header files or where public APIs need to be declared explicitly (like Pascal "units"). Implementation request is for code "specializing" the symbol at hand (extending an abstract base class, implementing a virtual method, implementing the highlighted interface etc.). I think for Python it would be useful to get a list of locations sub-classing the highlighted class or overloading the highlighted method. I'm not sure there's any documentation that describes this in depth other than discussions around the LSP spec mentioning some intended uses or examples of application. |
@davidhalter, could we support stubs for goto_definitions / goto_assignments & autocomplete? For example, suppose there is a file,
and
Facebook Thrift (https://github.com/facebook/fbthrift) is an example of a use case where it generates
I'm willing to help in whatever way I can. cc: @mostafaeweda or @kcaze may be able to answer questions about the differences between the LSP commands. |
@Goom11 Please try stuff like If anything doesn't work for you, please let me know. I'm happy to improve some things. |
How do you guys want to use stubs? Like BTW: @patrys I'm almost done with supporting both goto declaration and goto definition. Still some work is needed, but I'm pretty far. |
Two use cases for me:
|
So for your use case (1), where are the files? Can you give me an example of the original library and the stubs? If possible also with the github links. I'm still not 100% sure how these work and I would like to have examples (that I can test against). Typeshed is of course included by installing Jedi. |
So one case where I would have liked this was when I was doing some stuff
with Kivy a year or so ago. Kivy doesn't provide type stubs and at least at
the time was not covered by typeshed. It's also written in many parts in
cython.
I built some stubs here for the parts I was using:
https://gitlab.com/tonyfinn/mypy-types-kivy which were useful for
typechecking with mypy but we're not picked up for autocomplete because
jedi did not support them.
(Kivy itself can be found at: https://github.com/kivy/kivy )
|
There are two usecases for me:
|
My use case is similar to @The-Compiler 's PyQt5-stubs use case. My use case is using PEP 561 stub-only packages for definitions and completions. These .pyi files would not be included in Typeshed but rather the location of the library would be passed via the sys_path argument to jedi.Script. |
My use case is |
I actually also have the same / similar use case as @hoefling . I have a |
There's a shim called Qt.py which selects either PySide, PySide2, PyQt4 or PyQt5 depending on what is available. This is used as so:
Because of how Qt.py works, autocompletion/intellisense won't work properly of the selected Qt binding but it could work if sidecar stub files were used. I tried these stub files (modified PyQt5 stubs to work with Qt.py) and they worked great in PyCharm, but not in vscode. When contacting the vscode devs, they said this was because stubs were not supported by jedi. @davidhalter Would your additions possibly make this work better now in vscode? @ctismer @cmaureir Are there any stubs bundled with PySide2 which could potentially be used out of the box? |
@fredrikaverpil Not sure if Qt.py is going to work initially, but if it doesn't you can create a separate issue. I'm pretty sure the fix is trivial once PySide2 stubs are working. |
@davidhalter I am guessing I need to be running a different version of jedi inside vscode (than the one bundled) to test this? PySide2 stubs (via Qt.py imports) works fine inside PyCharm with PySide 5.12.3. |
@davidhalter indeed, I include docstrings in stubs; I use them to generate Sphinx docs for C extension modules with a custom Sphinx extension similar to this one. Not sure if it's a common usecase though. |
late to the party, but yeah, we are shipping .pyi files since a couple of versions ago. If you find any issue with them, let us know! |
The whole typeshed/stubs support is now on master. Please test and report errors. Release coming soon. |
v0.14.0 is released 🎆 In the end stubs were way more work than I originally thought - I ended up rewriting all "PEP 484" related things. It took a year and was probably like 3-4 months of work in 8 hour work days. Please test and report bugs. I hope all your requirements are working. Please let me know if they are not. I kind of lost track about all the different use cases. BTW I usually announce releases on twitter as well: https://twitter.com/jedidjah_ch (no spam to be expected) |
@davidhalter ran my tests now with 0.14 and my workarounds (ugly stuff like monkeypatching Looking at the code changes, it's hard to miss a new plugin system - are you planning on making it public, possibly with an easier plugging support (e.g. |
Yeah, there's a plugin system that you may hijack if you want, but the API is just not stable at the moment and may change at any time. I generally intend to release a plugin API at some point, but I'm not really sure, yet what people would use it for. I don't really understand your issues. What would you want to use it for? |
These are not currently supported but it would be useful to have them.
Support is tricky as Jedi seems to do definition discovery and type discover in the same parsing/evaluation pass. My initial ideas was to load a
.pyi
file instead of the.py
file when looking for a module and it seems to work for type inference but can't possibly work for providing actual definitions as in the stub all of the definitions are dummy ellipsis objects (which means names match but things like offsets won't).I think it's safe to follow what mypy does and ignore the
.py
file entirely when doing completion if a.pyi
file exists but it's unclear to me how to decouple completion from the definition provider (go to assignment, go to definition etc.).The text was updated successfully, but these errors were encountered: