diff --git a/tests/test_traitlets.py b/tests/test_traitlets.py index 2e7b8459..6cfa3051 100644 --- a/tests/test_traitlets.py +++ b/tests/test_traitlets.py @@ -2829,6 +2829,25 @@ 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, )