Skip to content

[FEATURE] Use enum.name as parameter, and enum.value as value received by the function #151

@sapristi

Description

@sapristi

Is your feature request related to a problem

I would like to be able to unleash the power of Enum ! The first case I stumbled onto is that of logging, e.g have the following Enum usable in typer:

class LogLevel(Enum):
    debug = 10
    info = 20
    warning = 30

Instead I have to use this one, and then convert the string to the right value

class LogLevel(Enum):
    debug = "debug"
    info = "info"
    warning = "warning"

The solution you would like

I would like typer to interpret the value.name as arguments, and provide value.value to the called function, so that the following program would work as intended:

from enum import Enum
import typer
import logging

logger = logging.getLogger(__name__)

class LogLevel(Enum):
    debug = logging.DEBUG
    info = logging.INFO
    warning = logging.WARNING

def main(
        level: LogLevel,
):
    logger.setLevel(level)
    ...

if __name__ == "__main__":
    typer.run(main)

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