Skip to content

Commit

Permalink
Allow config overrides to add new keys (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ines authored Sep 3, 2021
1 parent 26c29cc commit 35ac30e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion thinc/about.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "8.0.8"
__version__ = "8.0.9"
__release__ = True
3 changes: 2 additions & 1 deletion thinc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ def _set_overrides(self, config: "ConfigParser", overrides: Dict[str, Any]) -> N
if "." not in key:
raise ConfigValidationError(errors=err, title=err_title)
section, option = key.rsplit(".", 1)
if section not in config or option not in config[section]:
# Check for section and accept if option not in config[section]
if section not in config:
raise ConfigValidationError(errors=err, title=err_title)
config.set(section, option, try_dump_json(value, overrides))

Expand Down
8 changes: 5 additions & 3 deletions thinc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,14 @@ def test_config_from_str_overrides():
assert config["a"]["b"] == 10
assert config["a"]["c"]["d"] == 20
assert config["a"]["c"]["e"] == 3
# Valid values that previously weren't in config
config = Config().from_str(config_str, overrides={"a.c.f": 100})
assert config["a"]["c"]["d"] == 2
assert config["a"]["c"]["e"] == 3
assert config["a"]["c"]["f"] == 100
# Invalid keys and sections
with pytest.raises(ConfigValidationError):
Config().from_str(config_str, overrides={"f": 10})
# Adding new keys that are not in initial config via overrides
with pytest.raises(ConfigValidationError):
Config().from_str(config_str, overrides={"a.b": 10, "a.c.f": 200})
# This currently isn't expected to work, because the dict in f.g is not
# interpreted as a section while the config is still just the configparser
with pytest.raises(ConfigValidationError):
Expand Down

0 comments on commit 35ac30e

Please sign in to comment.