typer
typer copied to clipboard
No autocompletion and syntax highlighting in callback for typer.Context but they work using click.Context
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Typer documentation, with the integrated search.
- [X] I already searched in Google "How to X in Typer" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to Typer but to Click.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
import click
import typer
def validate_name_typer(ctx: typer.Context, param: typer.CallbackParam, value: str) -> str:
params = ctx.command.params # Autocompletion and syntax highlighting don't work
return value
def validate_name_click(ctx: click.Context, param: typer.CallbackParam, value: str) -> str:
params = ctx.command.params # Autocompletion and syntax highlighting work
return value
def main(name: str= typer.Option(...,callback=validate_name_typer)):
typer.echo(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)
Description
On VSCode, I don't have autocompletion for the context in a callback. I am not sure where it comes from but this definitely seems a typer issue since it is working with Click.
I added both in the example.
EDIT: I am here trying to get other options from this callback.
Operating System
Linux
Operating System Details
$ cat /etc/os-release
NAME="Manjaro Linux" ID=manjaro ID_LIKE=arch BUILD_ID=rolling PRETTY_NAME="Manjaro Linux" ANSI_COLOR="32;1;24;144;200" HOME_URL="https://manjaro.org/" DOCUMENTATION_URL="https://wiki.manjaro.org/" SUPPORT_URL="https://manjaro.org/" BUG_REPORT_URL="https://bugs.manjaro.org/" LOGO=manjarolinux
Typer Version
0.4.0
Python Version
3.9.9
Additional Context
No response
having a similar weird issue where autocompletion is working fine in bash/osx, but in pwsh/win11 some of my autocomplete works, but others fail in the same script.
For example using def hi(name: List[str] = typer.Argument(..., autocompletion=something)): ...
works fine to suggest completions starting from empty name
or partial string, but if I drop the List
and do def hi(name: str = typer.Argument(..., autocompletion=something)): ...
then I get autocomplete suggestions if I [tab][tab] from an empty argument, but as soon as I have one or more characters incomplete string then [tab][tab] gives nothing and apparently my callback something
isn't even called.
Tried various combinations of typer/click version but can't find a clue yet.
btw in your example you're using autocompletion
rather than callback
for typer?