diff --git a/recap/config.py b/recap/config.py index b2b21af..60ae0e7 100644 --- a/recap/config.py +++ b/recap/config.py @@ -50,6 +50,7 @@ def load_yaml_with_base(cls, filename: os.PathLike) -> "CfgNode": base_uri = uri.parent / base_uri base_cfg = cls.load_yaml_with_base(base_uri) del cfg[BASE_KEY] + # base_cfg.merge_with_dict(cfg.params_dict()) base_cfg.merge_from_other_cfg(cfg) return base_cfg return cfg @@ -99,3 +100,10 @@ def params_dict(self) -> Dict[str, Any]: else: params[k] = v return params + + @classmethod + def _decode_cfg_value(cls, value): + # Patch error in yacs causing the string '"1234"' being interpreted as the number '1234'. + if isinstance(value, dict): + return cls(value) + return value diff --git a/tests/resources/number_as_string.yaml b/tests/resources/number_as_string.yaml new file mode 100644 index 0000000..8f5d27b --- /dev/null +++ b/tests/resources/number_as_string.yaml @@ -0,0 +1,3 @@ +_BASE_: number_as_string_base.yaml + +PROPERTY: "1234" diff --git a/tests/resources/number_as_string_base.yaml b/tests/resources/number_as_string_base.yaml new file mode 100644 index 0000000..47e7b3e --- /dev/null +++ b/tests/resources/number_as_string_base.yaml @@ -0,0 +1 @@ +PROPERTY: diff --git a/tests/test_config.py b/tests/test_config.py index cf1dd6b..8330fcc 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -21,3 +21,7 @@ def test_inherit_yaml(): def test_data_type_override(): with pytest.raises(ValueError): cfg = CN.load_yaml_with_base(RESOURCES / "data_type_override.yaml") + +def test_number_as_string(): + cfg = CN.load_yaml_with_base(RESOURCES / "number_as_string.yaml") + assert isinstance(cfg.PROPERTY, str)