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.101 released on 22th/5/2024
should now be installable??
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file force_kwargs-0.101.tar.gz
.
File metadata
- Download URL: force_kwargs-0.101.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 708de5510e3ab5052dbdea1cb6ccb8038af12887ab064c3f1d08818a6a2c02d1 |
|
MD5 | 42c537e124a8946365d79736399ac48c |
|
BLAKE2b-256 | 5ed1c68240b56d97eebd3a2240f0262559464350d9c01e56a6ea872eeb060a3f |