Vscode-python: Argument suggestions for some functions in the pytorch module are duplicated when using Jedi

Created on 23 Jun 2020  路  17Comments  路  Source: microsoft/vscode-python

image

Reproduce

import time
import torch
from torch import nn, optim
import sys
import d2lzh_pytorch as d2l

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')


def nin_block(in_channels, out_channels, kernel_size, stride, padding):
    blk = nn.Sequential(
        nn.Conv2d(in_channels, out_channels, kernel_size, stride, pad)
    )
investigating type-bug

All 17 comments

version: 1.46.1 (user setup)
commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
date: 2020-06-17T21:13:20.174Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363

language server: use Jedi

This is definitely a bug, many function parameter prompts will have duplicate snippets In standard and third-party libraries.
馃槀馃槀馃槀
image
image

@CatNofishing, thanks for letting us know about this. What happens when you use the language server? (In your settings.json, set 'python.languageServer": "Microsoft".)

@ericsnowcurrently Microsoft language server does not have this problem, but some function parameter suggestions are wrong. For example print(sep=)
image

Thanks for checking that. We'd definitely like to resolve any problems you've had with the language server. To that end, I recommend opening a separate issue to address that directly.

If you also want to keep using Jedi then we can investigate further. (Otherwise we can close this issue.) I suspect that Jedi is returning multiple results due to some sort of overloading criteria (possibly due to type annotations), though it might also be a bug in Jedi (or the Python extension). Just keep in mind that our ability to address issues in Jedi is limited.

Either way, you might also consider contacting the Jedi project directly, to get a faster resolution. I've always found @davidhalter to be responsive, helpful, and committed to the success of his project.

What version of Jedi are you using currently?

It would be interesting to see the results with the latest version. If that happens there as well, it would be clearly a bug. (Happy to fix that ASAP).

@davidhalter Thank you for your reply, the jedi version I used is 0.15.2. Vscode is also the latest version馃榿.
@ericsnowcurrently Thank you for your suggestion, but now I prefer Jedi馃槀, because LSP will occupy a lot of memory and CPU. I hope you can keep track of Jedi and make further investigations.

@CatNofishing Can you upgrade to Jedi 0.17.1? It should probably mostly work (and be quite a bit better). If it does not work there I would have to investigate.

@CatNofishing, the Python extension ships with a vendored copy of Jedi, located in "[])https://code.visualstudio.com/docs/editor/extension-gallery#_where-are-extensions-installed)/pythonFiles/lib/python/" and uses that install explicitly for completions, etc. when configured to use Jedi. So to use a newer version you will need to manually replace the vendored copy with the newer one:

#PYEXT_DIR=~/.vscode/extensions/ms-python.python-$(code --list-extensions --show-versions | grep ms-python.python | awk -F'@' '{print $2}')
cd $PYEXT_DIR/pythonFiles/lib
mv jedi jedi.orig
python3 -m pip install --target . jedi

Doing that is fine as a one-off to see if the newer Jedi fixes the problem, but the proper solution is for the Python extension to update the vendored copy.

So if you feel up to manually installing the newer Jedi version, please give it a try. Otherwise we'll need to investigate further on our end. Either way, please let us know. Thanks!

@davidhalter @ericsnowcurrently I upgraded jedi to 0.17.1 through the pip command and set the jedi path in vscode, but the parameter suggestion still has duplicate fragments.

image
image
image
image

Can you run this?

>>> jedi.Script('import os\nos.path.join(p').complete()
[<Completion: path=>, <Completion: PendingDeprecationWarning>, <Completion: PermissionError>, <Completion: pow>, <Completion: print>, <Completion: ProcessLookupError>, <Completion: property>]
>>> jedi.Script('print(sep)').complete(column=9, fuzzy=True)
[<Completion: BaseException>, <Completion: sep=>]

If you get the same output, then VSCode is might be using Jedi wrong. The mistake might be that they add keyword params as completions, when in fact Jedi does that already by itself (so it results in the repeated entries).

image
Thanks for your reply, now I have to turn to Pylance as an alternative. 馃槀

You have to use 0.17.1 to use complete.

Can you try again with 0.17.1? Or use the old API jedi.Script('print(sep)', column=9).complete()?

@davidhalter Thanks your reply!馃榿
image
I got the same output as you, it seems to be a problem with vscode

@ericsnowcurrently @karthiknadig This problem still exists, do you have any plans to fix this problem, otherwise, I can only use pylance as an alternative.

same here ...

@ericsnowcurrently please figure this issue馃槀锛宼his problem seriously affects the development of jedi.

Was this page helpful?
0 / 5 - 0 ratings