I got a below code:
# settings.yaml
my_class:
columns_id: ${oc.env:MY_LIST}
all_columns: {"all_columns_as_str": ${oc.env:MY_LIST}}
where my variable is MY_LIST=a,b,c
then I got:
# hydra_conf.py
from dataclasses import dataclass
@dataclass
class MyClass:
columns_id: list
all_columns: dict[str, str]
and then I use it all like below:
# main.py
import hydra
from hydra_conf import MyClass
@hydra.main(config_path="settings", config_name="settings")
def main(cfg: MyClass) -> None:
assert isinstance(cfg.columns_id, list)
assert isinstance(cfg.all_columns, dict)
assert cfg.all_columns['all_columns_as_str'] == 'a,b,c'
How I need to configure my yml.file or my hydra_conf.py file to load columns_id as list and all_columns as a dict[str, str]?
Give this a try:
Here's how this works:
my_class_schemain the defaults list means that your yaml file will be merged with the schema defined byMyClass. See the Hydra docs on Structured Configs (and specifically on using a Structured Config Schema) for more info about this."[${oc.env:MY_LIST}]"results in"[a,b,c]"after the interpolation is resolved.oc.decoderesolver parses the string"[a,b,c]", resulting in["a", "b", "c"].