Skip to content

Path(exists=True, envvar='FOO') tries to interpret FOO="" as an existing path #1285

Description

@twosigmajab

Example:

@click.command()
@click.option('--mypath', type=click.Path(exists=True), envvar='MYPATH')
def cli(mypath):
    click.echo(f'mypath: {mypath}')

Test case:

➜ env MYPATH= ./mycli.py

Observed output:

Usage: mycli.py [OPTIONS]
Try "mycli.py --help" for help.

Error: Invalid value for "--mypath": Path "" does not exist.

Expected output:

➜ ./mycli.py
mypath: None

i.e. Shouldn't Click special-case envvar == "" and treat it as though the option wasn't passed? This is more useful than failing with "Path "" does not exist", as it gives users who are inheriting an unwanted env var, and who can only set it to empty string rather than unset, a way to clear it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions