@@ -202,28 +202,22 @@ def __init__(self, name, hook_execute, specmodule_or_class=None, spec_opts=None)
202
202
self ._wrappers = []
203
203
self ._nonwrappers = []
204
204
self ._hookexec = hook_execute
205
- self ._specmodule_or_class = None
206
205
self .argnames = None
207
206
self .kwargnames = None
208
207
self .multicall = _multicall
209
- self .spec_opts = spec_opts or {}
208
+ self .spec = None
210
209
if specmodule_or_class is not None :
210
+ assert spec_opts is not None
211
211
self .set_specification (specmodule_or_class , spec_opts )
212
212
213
213
def has_spec (self ):
214
- return self ._specmodule_or_class is not None
214
+ return True if self .spec is not None else False
215
215
216
216
def set_specification (self , specmodule_or_class , spec_opts ):
217
217
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 )
224
219
if spec_opts .get ("historic" ):
225
220
self ._call_history = []
226
- self .warn_on_impl = spec_opts .get ("warn_on_impl" )
227
221
228
222
def is_historic (self ):
229
223
return hasattr (self , "_call_history" )
@@ -273,8 +267,10 @@ def __call__(self, *args, **kwargs):
273
267
if args :
274
268
raise TypeError ("hook calling supports only keyword arguments" )
275
269
assert not self .is_historic ()
276
- if self .argnames :
277
- notincall = set (self .argnames ) - set (["__multicall__" ]) - set (kwargs .keys ())
270
+ if self .spec :
271
+ notincall = (
272
+ set (self .spec .argnames ) - set (["__multicall__" ]) - set (kwargs .keys ())
273
+ )
278
274
if notincall :
279
275
warnings .warn (
280
276
"Argument(s) {} which are declared in the hookspec "
@@ -344,3 +340,14 @@ def __init__(self, plugin, plugin_name, function, hook_impl_opts):
344
340
345
341
def __repr__ (self ):
346
342
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