WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Using a class as a flag_value causes the default to be instantiated in click 8.3.0 #3121

@jwodder

Description

@jwodder

Consider the following code:

import click

class Foo:
    pass

class Bar:
    pass

@click.command()
@click.option("--foo", "ty", flag_value=Foo, type=click.UNPROCESSED, default=True)
@click.option("--bar", "ty", flag_value=Bar, type=click.UNPROCESSED)
def main(ty):
    click.echo(repr(ty))

if __name__ == "__main__":
    main()

When run with no arguments using click 8.3.0, this prints <__main__.Foo object at 0x10bed92b0>, indicating that Foo has been instantiated, which is not what I want. When using an older version of click, the script outputs <class '__main__.Foo'>, which is what I want.

If the script is passed an explicit --foo or --bar option, a class is output, indicating that the problem lies with the default handling.

Changing the default=True to default=Foo does not help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions