1 class TypeidHook(object):
2 def __init__(self
, *typeids
):
4 if not isinstance(typeid
, type):
5 raise ValueError(typeid
)
6 self
.__typeids
= typeids
7 return super().__init
__()
10 yield from self
.__typeids
13 return f
"{self.__class__.__name__}({self.__typeids!r})"
15 def __call__(self
, call
):
16 if not callable(call
):
17 raise ValueError(call
)
18 return CallHook(typeids
=self
, call
=call
)
21 class CallHook(object):
22 def __init__(self
, typeids
, call
):
23 if not isinstance(typeids
, TypeidHook
):
24 raise ValueError(typeids
)
25 if not callable(call
):
26 raise ValueError(call
)
27 self
.__typeids
= typeids
29 return super().__init
__()
32 yield from self
.__typeids
35 return f
"{self.__class__.__name__}(call={self.__call!r}, typeids={self.__typeids!r})"
37 def __call__(self
, dispatcher
, instance
):
38 return self
.__call
(dispatcher
, instance
)
42 return TypeidHook(*typeids
)