Skip to main content

A simple decorator to force kwargs. Doing so provides readability to the function signature.

Project description

force_kwargs

A simple Python decorator to enforce the use of keyword arguments in functions, limiting the number of positional arguments allowed.

Installation

pip install force_kwargs

Usage

Import the force_kwargs function and use it as a decorator on your functions to limit the number of positional arguments that can be passed.

You can specify the number of allowed positional arguments with the n_allowed_args parameter.

Example

from force_kwargs import force_kwargs

@force_kwargs(n_allowed_args=2)
def add(a, b, do_print):
	res = a + b
	if do_print:
		print(res)
	return res

add(1, 2, do_print=True)  # `3`.
add(1, 2, False)  # SyntaxError.

License

No License since this code is extremely basic.

Feel free to do what ever you want with this code.

:D

V0.1 released on 22th/5/2024

init

Project details


Download files

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

Source Distribution

force_kwargs-0.1.tar.gz (1.6 kB view details)

Uploaded Source

File details

Details for the file force_kwargs-0.1.tar.gz.

File metadata

  • Download URL: force_kwargs-0.1.tar.gz
  • Upload date:
  • Size: 1.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for force_kwargs-0.1.tar.gz
Algorithm Hash digest
SHA256 7efd74c2423e0ea7ecaba54d4fece4b01a30c7d49b5bd626ffbb66f725b3ebaa
MD5 389483a1f1cf3bbdebc6fd57b30b0f6a
BLAKE2b-256 371f6193352f3be2137094917b718bbe04e6cd9da2afb96e4c1c390f85f89542

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page