-
Notifications
You must be signed in to change notification settings - Fork 146
Open
Description
Hello I like to use structured configs to have auto completion from the IDE but I have two issues:
First, Literal type annotation is not supported:
from dataclasses import dataclass
from typing import Literal
from omegaconf import OmegaConf
@dataclass
class MyConfig:
mode: Literal["train", "test"] = "train"
conf = OmegaConf.structured(MyConfig)Error:
ValidationError: Unexpected type annotation: Literal[train, test]
full_key: mode
object_type=MyConfig
Second issue is that if I use String Enum's, I cannot provide a string default for it anymore which is pretty annoying!
from dataclasses import dataclass
from typing import Literal
from omegaconf import OmegaConf
from enum import Enum
class Mode(str, Enum):
Train = "train"
Test = "test"
@dataclass
class MyConfig:
mode: Mode = "train"
conf = OmegaConf.structured(MyConfig)Error:
ValidationError: Invalid value 'train', expected one of [Train, Test]
full_key: mode
object_type=MyConfig
To alleviate this I would have to do mode: Mode = Mode("train")which is not very intuitive, so if I had Literal support I wouldn't even need to try Enums.
Thanks very much for this great library. It has helped me immensely.
EternalGoldenBraid, xvyv99, Break-Neck, SamProell, arashsm79 and 1 more
Metadata
Metadata
Assignees
Labels
No labels