Skip to content

Bug: Optional value not optional anymore #3084

@axelbringenberg

Description

@axelbringenberg

Outline

As stated in official documentation:

Setting is_flag=False, flag_value=value tells Click that the option can still be passed a value, but if only the flag is given, the value will be flag_value.

Since 8.3.0 this doesn't work anymore, instead SystemExit with "Error: Option '--xyz' requires an argument." is thrown.

Replication of bug

Example taken from documentation:

@click.command()
@click.option("--name", is_flag=False, flag_value="Flag", default="Default")
def hello(name):
    click.echo(f"Hello, {name}!")
$ hello --name
Error: Option '--name' requires an argument.

Expected behavior

The code example above should work as

$ hello --name
Hello, Flag!

It's not even working in the generated documentation anymore: while documentation up to Sep, 10th shows the expected and correct behavior, current documentation demonstrates the bug.

  • Python version: 3.11
  • Click version: 8.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions