Get all callbacks/handlers of a widget

I was wondering if there is a possibilty to get all the callbacks related to a defined widget for test purposes.

Imagine the following:

input= widgets.Password(
    value="",
    placeholder="",
    description='Password:',
    disabled=False
)

def on_change(change):
    # do something here

input.observe(on_change, names='value')

I want to know how i can get a list/set/dictionary/… which tells me all the callback functions related to the widget input.

In this case for example [on_change] or something like that.

I already tried out various things, I guess the closes was:
print(password_input._display_callbacks.callbacks)
Nevertheless, this give me an empty list.

Note: I might have found a corresponding was:

input= widgets.Password(
    value="",
    placeholder="",
    description='Password:',
    disabled=False
)

def on_change(change):
    # do something here

input.observe(on_change, names='value')

print(input._trait_notifiers)

This prints out something like {'comm': {'change': [<traitlets.traitlets.ObserveHandler object at XXXXXXXXXXXXX>]}, 'value': {'change': [<function on_change at XXXXXXXXXXXXX>]}}

1 Like