Skip to content

Bug: Optional value not optional anymore #3084

Closed

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

Activity

  1. added theissue type on Sep 24, 2025
  2. Rowlando13 commented on Sep 24, 2025

    @Rowlando13
    Member

    Thanks for the clear report! We will work on this

  3. pawamoy commented on Oct 2, 2025

    @pawamoy

    MkDocs seems to be affected by this again, like with version 8.2.2. Here's how it declares its boolean flags: https://github.com/mkdocs/mkdocs/blob/f68e5fc18d3cd3811dbddfdeda1a57721f9e2e4e/mkdocs/__main__.py#L253-L264. Should MkDocs change something or is Click 8.3.0 suffering from the same kind of issue as 8.2.2?

  4. Rowlando13 commented on Oct 2, 2025

    @Rowlando13
    Member

    This is still broken in 8.3.0.

  5. added 4 commits that reference this issue on Oct 7, 2025
    5c7e719
    552d25d
    f702629
    2f36965
  6. uriii3 commented on Nov 19, 2025

    @uriii3
  7. added a commit that references this issue on Nov 19, 2025
    91de59c
  8. locked as resolved and limited conversation to collaborators on Dec 5, 2025
  9. added this to the 8.3.2 milestone on Feb 18, 2026
  10. added
    parsingParsing, parameters, commands, chaining, context
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsingParsing, parameters, commands, chaining, context

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions