-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
typer.Argument with autocompletion #334
Comments
this (mostly) works for me using |
@patricksurry autocompletion works, but it is deprecated in click
I'm still unable to make Arguments work with shell_complete. On the opposite, shell_complete works very well with Options. This is the situation, at least for me:
|
which shell are you using with does that mean the typer docs are out of date? they don't seem to mention shell_completion. i wonder if the deprecation warning itself (via |
I'm using bash (on Ubuntu 20.04). But I assume (maybe I'm wrong) that completion should work on the shell because it works with Options. In case of troubles at shell level I was expecting the completion to don't work at all You are right about the docs, no mention of shell_complete. There is a test with typer.Option + shell_complete But nothing with typer.Argument + shell_complete The lack of documentation may suggest that the support is still not completed. I think that only @tiangolo can clarify |
I experience exactly the same behaviour / error: |
This issue seems to be fixed, at least when using Ubuntu 22.04, env: |
This is in fact a very simple bug. The shell_complete parameter is not passed to TyperArgument. See here. I will submit a PR. |
If anyone has the ability to switch this issue label to a bug that would be appreciated! It might be a while before my PR is merged so, here's the most minimally invasive monkey patch I could come up with to fix this: from typer import __version__
if (0, 4, 0) <= tuple(int(v) for v in __version__.split(".")) <= (0, 13, 0):
from typer import main as typer_main
from typer.models import ParamMeta
upstream_get_click_param = typer_main.get_click_param
def patched_get_click_param(
param: ParamMeta,
) -> t.Tuple[t.Union[click.Argument, click.Option], t.Any]:
"""
Patch this bug: https://github.com/tiangolo/typer/issues/334
"""
click_param = upstream_get_click_param(param)
if isinstance(click_param[0], click.Argument) and getattr(
param.default, "shell_complete", None
):
click_param[0]._custom_shell_complete = param.default.shell_complete
return click_param
typer_main.get_click_param = patched_get_click_param |
Hi @mdantonio, @patricksurry, @torstello and @bckohan! I would like to draw your attention to #949 and #974. In summary, we've decided to stick to I just wanted to check with you whether that works for you, or whether there are use-cases you can't cover with the original |
makes sense, thank you |
First Check
Commit to Help
Example Code
Description
I'm trying to enable shell complete on an Argument but it does not work. On the opposite with Options everything is working as expected
I think that the same problem was already in the previous versions of typer (so that it is NOT introduced by typer 0.4.0 & click 8... but i'm not totally sure about that)
Based on tests on click, shell_complete on arguments should work: https://github.com/pallets/click/blob/48cb86d85fc1abfcf1478ee660e42aaa5382fd64/examples/completion/completion.py#L25
in typer I can't find tests with arguments, I only found this with option https://github.com/tiangolo/typer/blob/a1520dcda685220a9a796288f5eaaebd00d68845/tests/assets/compat_click7_8.py#L20
Operating System
Linux
Operating System Details
Ubuntu 20.04
Typer Version
0.4.0
Python Version
Python 3.9.5
Additional Context
click 8.0.1
The text was updated successfully, but these errors were encountered: