From ed77d642e27b376881962b1f2a79ccce92dd6e76 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 17:08:56 +0300 Subject: [PATCH] Fix subset_hook_caller failing to exclude plugins using specname The subset_hook_caller uses `hasattr(plug, name)` to check if a plugin participates in a hook. When a plugin uses specname to map a differently-named method to a hook, hasattr returns False and the plugin is incorrectly kept in the subset. Instead of checking for an attribute by name, check whether the plugin is actually registered in the hook caller's hookimpls list. This correctly handles both regular implementations and those using specname. --- src/pluggy/_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 1b994f25..2de3327c 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -516,7 +516,10 @@ def subset_hook_caller( method which manages calls to all registered plugins except the ones from remove_plugins.""" orig: HookCaller = getattr(self.hook, name) - plugins_to_remove = {plug for plug in remove_plugins if hasattr(plug, name)} + registered_plugins = {impl.plugin for impl in orig._hookimpls} + plugins_to_remove = { + plug for plug in remove_plugins if plug in registered_plugins + } if plugins_to_remove: return _SubsetHookCaller(orig, plugins_to_remove) return orig