From 16bed4ad1058ee1d01a5d072f274f9d50e4c5614 Mon Sep 17 00:00:00 2001 From: fei <204683769+feiiiiii5@users.noreply.github.com> Date: Fri, 25 Sep 2026 22:41:23 +0800 Subject: [PATCH 1/3] Warn for defaulted deprecated hookimpl args --- src/pluggy/_manager.py | 2 +- testing/test_details.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 8a0959f7..1d7984a9 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -440,7 +440,7 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None: ) if hook.spec.warn_on_impl_args: - for hookimpl_argname in hookimpl.argnames: + for hookimpl_argname in hookimpl.argnames + hookimpl.kwargnames: argname_warning = hook.spec.warn_on_impl_args.get(hookimpl_argname) if argname_warning is not None: _warn_for_function(argname_warning, hookimpl.function) diff --git a/testing/test_details.py b/testing/test_details.py index 8df167f4..3a9858f8 100644 --- a/testing/test_details.py +++ b/testing/test_details.py @@ -128,6 +128,30 @@ def foo(self, old2, old1, new): assert record2.lineno == Plugin.foo.__code__.co_firstlineno +def test_warn_when_deprecated_args_with_defaults_specified() -> None: + warning = DeprecationWarning("old is deprecated") + + class Spec: + @hookspec(warn_on_impl_args={"old": warning}) + def foo(self, old=None, new=None): + raise NotImplementedError() + + class Plugin: + @hookimpl + def foo(self, old=None, new=None): + raise NotImplementedError() + + pm = PluginManager(hookspec.project_name) + pm.add_hookspecs(Spec) + + with pytest.warns(DeprecationWarning) as records: + pm.register(Plugin()) + (record,) = records + assert record.message is warning + assert record.filename == Plugin.foo.__code__.co_filename + assert record.lineno == Plugin.foo.__code__.co_firstlineno + + def test_plugin_getattr_raises_errors() -> None: """Pluggy must be able to handle plugins which raise weird exceptions when getattr() gets called (#11). From d80c8541c4a59a25648c60b70495e6397472b1c4 Mon Sep 17 00:00:00 2001 From: fei <204683769+feiiiiii5@users.noreply.github.com> Date: Fri, 25 Sep 2026 22:43:00 +0800 Subject: [PATCH 2/3] Add changelog fragment for #743 --- changelog/743.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/743.bugfix.rst diff --git a/changelog/743.bugfix.rst b/changelog/743.bugfix.rst new file mode 100644 index 00000000..24f546f5 --- /dev/null +++ b/changelog/743.bugfix.rst @@ -0,0 +1 @@ +Fixed ``warn_on_impl_args`` to warn when a hook implementation requests a deprecated argument with a default. From 6531c90695ef04ef74fedf4b36d67b19a2998ffd Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 27 Sep 2026 12:08:16 +0300 Subject: [PATCH 3/3] Delete changelog/743.bugfix.rst --- changelog/743.bugfix.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog/743.bugfix.rst diff --git a/changelog/743.bugfix.rst b/changelog/743.bugfix.rst deleted file mode 100644 index 24f546f5..00000000 --- a/changelog/743.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed ``warn_on_impl_args`` to warn when a hook implementation requests a deprecated argument with a default.