enhanced_partial()
Enhanced partial application with _argcount tracking.
Implementation
Args: func: The function to partially apply *bound_args: Arguments to bind **bound_kwargs: Keyword arguments to bind Returns: A partially applied function with _argcount metadata
Example
def multiply(a, b, c):
return a * b * c
times_two = enhanced_partial(multiply, 2)
times_two(3, 4)
Expected output: 24
Source Code
def enhanced_partial(func: Callable, *bound_args, **bound_kwargs) -> Callable:
_validate_callable(func)
def wrapper(*args, **kwargs):
return func(*(bound_args + args), **{**bound_kwargs, **kwargs})
# Calculate remaining argument count
original_arity = func.__code__.co_argcount
wrapper._argcount = max(0, original_arity - len(bound_args)) # type: ignore
return _copy_function_metadata(wrapper, func)