Skip to content

Commit

Permalink
defaults is now a method
Browse files Browse the repository at this point in the history
  • Loading branch information
soldni committed Sep 20, 2022
1 parent 2134fa3 commit 023834c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "springs"
version = "1.4.2"
version = "1.4.3"
description = "A set of utilities to create and manage typed configuration files effectively, built on top of OmegaConf."
authors = [
{name = "Luca Soldaini", email = "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion src/springs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def from_dataclass(config: Any) -> DictConfig:
return from_none()

if isclass(config) and issubclass(config, FlexyClass):
config = config.defaults
config = config.defaults()

elif not is_dataclass(config):
raise TypeError(f"`{config}` is not a dataclass!")
Expand Down
3 changes: 1 addition & 2 deletions src/springs/flexyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def _unpack_if_dataclass_field(cls, value: Any) -> Any:
return value

@classmethod
@property
def defaults(cls):
"""The default values for the FlexyClass"""

Expand All @@ -59,7 +58,7 @@ def __new__(cls, **kwargs):
# We completely change how the constructor works to allow users
# to use flexyclasses in the same way they would use a dataclass.
factory_dict: Dict[str, Any] = {}
factory_dict = {**cls.defaults, **kwargs}
factory_dict = {**cls.defaults(), **kwargs}
return field(default_factory=lambda: factory_dict)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/test_new_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_second_override(self):
self.assertEqual(out.c._target_, "springs.core")

def test_third_override(self):
override_dict = {"cn": {"c_1": {**ObjConfig.defaults, "bar": 33}}}
override_dict = {"cn": {"c_1": {**ObjConfig.defaults(), "bar": 33}}}

config: DictConfig = OmegaConf.structured(AppCfg)
out = merge(config, OmegaConf.create(override_dict))
Expand Down

0 comments on commit 023834c

Please sign in to comment.