Skip to main content

An improvement to Python's kwargs

Project description

Chocolate

Chocolate is a Python package that improves Python's **kwargs.

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for chocolate, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size chocolate-0.0.2-py3-none-any.whl (2.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size chocolate-0.0.2.tar.gz (1.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page