Skip to content

Same dest name flag_value and type not working. #1688

@no1xsyzy

Description

@no1xsyzy

Expected Behavior

Tell us what should happen.

import os, click

@click.command()
@click.option('--output-stdout', 'output', flag_value='-')
@click.option('--output-default', 'output', flag_value='/path/to/default/output/location')
@click.option('-o', '--output', type=click.File('w'), default=None)
def edit(output):
    click.echo(type(output))
    click.echo(output)

edit()

with --output option, the provided string should be (lazily) opened.

$ python e.py --output /path/to/file
<class 'click.utils.LazyFile'>
<unopened file '/path/to/file' w>

Actual Behavior

Instead, it is still str

$ python e.py --output /path/to/file
<class 'str'>
/path/to/file

Although --output-stdout and --output-default works as expected.

$ python e.py --output-default
<class 'click.utils.LazyFile'>
<unopened file '/path/to/default/output/location' w>
$ python e.py --output-stdout
<class '_io.TextIOWrapper'>
<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>

But if I put them after --output, they will not work too.

Environment

  • Python version: Python 3.8.6
  • Click version: click==7.1.2

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