-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to fill config if using *args #47
Comments
A minimal reproducible example: from dataclasses import dataclass
import catalogue
from confection import Config, registry
class Registry(registry):
registry = catalogue.create("psycop", "test_reg")
@dataclass(frozen=True)
class DataClass:
pass
@Registry.registry.register("test_fn")
def test_fn(*args: DataClass):
pass
@Registry.registry.register("dataclass_factory")
def dataclass_factory() -> DataClass:
return DataClass()
config_str = """
[test_fn]
@registry = "test_fn"
[test_fn.*.test_arg]
@registry = "dataclass_factory"
"""
if __name__ == "__main__":
cfg = Config().from_str(text=config_str)
filled = Registry.fill(cfg) Further experimentsIt seems that running .fill also removes any *-arguments. if __name__ == "__main__":
cfg = Config().from_str(text=config_str)
filled = Registry.fill(cfg, validate=False) > cfg
{'test_fn': {'@registry': 'test_fn', '*': {...}}}
> filled
{'test_fn': {'@registry': 'test_fn'}} |
So a bit of experimenting. First of all simplified the example a bit (still breaks):
Seems like avoiding validation works just fine:
but resolving the filled cfg does not work:
this seems to be due to the cfg having the following invalid format:
Where it seemingly deleted an argument during filling. |
Errors seem to arise from the line:
Which seeks to parse:
Where the schema is defined as: print(schema.__fields__)
{'@registry': ModelField(name='@registry', type=str, required=True), 'a': ModelField(name='a', type=Optional[Any], required=False, default=1), 'VARIABLE_POSITIONAL_ARGS': ModelField(name='VARIABLE_POSITIONAL_ARGS', type=Sequence[int], required=True, alias='*')} It seems to expect that [{'arg': 1}] is a |
As for the filtering of Due to |
Thanks for the report(s)! We'll look into this. |
@svlandeg added a PR for solving this issue. |
I'd like to do the filling before resolution, because then I can overwrite the
.cfg
with the filled values. A minimal reproducible example below.The text was updated successfully, but these errors were encountered: