UniCoreFW

enhanced_partial_right()

Enhanced partial_right application with _argcount tracking.

Implementation

Args: func: The function to partially apply from right *bound_args: Arguments to bind to the right **bound_kwargs: Keyword arguments to bind Returns: A partially applied function with _argcount metadata

Example

def divide(a, b, c): return a / b / c divide_by_two = enhanced_partial_right(divide, 2) divide_by_two(8, 2) # 8 / 2 / 2

Expected output: 2.0

Source Code

def enhanced_partial_right(func: Callable, *bound_args, **bound_kwargs) -> Callable: _validate_callable(func) def wrapper(*args, **kwargs): return func(*args, *bound_args, **{**kwargs, **bound_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)