Skip to content

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

License

Notifications You must be signed in to change notification settings

Cxx-mlr/argument-names

Repository files navigation

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

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages