SimpleParsing
SimpleParsing copied to clipboard
Optional Enum's are not parsed properly
Optional enums need to be passed to command line by value instead of name:
import enum
from dataclasses import dataclass
from typing import Optional
from simple_parsing import ArgumentParser
parser = ArgumentParser()
class Color(enum.Enum):
RED = "red"
ORANGE = "orange"
BLUE = "blue"
@dataclass
class MyPreferences:
"""You can use Enums"""
color_one: Optional[Color] = Color.BLUE
color_two: Color = Color.BLUE
parser.add_arguments(MyPreferences, "my_preferences")
parser.parse_args(["--color_one", "red", "--color_two", "RED"]) # This works
parser.parse_args(["--color_one", "RED", "--color_two", "RED"]) # This fails
error: argument --color_one: invalid Color value: 'RED'
Hey @rggjan , thanks for posting!
Indeed, this was mentioned in #62 , and I've been working on a fix in #99 . I need to fix the failing tests for other python versions, and this should be good to go.
Ah, I missed that, thanks a lot!