Skip to content

Can't set the default value for multiple options with optional values #2001

@ikapelyukhin

Description

@ikapelyukhin

The following example combines optional values with multiple options:

#!/usr/bin/env python3

import click


@click.command()
@click.option('--label', multiple=True, is_flag=False, flag_value='default')
def cli(label):
    print(label)
    print(f"click.core._flag_needs_value: {click.core._flag_needs_value}")


cli()
$ ./test.py --label --label test
('<object object at 0x7f5ef63ec250>', 'test')
click.core._flag_needs_value: <object object at 0x7f5ef63ec250>

Expected result: ('default', 'test')

Looks like when multiple=True, the sentinel value (click.core._flag_needs_value) is never substituted with the default value specified by flag_value.

Environment:

  • Python version: 3.7.3
  • Click version: 8.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions