Skip to content

Commit

Permalink
Patch error in yacs causing the string '"1234"' being interpreted as …
Browse files Browse the repository at this point in the history
…the number '1234'.
  • Loading branch information
georg-wolflein committed May 5, 2021
1 parent 4712f89 commit 6168602
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions recap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions tests/resources/number_as_string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_BASE_: number_as_string_base.yaml

PROPERTY: "1234"
1 change: 1 addition & 0 deletions tests/resources/number_as_string_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROPERTY:
4 changes: 4 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6168602

Please sign in to comment.