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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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