Skip to content

Option.is_bool_flag is set to True even if the option is not a flag #1925

@janluke

Description

@janluke

This is relevant only for Click 8.0.1, since the following line was introduced in PR #1913:

self.is_bool_flag = isinstance(self.type, types.BoolParamType)

The solution is as easy as:

self.is_bool_flag = self.is_flag and isinstance(self.type, types.BoolParamType)

Available to open a PR.

Demonstration code

import click

@click.command()
@click.option('--switch', type=bool)
def f(switch):
    print(switch)


if __name__ == '__main__':
    assert not f.params[0].is_flag
    assert f.params[0].is_bool_flag
    f('--switch'.split())
Error: Option '--switch' requires an argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions