From 8fddd8d3c7ee4bb4b725eeba258922583b41c9e6 Mon Sep 17 00:00:00 2001 From: ytwei Date: Mon, 24 Aug 2026 20:52:58 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20document=20trait=20declaration=20deprec?= =?UTF-8?q?ation=20=F0=9F=A4=96=F0=9F=8D=86=20(#520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/migration.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/migration.rst b/docs/source/migration.rst index 31a67b293..3b7b905b0 100644 --- a/docs/source/migration.rst +++ b/docs/source/migration.rst @@ -26,6 +26,27 @@ populate the metadata for a trait type instance is to use the new We also deprecated the ``get_metadata`` method. The metadata of a trait type instance can directly be accessed via the ``metadata`` attribute. +Deprecation of trait declarations via classes +---------------------------------------------- + +Traits should be declared with instances of their trait types. Declaring a +trait with the trait type itself is deprecated: + +.. code:: python + + from traitlets import HasTraits, Int + + + class OldStyle(HasTraits): + value = Int # deprecated + + + class NewStyle(HasTraits): + value = Int() # preferred + +This applies to container traits as well. For example, use ``List(Int())`` +instead of ``List(Int)``. + Deprecation of ``on_trait_change`` ----------------------------------