@@ -242,14 +242,19 @@ def subset_hook_caller(self, name, remove_plugins):
242
242
""" Return a new HookCaller instance for the named method
243
243
which manages calls to all registered plugins except the
244
244
ones from remove_plugins. """
245
- hc = getattr (self .hook , name )
245
+ orig = getattr (self .hook , name )
246
246
plugins_to_remove = [plugin for plugin in remove_plugins
247
247
if hasattr (plugin , name )]
248
248
if plugins_to_remove :
249
- hc = hc .clone ()
250
- for plugin in plugins_to_remove :
251
- hc ._remove_plugin (plugin )
252
- return hc
249
+ hc = HookCaller (orig .name , orig ._hookexec , orig ._specmodule_or_class )
250
+ for plugin in orig ._plugins :
251
+ if plugin not in plugins_to_remove :
252
+ hc ._add_plugin (plugin )
253
+ # we also keep track of this hook caller so it
254
+ # gets properly removed on plugin unregistration
255
+ self ._plugin2hookcallers .setdefault (plugin , []).append (hc )
256
+ return hc
257
+ return orig
253
258
254
259
def get_canonical_name (self , plugin ):
255
260
""" Return canonical name for a plugin object. """
@@ -488,7 +493,6 @@ def __init__(self, name, hook_execute, specmodule_or_class=None):
488
493
self ._wrappers = []
489
494
self ._nonwrappers = []
490
495
self ._hookexec = hook_execute
491
- self ._subcaller = []
492
496
if specmodule_or_class is not None :
493
497
self .set_specification (specmodule_or_class )
494
498
@@ -506,21 +510,6 @@ def set_specification(self, specmodule_or_class):
506
510
if hasattr (specfunc , "historic" ):
507
511
self ._call_history = []
508
512
509
- def clone (self ):
510
- assert not self .is_historic ()
511
- hc = object .__new__ (HookCaller )
512
- hc .name = self .name
513
- hc ._plugins = list (self ._plugins )
514
- hc ._wrappers = list (self ._wrappers )
515
- hc ._nonwrappers = list (self ._nonwrappers )
516
- hc ._hookexec = self ._hookexec
517
- hc .argnames = self .argnames
518
- hc .firstresult = self .firstresult
519
- # we keep track of this hook caller so it
520
- # gets properly pruned on plugin unregistration
521
- self ._subcaller .append (hc )
522
- return hc
523
-
524
513
def is_historic (self ):
525
514
return hasattr (self , "_call_history" )
526
515
@@ -531,10 +520,6 @@ def _remove_plugin(self, plugin):
531
520
self ._nonwrappers .remove (meth )
532
521
except ValueError :
533
522
self ._wrappers .remove (meth )
534
- if hasattr (self , "_subcaller" ):
535
- for hc in self ._subcaller :
536
- if plugin in hc ._plugins :
537
- hc ._remove_plugin (plugin )
538
523
539
524
def _add_plugin (self , plugin ):
540
525
self ._plugins .append (plugin )
@@ -553,6 +538,7 @@ def _add_method(self, meth):
553
538
i = len (nonwrappers ) - 1
554
539
while i >= 0 and hasattr (nonwrappers [i ], "tryfirst" ):
555
540
i -= 1
541
+
556
542
# and insert right in front of the tryfirst ones
557
543
nonwrappers .insert (i + 1 , meth )
558
544
0 commit comments