Skip to main content

This decorator dynamically maps argument names from a function's call to a specified function.

Project description

Argument Names

A Python library that provides a decorator to automatically retrieve and process the argument names of a function when it's called. This can be useful for tasks like debugging, logging, or other custom operations.

Installation

Install argument-names via pip:

pip install argument-names

Use Case Example

This example demonstrates how to utilize the argument_names decorator to log the names of the arguments passed to a function:

from argument_names import argument_names

@argument_names(function=lambda *args: print("Received arguments:", *args))
def process_data(_1, _2, _3):
    pass

# Example invocation
name = "Alice"
age = 30
occupation = "Engineer"

# Calling the process_data function with the specified arguments
process_data(name, age, occupation)   # Received arguments: name age occupation

process_data(occupation, age, age)   # Received arguments: occupation age age
from argument_names import argument_names

@argument_names(function=lambda *args: print("".join(args)))
def foo(*args):
    pass

h = None
e = 1
l = 9
o = 3
w = True
r = 3.14
d = 600
_ = 0.03

foo(h, e, l, l, o, _, w, o, r, l, d) # hello_world

Limitations

  • The library requires you to provide named variables as arguments when calling the decorated function. Direct values, literals, or function calls will not work as expected.

    For example, calling process_data("Alice", 30, "Engineer") would not work properly because the arguments are passed as values, not named variables. You must use named arguments like in the example process_data(name, age, occupation).

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

argument_names-0.1.0a2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

argument_names-0.1.0a2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file argument_names-0.1.0a2.tar.gz.

File metadata

  • Download URL: argument_names-0.1.0a2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.19.1 CPython/3.10.14 Windows/10

File hashes

Hashes for argument_names-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 156e97034bc1e917b0754533d8a1601ea8568e968fae0c30eb549ffba2a70654
MD5 97a152f8a761d3d725b52e663ca42f14
BLAKE2b-256 8cc555ba045c9e0a656f19f370ad62d35fcd04539245ca434c2dc9c3c91d4b33

See more details on using hashes here.

File details

Details for the file argument_names-0.1.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for argument_names-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 853217a989d38a32c49048d09d86df90313d1ce0abaf31832da2fb80cff44b70
MD5 a52201faddf0c7c2c004cc5e81ed7a08
BLAKE2b-256 3a049dc9087810907490245f51236b30a0f998039a7ebbb4bd5b4e88115cc7cc

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