🔍 Code Extractor

function resolve_dependent_kwargs

Maturity: 46

Resolves parameter dependencies in a dictionary by evaluating dependent parameter values, Parameterized instance methods, and parameterized functions.

File:
/tf/active/vicechatdev/patches/util.py
Lines:
1603 - 1617
Complexity:
simple

Purpose

This function is designed to work with the Param library's dependency system. It takes a dictionary of keyword arguments and resolves any values that have parameter dependencies, returning a new dictionary with all dependencies evaluated. This is useful when working with Parameterized objects where parameter values may depend on other parameters or need to be computed dynamically.

Source Code

def resolve_dependent_kwargs(kwargs):
    """Resolves parameter dependencies in the supplied dictionary

    Resolves parameter values, Parameterized instance methods and
    parameterized functions with dependencies in the supplied
    dictionary.

    Args:
       kwargs (dict): A dictionary of keyword arguments

    Returns:
       A new dictionary where any parameter dependencies have been
       resolved.
    """
    return {k: resolve_dependent_value(v) for k, v in kwargs.items()}

Parameters

Name Type Default Kind
kwargs - - positional_or_keyword

Parameter Details

kwargs: A dictionary of keyword arguments where values may include parameter dependencies, Parameterized instance methods, or parameterized functions that need to be resolved. The keys are strings representing parameter names, and values can be any type including dependent parameter references.

Return Value

Returns a new dictionary with the same keys as the input kwargs dictionary, but with all parameter dependencies resolved to their actual values. The structure mirrors the input dictionary, but dependent values are replaced with their evaluated results.

Dependencies

  • param

Required Imports

import param

Usage Example

import param
from holoviews.util import resolve_dependent_kwargs, resolve_dependent_value

class MyParams(param.Parameterized):
    x = param.Number(default=5)
    y = param.Number(default=10)
    
    @param.depends('x')
    def compute_z(self):
        return self.x * 2

obj = MyParams()
kwargs = {
    'value1': 42,
    'value2': obj.compute_z,
    'value3': obj.param.x
}

resolved = resolve_dependent_kwargs(kwargs)
print(resolved)
# Output: {'value1': 42, 'value2': 10, 'value3': 5}

Best Practices

  • This function creates a new dictionary rather than modifying the input, ensuring immutability
  • Ensure that resolve_dependent_value function is available in scope before calling this function
  • Use this function when you need to evaluate all parameter dependencies in a dictionary at once
  • The function is particularly useful in visualization and data processing pipelines where parameter values may be dynamically computed
  • Be aware that this function will evaluate all dependencies immediately, which may trigger computations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function resolve_dependent_value 73.8% similar

    Recursively resolves parameter dependencies in a value by evaluating parameterized methods, functions, and widgets, including those nested in collections (lists, tuples, dicts, slices).

    From: /tf/active/vicechatdev/patches/util.py
  • function rename_stream_kwargs 48.7% similar

    Maps parameter names in a kwargs dictionary to their renamed equivalents for a given stream object, with optional reverse mapping from renamed back to original names.

    From: /tf/active/vicechatdev/patches/util.py
  • function merge_option_dicts 42.9% similar

    Performs a deep merge of two nested dictionaries where the top-level values are themselves dictionaries, preserving values from both dictionaries at the nested level.

    From: /tf/active/vicechatdev/patches/util.py
  • function validate_dynamic_argspec 41.4% similar

    Validates that a callback function has an appropriate signature to work with DynamicMap by checking its arguments against key dimensions (kdims) and stream parameters.

    From: /tf/active/vicechatdev/patches/util.py
  • function is_param_method 41.1% similar

    Checks whether an object is a method on a Parameterized object, with optional verification of parameter dependencies.

    From: /tf/active/vicechatdev/patches/util.py
← Back to Browse