Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flag_value paramters are cast with the wrong type #1960

Closed
antoniivanov opened this issue Jun 17, 2021 · 1 comment
Closed

flag_value paramters are cast with the wrong type #1960

antoniivanov opened this issue Jun 17, 2021 · 1 comment

Comments

@antoniivanov
Copy link

antoniivanov commented Jun 17, 2021

Since click 8.0 passing flag_value enum value , it is converting it to string which breaks the CLI. (7.x works fine)

For example

@unique
class Operation(Enum): 
    CREATE = "create"
    UPDATE = "update" 

@click.option(
    "--update",
    "operation",
    flag_value=Operation.UPDATE
)
@click.option(
    "--create",
    "operation",
    flag_value=Operation.CREATE
)
def my_cli(operation)
   if operation == Operation.CREATE: 
       print("create")
  
 if operation == Operation.UPDATE: 
       print("UPDATE")

if are run it with cli --create

Expected behavior

operation is Operation.CREATE of type Operation and the cli prints "create"

Actual behavior
operation is a string with value "Operation.CREATE" and the cli prints nothing

Environment:

  • Python version: 3.7+
  • Click version: 8.0
@davidism
Copy link
Member

The default param type for types that Click does not have special handling for is str. Click does not have special handling for Enum. The processing pipeline was updated to apply type casting to all data sources consistently. Either use type=click.UNPROCESSED or write a custom type to handle enum members.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants