From ccdd5edc75d93dd062f5bf126b3fa8214a6594cc Mon Sep 17 00:00:00 2001 From: ytwei Date: Mon, 24 Aug 2026 20:54:50 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20clarify=20All=20observer=20registration?= =?UTF-8?q?s=20=F0=9F=A4=96=F0=9F=8D=86=20(#485)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/using_traitlets.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/using_traitlets.rst b/docs/source/using_traitlets.rst index 0c5de2f9f..4b94a1847 100644 --- a/docs/source/using_traitlets.rst +++ b/docs/source/using_traitlets.rst @@ -82,6 +82,27 @@ When observers are methods of the class, a decorator syntax can be used. print(change["old"]) print(change["new"]) +The special value ``All`` can be used to register a handler for every trait. +When unregistering a handler, pass the same ``names`` and ``type`` values that +were used when registering it. ``All`` refers to the registration for all +traits; it does not match a handler that was registered for one particular +trait. + +.. code:: python + + from traitlets import All + + + def handle_any_change(change): + print(change["name"]) + + + foo.observe(handle_any_change, names=All) + foo.unobserve(handle_any_change, names=All) + + foo.observe(handle_any_change, names="bar") + foo.unobserve(handle_any_change, names="bar") + Validation and Coercion -----------------------