Skip to content

flag_value:str and default=False produces str value #3054

@QuLogic

Description

@QuLogic

rasterio has the following code:

@click.option('--all', 'allmd', callback=all_handler, flag_value='like',
              is_eager=True, default=False,
              help="Copy all metadata items from the template file.")

With click 8.2.1, this produced allmd=False (i.e., a boolean value) when called without argument, but in 8.2.2 is produces allmd='False' (i.e., a string).

I have whittled it down to the following minimal example:

import click

@click.command('edit-info', short_help="Edit dataset metadata.")
@click.option('--all', 'allmd', flag_value='like', default=False)
def edit(allmd):
    print(f'HERE is allmd: {allmd!r}')

if __name__ == '__main__':
    edit()

That is, specifying flag_value as a string and default=False together produced a string now, but a boolean a release ago.

A bisection points to 9caedb9 as the first bad commit. I have tested against main (i.e., with #3030 merged) as well, but it is not fixed there.

Environment:

  • Python version: 3.13.3
  • Click version: 8.2.2 and main (10b77f9)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions