Skip to main content

A decorator that modifies the arguments and keyword arguments of a function based on the calling instance's attributes.

Tested against Windows / Python 3.11 / Anaconda

pip install argskwargsmodifierclass

A decorator that modifies the arguments and keyword arguments of a function based on the calling instance's attributes.

Args:
	f_py (function, optional): Reserved for the function; do not use this argument explicitly.

	args_and_function (tuple of tuples): A tuple of tuples where each tuple contains an argument
	name and a function to transform the argument.
	The decorator will apply the specified function to each argument with a matching name.
	Each transformation function takes three arguments: the argument value,
	a dictionary of keyword arguments, and the instance that called the decorated method.

Returns:
	function: The decorated function.

Example:
	from argskwargsmodifierclass import change_args_kwargs
	class ADBTEST:
		def __init__(self, stripit=True):
			self.stripit = stripit

		@change_args_kwargs(
			args_and_function=(
					(
							"text",
							lambda arg, argdict, instance: arg.strip("x")
							if instance.stripit
							else arg,
					),
			)
		)
		def onefunction(self, text,number=10):
			print(f"{text=}")
			print(f"{number=}")


	t = ADBTEST(stripit=True)
	t.onefunction("bibib    xxxx",number=20)
	t.onefunction("bibibx    xxxx",15)

	t2 = ADBTEST(stripit=False)
	t2.onefunction(text="aaabibib",   number=0x5)
	t2.onefunction("aaaabibibx    xx")

	t.stripit = False
	t.onefunction("bibib    xxxx")
	t.onefunction("bibibx    xxxx")

	t2.stripit = True
	t2.onefunction("aaabibib   xxx")
	t2.onefunction("aaaabibibx    xx")

	# text='bibib    '
	# number=20
	# text='bibibx    '
	# number=15
	# text='aaabibib'
	# number=5
	# text='aaaabibibx    xx'
	# number=10
	# text='bibib    xxxx'
	# number=10
	# text='bibibx    xxxx'
	# number=10
	# text='aaabibib   '
	# number=10
	# text='aaaabibibx    '
	# number=10


The `change_args_kwargs` decorator allows you to modify function arguments and keyword arguments based on
the attributes of the calling instance.
It takes a tuple of argument transformations, each of which is defined as a tuple containing an argument name,
a transformation function, and the instance that called the decorated method.
The decorator dynamically adjusts the arguments according to the instance's attributes,
providing fine-grained control over argument modification.

Metadata

Release files for argskwargsmodifierclass 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for argskwargsmodifierclass 0.10
File Size Uploaded Provenance Actions
argskwargsmodifierclass-0.10.tar.gz 4.0 kB Without provenance Details for argskwargsmodifierclass-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for argskwargsmodifierclass 0.10
File Interpreter ABI Platform Actions
argskwargsmodifierclass-0.10-py3-none-any.whl Python 3 none any Details for argskwargsmodifierclass-0.10-py3-none-any.whl

Total release size: 9.9 kB

Release files / argskwargsmodifierclass-0.10.tar.gz

Download URL argskwargsmodifierclass-0.10.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6afb519cd14dbfb0fe961a81a559a787b864c4a35542974a725bced2c8b763fe
BLAKE2b-256 checksum
How to use checksums
02182f24c82d1aa9c6991218b94b2496ef639996deefa613ce4624bcfb1251c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / argskwargsmodifierclass-0.10-py3-none-any.whl

Download URL argskwargsmodifierclass-0.10-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbb506d1a64ed0c571ef5875ca9a7d375f7f55ee12c73f208188d4e073a409b4
BLAKE2b-256 checksum
How to use checksums
c6f6a572390b6cc4ca95a84f22e80a4b7d423bb71ed12b5f4739608d33117f26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for argskwargsmodifierclass 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page