diff --git a/CHANGELOG.md b/CHANGELOG.md index 756d14cfb..ff32a7ccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed unassigned variable names - Contributing guidelines steps for installing for the first time - Updated gitignore to ignore yarn files and folders for latest version of yarn +- Fixed the bug that caused ValueError error when using KEYWORD_ONLY parameter in electron func +- changed code at line 218 in covalent/_shared_files/utils.py ### Operations diff --git a/covalent/_shared_files/utils.py b/covalent/_shared_files/utils.py index 14136f6e3..48e268704 100644 --- a/covalent/_shared_files/utils.py +++ b/covalent/_shared_files/utils.py @@ -212,10 +212,13 @@ def get_named_params(func, args, kwargs): elif param.kind == param.VAR_POSITIONAL: for i in range(ind, len(args)): named_args[f"arg[{i}]"] = args[i] - elif param.kind in [param.KEYWORD_ONLY, param.VAR_KEYWORD]: + elif param.kind == param.VAR_KEYWORD: for key, value in kwargs.items(): if key != param_name: named_kwargs[key] = value + elif param.kind == param.KEYWORD_ONLY: + if param_name in kwargs: + named_kwargs[param_name] = kwargs[param_name] if len(args) > len(named_args): raise ValueError( diff --git a/tests/covalent_tests/shared_files/utils_test.py b/tests/covalent_tests/shared_files/utils_test.py index e5833b413..d688b0229 100644 --- a/tests/covalent_tests/shared_files/utils_test.py +++ b/tests/covalent_tests/shared_files/utils_test.py @@ -20,7 +20,7 @@ import pytest from covalent._shared_files.config import get_config -from covalent._shared_files.utils import filter_null_metadata, format_server_url +from covalent._shared_files.utils import filter_null_metadata, format_server_url, get_named_params @pytest.mark.parametrize( @@ -37,6 +37,18 @@ def test_filter_null_metadata(meta_dict, expected): assert filtered == expected +def test_get_named_params(): + """Tests the changes I made in covalent/covalent/_shared_files/utils.py for fixing ValueError in when using KEYWORD_ONLU parameter in electron func""" + + def test_func(a, *, b): + return a + b + + named_args, named_kwargs = get_named_params(test_func, [1], {"b": 2}) + + assert named_args == {"a": 1} + assert named_kwargs == {"b": 2} + + def test_format_server_url(): """Test the convenience function to format server urls."""