@@ -202,28 +202,22 @@ def __init__(self, name, hook_execute, specmodule_or_class=None, spec_opts=None)
202202 self ._wrappers = []
203203 self ._nonwrappers = []
204204 self ._hookexec = hook_execute
205- self ._specmodule_or_class = None
206205 self .argnames = None
207206 self .kwargnames = None
208207 self .multicall = _multicall
209- self .spec_opts = spec_opts or {}
208+ self .spec = None
210209 if specmodule_or_class is not None :
210+ assert spec_opts is not None
211211 self .set_specification (specmodule_or_class , spec_opts )
212212
213213 def has_spec (self ):
214- return self ._specmodule_or_class is not None
214+ return self .spec is not None
215215
216216 def set_specification (self , specmodule_or_class , spec_opts ):
217217 assert not self .has_spec ()
218- self ._specmodule_or_class = specmodule_or_class
219- specfunc = getattr (specmodule_or_class , self .name )
220- # get spec arg signature
221- argnames , self .kwargnames = varnames (specfunc )
222- self .argnames = ["__multicall__" ] + list (argnames )
223- self .spec_opts .update (spec_opts )
218+ self .spec = HookSpec (specmodule_or_class , self .name , spec_opts )
224219 if spec_opts .get ("historic" ):
225220 self ._call_history = []
226- self .warn_on_impl = spec_opts .get ("warn_on_impl" )
227221
228222 def is_historic (self ):
229223 return hasattr (self , "_call_history" )
@@ -273,8 +267,10 @@ def __call__(self, *args, **kwargs):
273267 if args :
274268 raise TypeError ("hook calling supports only keyword arguments" )
275269 assert not self .is_historic ()
276- if self .argnames :
277- notincall = set (self .argnames ) - set (["__multicall__" ]) - set (kwargs .keys ())
270+ if self .spec and self .spec .argnames :
271+ notincall = (
272+ set (self .spec .argnames ) - set (["__multicall__" ]) - set (kwargs .keys ())
273+ )
278274 if notincall :
279275 warnings .warn (
280276 "Argument(s) {} which are declared in the hookspec "
@@ -344,3 +340,14 @@ def __init__(self, plugin, plugin_name, function, hook_impl_opts):
344340
345341 def __repr__ (self ):
346342 return "<HookImpl plugin_name=%r, plugin=%r>" % (self .plugin_name , self .plugin )
343+
344+
345+ class HookSpec (object ):
346+ def __init__ (self , namespace , name , opts ):
347+ self .namespace = namespace
348+ self .function = function = getattr (namespace , name )
349+ self .name = name
350+ self .argnames , self .kwargnames = varnames (function )
351+ self .opts = opts
352+ self .argnames = ["__multicall__" ] + list (self .argnames )
353+ self .warn_on_impl = opts .get ("warn_on_impl" )
0 commit comments