You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to limit the possible values of a field in a config yaml file using type hints? I want to limit the values of the STEP_NAME variable in step1.yaml to only 2 values: "extract_info" and "run_ovp"
I tried using the Literal["extract_info", "run_ovp"] type but it threw an error. When the type was str it worked fine
Checklist
[ X] I checked on the latest version of Hydra
[ X] I created a minimal repro (See this for tips).
To reproduce
** Minimal Code/Config snippet to reproduce **
Directory structure:
importloggingfromdataclassesimportdataclassimportosfromtypingimportLiteral, UnionfromenumimportEnumfromomegaconfimportDictConfig, OmegaConf, MISSINGimporthydrafromhydra.core.config_storeimportConfigStore# A logger for this filelog=logging.getLogger(__name__)
# +@dataclassclassstep1:
STEP_NAME: Literal["extract_info", "run_ovp", "???"] =MISSING#read this from step1.yaml and limit the step name to 2 possible values@dataclassclassConfig:
step=MISSING# -cs=ConfigStore.instance()
cs.store(name="config", node=Config)
cs.store(group="step", name="step1", node=step1)
@hydra.main(config_path='conf/hydra_all_confs', config_name="config")defmy_app(cfg: DictConfig) ->None:
log.debug(cfg)
log.info(OmegaConf.to_yaml(cfg))
log.info("Working directory : {}".format(os.getcwd()))
if__name__=="__main__":
my_app()
Content of config.yaml
defaults:
- step: ??? #want user to provide this at run time
🐛 Bug
Description
Is it possible to limit the possible values of a field in a config yaml file using type hints? I want to limit the values of the
STEP_NAME
variable instep1.yaml
to only 2 values:"extract_info"
and"run_ovp"
I tried using the
Literal["extract_info", "run_ovp"]
type but it threw an error. When the type wasstr
it worked fineChecklist
To reproduce
** Minimal Code/Config snippet to reproduce **
Directory structure:
Content of hydra_test_app.py
Content of config.yaml
** Stack trace/error message **
Expected Behavior
System information
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: