From d1dc3a98c612d24f951dcc004283517d8f92e322 Mon Sep 17 00:00:00 2001 From: SeaStar Deng <37767638+DSeaStar@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:53:39 +0000 Subject: [PATCH 1/2] Warn on unrecognized Configurable kwargs with UserWarning HasTraits already warned when leftover kwargs reached object.__init__, but it used DeprecationWarning at stacklevel=2. That points at Configurable.__init__, so IPython hid the message. UserWarning is visible by default, which matches the discussion on #926. --- tests/test_traitlets.py | 17 +++++++++++++++++ traitlets/traitlets.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_traitlets.py b/tests/test_traitlets.py index 2e7b8459..fabcd30d 100644 --- a/tests/test_traitlets.py +++ b/tests/test_traitlets.py @@ -2829,6 +2829,23 @@ class SuperHasTraits(HasTraits): assert not hasattr(obj, "b") +def test_configurable_unrecognized_args_user_warning(): + """Configurable should surface unknown kwargs as UserWarning (#926).""" + import warnings + + from traitlets.config.configurable import Configurable + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + Configurable(not_a_trait=1) + user = [w for w in caught if issubclass(w.category, UserWarning)] + assert user + assert "Passing unrecognized arguments" in str(user[0].message) + assert not any(issubclass(w.category, DeprecationWarning) and + "Passing unrecognized arguments" in str(w.message) + for w in caught) + + def test_default_mro(): """Verify that default values follow mro""" diff --git a/traitlets/traitlets.py b/traitlets/traitlets.py index 0989ea98..146f2e74 100644 --- a/traitlets/traitlets.py +++ b/traitlets/traitlets.py @@ -1399,7 +1399,7 @@ def ignore(change: Bunch) -> None: f"{e}\n" "This is deprecated in traitlets 4.2." "This error will be raised in a future release of traitlets.", - DeprecationWarning, + UserWarning, stacklevel=2, ) From 3d606be2a43f4f14c2405c88956fc786bd1c8cc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:54:07 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- tests/test_traitlets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_traitlets.py b/tests/test_traitlets.py index fabcd30d..6cfa3051 100644 --- a/tests/test_traitlets.py +++ b/tests/test_traitlets.py @@ -2841,9 +2841,11 @@ def test_configurable_unrecognized_args_user_warning(): user = [w for w in caught if issubclass(w.category, UserWarning)] assert user assert "Passing unrecognized arguments" in str(user[0].message) - assert not any(issubclass(w.category, DeprecationWarning) and - "Passing unrecognized arguments" in str(w.message) - for w in caught) + assert not any( + issubclass(w.category, DeprecationWarning) + and "Passing unrecognized arguments" in str(w.message) + for w in caught + ) def test_default_mro():