You are viewing an older version (5.14.3). Go to latest (5.15.0)
{ } Raw JSON

bundles / traitlets 5.14.3 / traitlets / traitlets / HasTraits / observe

function

traitlets.traitlets:HasTraits.observe

source: /traitlets/traitlets.py :1641

Signature

def   observe ( self handler : t.Callable[..., t.Any] names : Sentinel | str | t.Iterable[Sentinel | str] = traitlets.All type : Sentinel | str = change )  →  None

Summary

Setup a handler to be called when a trait changes.

Extended Summary

This is used to setup dynamic notifications of trait changes.

Parameters

handler : callable

A callable that is called when a trait changes. Its signature should be handler(change), where change is a dictionary. The change dictionary at least holds a 'type' key. * type: the type of notification. Other keys may be passed depending on the value of 'type'. In the case where type is 'change', we also have the following keys: * owner : the HasTraits instance * old : the old value of the modified trait attribute * new : the new value of the modified trait attribute * name : the name of the modified trait attribute.

names : list, str, All

If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

type : str, All (default: 'change')

The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.

Aliases

  • traitlets.HasTraits.observe