click icon indicating copy to clipboard operation
click copied to clipboard

Click shell completion can trigger parameter callbacks unexpectedly

Open archiep867-sys opened this issue 1 month ago • 0 comments

Description

Shell completion can execute parameter callbacks while Click is only trying to determine completion information.

This can cause application code to run during tab completion even though the command has not been invoked.

Minimal reproduction

import click

def callback(ctx, param, value):
    print("CALLBACK EXECUTED", file=__import__("sys").stderr)
    return value

@click.command()
@click.option("--name", callback=callback)
def cli(name):
    click.echo(name)

if __name__ == "__main__":
    cli()

archiep867-sys avatar Oct 08 '26 05:10 archiep867-sys