Cause an error when trying to hook invalid HookMixin method
This commit is contained in:
parent
0b931d1a05
commit
eafff2ae43
|
@ -25,9 +25,12 @@ class HookMixinMeta(type):
|
|||
def __new__(cls, name, bases, attrs):
|
||||
super_new = super(HookMixinMeta, cls).__new__
|
||||
|
||||
hookable = []
|
||||
for key, value in attrs.items():
|
||||
if callable(value):
|
||||
attrs[key] = hook_func(key, value)
|
||||
hookable.append(key)
|
||||
attrs['_hookable'] = hookable
|
||||
|
||||
return super_new(cls, name, bases, attrs)
|
||||
|
||||
|
@ -37,9 +40,12 @@ class HookMixin(object):
|
|||
|
||||
_pre_hooks = {}
|
||||
_post_hooks = {}
|
||||
_hookable = []
|
||||
|
||||
@classmethod
|
||||
def after(cls, method_name):
|
||||
assert method_name in cls._hookable, "'%s' not a hookable method of '%s'" % (method_name, cls.__name__)
|
||||
|
||||
def outer(f, *args, **kwargs):
|
||||
cls._post_hooks.setdefault(method_name, []).append((f, args, kwargs))
|
||||
return f
|
||||
|
@ -47,6 +53,8 @@ class HookMixin(object):
|
|||
|
||||
@classmethod
|
||||
def before(cls, method_name):
|
||||
assert method_name in cls._hookable, "'%s' not a hookable method of '%s'" % (method_name, cls.__name__)
|
||||
|
||||
def outer(f, *args, **kwargs):
|
||||
cls._pre_hooks.setdefault(method_name, []).append((f, args, kwargs))
|
||||
return f
|
||||
|
|
Loading…
Reference in a new issue