-
-
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
Only the first item when unpacking a function return value gets completions #2040
Comments
Is this also happening without syntax errors. This means if you write it like |
Yes it does |
Sorry, but I cannot reproduce that in Python 3.8 and in Python 3.13. Are you on some weird OS or non-standard thing? You could also try writing a test (see |
Oh that's interesting! Well I am on Arch Linux, but I don't know how non-standard that is. I just tried a bunch of different stuff and I always get the same result:
I also tried the same script in a Windows VM that I have and still got the same result. When you say you cannot reproduce that, do you mean that both print statements in my example return a non-empty list? I will try what you suggested to try that in CI. |
This reproduces for me on 3.8, 3.11 and 3.13 (other version untested) on Ubuntu 22.04. Aside: for some reason I misread the report initially and tried the tuple unpacking first, which then didn't show any issues. |
Yes I confirm that on my end as well removing the annotation on the return type makes the completion work for all the tuple items. I didn't think of trying that because I didn't even know that there was type inference! Also, I tried that through pylsp and got the same result, I do have completion in my editor for all tuple items when I remove the annotation on the return type. |
Sorry, I guess I copy-pasted the wrong sample... If I had to bet, this has to do with the fact that |
So I did some additional testing and I get the exact same behavior with all minor releases until 0.12.0 (I haven't been able to run my example successfully with 0.11.0 because there is a I was not familiar with the codebase at all but I tried to dig a little and this led me to the S{_GenericInstanceWrapper(<TreeInstance of <GenericClass: <ClassValue: <Class: tuple@671-695>>[S{<ClassValue: <Class: int@164-240>>}, S{<ClassValue: <Class: int@164-240>>}]>(<ValuesArguments: []>)>)} so it looks like the annotation is in fact correctly identified as a |
The problem is probably that |
I see. So in fact this has nothing to do with return values from functions, but only with type annotations for tuples. I confirmed that by changing my initial example to: import jedi
code = """\
tup: tuple[int, int] = (1, 2)
a, b = tup
a.foo
b.foo
"""
script = jedi.Script(code, path="example.py")
print(script.complete(3, 2))
print(script.complete(4, 2)) which yields exactly the same behavior I observed (no completion for Also, interestingly, if I replace I propose to update the title and description of the issue to reflect this information, what do you think? Also, does this seem tractable for a first contribution to you? If so, I would appreciate some guidance as to where this special casing should be taking place in the repo :) |
When unpacking the return value of a function which returns a tuple, only the first item of the tuple gets completions.
For example:
yields a correct completion list for
a.
but an empty list forb.
.Output
Output for
a.
:Output for
b.
:This sounds a little like #1389, but this issue is marked as solved so it might be something else.
System setup
I am using
jedi==0.19.2
. I noticed this while using it throughpylsp==1.12.0
, but as shown above in the example I was able to reproduce it with thejedi
library.Note
It works fine when unpacking a regular tuple:
So it seems this is related to function return types.
The text was updated successfully, but these errors were encountered: