jedi icon indicating copy to clipboard operation
jedi copied to clipboard

TypedDict : Suggestion issues

Open yoann9344 opened this issue 2 years ago • 2 comments

I'm making tests about python typing's state of art, and I noticed few issues with TypedDict. I will use -> for start completion and _ for next cursor position.

import typing as t


class Table(t.TypedDict):
    a: int
    b: str


def create(v: Table) -> Table:
    v["a"] += 1  # v["->"] Suggestion and completion are correct 
    v["a"] += 1  # v["->"] Suggestion contains 2 times the row : « "a" string "a" »
    v["a"] += 1  # v["->"] Suggestion contains 3 times the row : « "a" string "a" »
    # and so on, and it is the same for b, each assignment add a suggestion
    print(v["a"])  # print(v["->"] Suggestion contains « "a?!?jedi=1, " »
    # it seems to be caused by a previous assignment
    return v


create()  # create(->) Global suggestion ; should complete with `{_}` or `dict(_)` ?
create({})  # create({->}) Global suggestion :
# should suggest « "a" string "a" » or « "b" string "b" » ?
# should complete with `"a": _` or  `"b": ` ?
# I guess TypedDict's total should not change anything unless we add the coma :
# Total=True : should complete with `"a": _,` or  `"b": "_",` ?
# Total=False : should complete with `"a": _` or  `"b": "_"` ?
create({"a": 5,})
# create({"a": 5,->}) should complete with `b": "_"` (last attribute so without coma)

I'm using jedi through vim-jedi. And I don't think I'm able to fix the issues (at least in a descent amount of time).

yoann9344 avatar Feb 04 '24 16:02 yoann9344

What do you mean with completion vs. suggestion?

print(v["->"] Suggestion contains « "a?!?jedi=1, " »

I'm pretty sure this is related to call signatures. You can either change the setting there to show it differently or turn it off. This sometimes bugs out, but it's definitely not a Jedi bug.

I'm using jedi through vim-jedi. And I don't think I'm able to fix the issues (at least in a descent amount of time).

Yes, these are not easy issues. Some of them however are doable, like the create(->) Global suggestion ; should complete with {}ordict() ?

davidhalter avatar Feb 04 '24 22:02 davidhalter

What do you mean with completion vs. suggestion?

print(v["->"] Suggestion contains « "a?!?jedi=1, " »

It is the propositions for completions, and completions are results when accept proposition : 1981_suggestion_duplicated 1981_suggestion_wrong

Indeed, :let g:jedi#show_call_signatures=2 solved the "a?!?jedi=1, " suggestion but I still have duplicated suggestions for "a" for each previous assignment.

Yes, these are not easy issues. Some of them however are doable, like the create(->) Global suggestion ; should complete with {}ordict() ?

I'll try to start with it !

yoann9344 avatar Feb 06 '24 11:02 yoann9344

I'm closing, because there's https://github.com/davidhalter/jedi/issues/1740.

davidhalter avatar Sep 11 '24 08:09 davidhalter