From ce648613633a455ebe3a379ff27f73c266a70b17 Mon Sep 17 00:00:00 2001 From: draarivpatel-ui <287273626+draarivpatel-ui@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:27:34 -0600 Subject: [PATCH] Keep subset exclusions for late plugin registration --- src/pluggy/_manager.py | 7 ------- testing/test_pluginmanager.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 15214676..3fadf62b 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -650,13 +650,6 @@ def subset_hook_caller( calls all registered plugins except the ones from remove_plugins.""" orig: HookCaller = getattr(self.hook, name) plugins_to_remove = set(remove_plugins) - # Optimization: discard plugins to remove which don't actually implement - # the hook, to make checks faster. - plugins_to_remove.intersection_update( - hookimpl.plugin for hookimpl in orig._hookimpls - ) - # Optimization: if none of the plugins to remove actually implement the - # hook, avoid the subset hook caller overhead. if not plugins_to_remove: return orig return _SubsetHookCaller(orig, plugins_to_remove) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index be34efb1..c6283079 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -775,6 +775,27 @@ class PluginNo: assert repr(hc) == "<_SubsetHookCaller 'he_method1'>" +def test_subset_hook_caller_excludes_late_registered_plugin(pm: PluginManager) -> None: + class Hooks: + @hookspec + def he_method1(self): + pass + + pm.add_hookspecs(Hooks) + + class Plugin1: + @hookimpl + def he_method1(self): + return 1 + + plugin1 = Plugin1() + hc = pm.subset_hook_caller("he_method1", [plugin1]) + pm.register(plugin1) + + assert hc() == [] + assert repr(hc) == "<_SubsetHookCaller 'he_method1'>" + + def test_subset_hook_caller_with_specname(pm: PluginManager) -> None: """Test that subset_hook_caller doesn't get confused by specname."""