typer
typer copied to clipboard
Faster Auto-completion
Is your feature request related to a problem
Typer auto-completion becomes slower as the project grows. In my sample application, having only a few imports increases the response time above 100ms. This affects the user experience.
The solution you would like
If there could be some way of defining auto-completion functions in different file, we can only have imports necessary for auto-completion.
I provide a proposal below, but I am not too confident in it due to type-hint discontinuity. This just serves as starting point.
Additional context
""" Calculation of response time """
import time
start = time.perf_counter()
import subprocess # necessary for autocompletion
import typer
import rich.console # not necessary
import pystray # not necessary
import pynput # not necessary
import watchgod # not necessary
print(1000 * (time.perf_counter() - start)) # ~104
""" Draft of proposed API """
## main.py
from typer import Typer, Argument
app = Typer(completion_module="./completion.py")
@app.command()
def branch_autocompletion(name: str = Argument(autocompletion_function="branch_names")): ...
## completion.py
from typer import CompletionModule
def branch_names():
return ("feature", "bug")
completion = CompletionModule({'branch_names': branch_names})