Repository: AgnostiqHQ/covalent (python)

Issue:
Use KEYWORD_ONLY parameter in electron func will cause `ValueError`
### Environment

- **Covalent version**: 0.220.0
- **Python version**: 3.10.11
- **Operating system**: Ubuntu 22.04.1 LTS


### What is happening?

When KEYWORD_ONLY parameter in `func`, calling `ct.electron(func)` will give a `ValueError`.

### How can we reproduce the issue?

```python
@ct.lattice
@ct.electron
def test_func(a, *, b):
    return a + b

ct.dispatch(test_func)(a=1, b=2)
```

### What should happen?

This example will raise `ValueError: Unexpected keyword arguments: b`

### Any suggestions?

https://github.com/AgnostiqHQ/covalent/blob/acfc902e2296bdf6b9210789516e12b9fd1b94a2/covalent/_shared_files/utils.py#L218-L221

To change these codes as follows, maybe solve this problem.

```python
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]
```

Pull request:
fixes #1783
<!--
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Add a note to /CHANGELOG.md summarizing the changes.
⚠️ If your pull request fixes an open issue, please link to the issue.
⚠️ Ensure that your branch is up-to-date with the base branch.
-->

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation and CHANGELOG accordingly.
- [x] I have read the CONTRIBUTING document.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 756d14cf..ff32a7cc 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 14136f6e..48e26870 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(


Test patch:
diff --git a/tests/covalent_tests/shared_files/utils_test.py b/tests/covalent_tests/shared_files/utils_test.py
index e5833b41..d688b022 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."""