param.ParamOverrides#

class param.ParamOverrides(overridden: Parameterized, dict_: dict[str, Any], allow_extra_keywords: bool = False)[source]#

A dictionary-like object that provides two-level lookup for parameter values.

ParamOverrides allows overriding the parameters of a ParameterizedFunction or other Parameterized object. When a parameter is accessed, it first checks for the value in the supplied dictionary. If the value is not present, it falls back to the parameter’s default value on the overridden object.

This mechanism is used to combine explicit parameter values provided at runtime with the default parameter values defined on a ParameterizedFunction or Parameterized object.

References

See https://param.holoviz.org/user_guide/ParameterizedFunctions.html

Examples

Use ParamOverrides to combine runtime arguments with default parameters:

>>> from param import Parameter, ParameterizedFunction, ParamOverrides
>>> class multiply(ParameterizedFunction):
...    left  = Parameter(2, doc="Left-hand-side argument")
...    right = Parameter(4, doc="Right-hand-side argument")
...
...    def __call__(self, **params):
...        p = ParamOverrides(self, params)
...        return p.left * p.right
>>> multiply()
8
>>> multiply(left=3, right=7)
21
__init__(overridden: Parameterized, dict_: dict[str, Any], allow_extra_keywords: bool = False)[source]#

Initialize a ParamOverrides object.

Parameters:
  • overridden (Parameterized) – The object whose parameters are being overridden.

  • dict (dict[str, Any]) – A dictionary containing parameter overrides. Keys must match parameter names on the overridden object unless allow_extra_keywords is True.

  • allow_extra_keywords (bool, optional) – If False, all keys in dict_ must correspond to parameter names on the overridden object. A warning is printed for any mismatched keys. If True, mismatched keys are stored in _extra_keywords and can be accessed using the extra_keywords() method. Default is False.

Methods

__init__(overridden, dict_[, ...])

Initialize a ParamOverrides object.

clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

extra_keywords()

Retrieve extra keyword arguments not matching the overridden object's parameters.

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Retrieve the value for a given key, with a default if the key is not found.

items()

Return a set-like object providing a view on the dict's items.

keys()

Return a set-like object providing a view on the dict's keys.

param_keywords()

Retrieve parameters matching the overridden object's declared parameters.

pop(k[,d])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict's values.