Skip to content
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

Fix bug while parsing dummy mappings (i.e. dict) introduced with lazy args #39

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions fromconfig/parser/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ def _map_fn(item):
if evaluate == EvaluateMode.PARTIAL:

def is_lazy(arg):
# Argument will be parsed before the function itself and hence lazy arguments would have been wrapped into a _LazyArg
return bool(is_mapping(arg) and arg[Keys.ATTR.value] == to_import_string(_LazyArg))
# Argument will be parsed before the function itself and hence lazy arguments would have been
# wrapped into a _LazyArg
return bool(
is_mapping(arg)
and Keys.ATTR.value in arg
and arg[Keys.ATTR.value] == to_import_string(_LazyArg)
)

lazy_args_mask = [is_lazy(arg) for arg in args]
lazy_kwargs_map = {key: is_lazy(value) for key, value in kwargs.items()}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/parser/test_parser_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
"config, expected",
[
pytest.param(None, None, id="none"),
pytest.param({"a": 1, "b": 2}, {"a": 1, "b": 2}, id="dummy_mapping"),
pytest.param({"_attr_": "str", "_eval_": "import"}, str, id="import"),
pytest.param({"_attr_": "str", "_args_": ["hello"], "_eval_": "call"}, "hello", id="call"),
pytest.param({"_attr_": "str", "_args_": ["hello"], "_eval_": "partial"}, lambda: "hello", id="partial"),
pytest.param(
{"_attr_": "str", "_args_": [{"hello": "world"}], "_eval_": "partial"},
lambda: "{'hello': 'world'}",
id="partial_with_dummy_mapping",
),
],
)
def test_parser_evaluate(config, expected):
Expand Down