Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seungjaeryanlee/chocolate
Python's kwargs, improved.
https://github.com/seungjaeryanlee/chocolate
python
Last synced: 2 days ago
JSON representation
Python's kwargs, improved.
- Host: GitHub
- URL: https://github.com/seungjaeryanlee/chocolate
- Owner: seungjaeryanlee
- License: mit
- Created: 2020-05-23T05:23:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-31T07:31:34.000Z (almost 3 years ago)
- Last Synced: 2025-01-16T15:45:57.592Z (11 days ago)
- Topics: python
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chocolate
**Chocolate** is a Python package that improves Python's `**kwargs`.
```python
from chocolate import filter_args# Here is some function.
def example_function(arg1, arg2: int, arg3=3, arg4: str = ""):
print(f"{arg1} {arg2} {arg3} {arg4}")# We can give this function a dictionary of arguments using **kwargs.
kwargs = {"arg1": 1, "arg2": 2, "arg4": "4"}
example_function(**kwargs)# But what if the **kwargs dictionary has additional keys?
broken_kwargs = {"arg1": "This", "arg2": "does", "undefined_arg": "not", "arg3": "work"}
try:
example_function(**broken_kwargs)
except Exception as exception:
print(exception)# Chocolate can take care of that!
example_function(**filter_args(broken_kwargs, example_function))
```