jedi icon indicating copy to clipboard operation
jedi copied to clipboard

Literal type autocompletion?

Open illume opened this issue 5 years ago • 4 comments

Literal types let you specify valid inputs, which potentially provides an elegant interface...

SystemCursors = Literal["arrow", "ibeam", "wait", "crosshair", "waitarrow",
    "size_nwse", "size_we", "size_ns", "size", "no", "hand"]

def set_cursor(cursor: SystemCursors) -> None:
    pass

set_cursor("wait") #autocomplete on the literals would be nice here.

Could jedi eventually use Literal types with autocomplete?

Related pygame issue: https://github.com/pygame/pygame/pull/2331

illume avatar Nov 29 '20 20:11 illume

So I suppose you mean that in set_cursor we would autocomplete "wait" or "ibeam" or all the other cases.

IMO that would be a really nice feature. It's pretty unlikely that this is going to happen soon, but I'm definitely in favor, so I will keep it open. The hard part here is not the completion part, it's that you have to infer the type that is needed at a specific position, which is not something Jedi can do, at the moment.

It wouldn't be an extreme amount of work, but it's definitely a few hours up to days and I'm likely not going to do it unless a lot of people start using Literal.

davidhalter avatar Dec 01 '20 17:12 davidhalter

So I suppose you mean that in set_cursor we would autocomplete "wait" or "ibeam" or all the other cases.

Indeed.

  • set_cursor("a -> ["arrow"]
  • set_cursor("s -> ["size_nwse", "size_we", "size_ns", "size"]

It wouldn't be an extreme amount of work, but it's definitely a few hours up to days and I'm likely not going to do it unless a lot of people start using Literal.

Sounds reasonable :)

illume avatar Dec 03 '20 10:12 illume

+1 We're making more use of Literal types in python and this would be really handy for us. @davidhalter I may take a stab at this, any pointers on where I'd need to plug it in?

mofojed avatar Nov 09 '23 21:11 mofojed

Hmm, this is a hard one. It's probably next to the other string completions. So somewhere in jedi/api/completions.py. But then you also need to do the inference and maybe improve literal support within Jedi.

davidhalter avatar Nov 10 '23 00:11 davidhalter