Literal type autocompletion?
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
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.
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 :)
+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?
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.