119
119
from functools import _find_impl # type: ignore # noqa: WPS450
120
120
from typing import ( # noqa: WPS235
121
121
TYPE_CHECKING ,
122
+ Any ,
122
123
Callable ,
123
124
Dict ,
124
125
Generic ,
125
126
Optional ,
127
+ Protocol ,
126
128
Type ,
127
129
TypeVar ,
128
130
Union ,
@@ -298,6 +300,10 @@ class Supports(Generic[_AssociatedTypeDef]):
298
300
__slots__ = ()
299
301
300
302
303
+ class Callback (Protocol ):
304
+ def __call__ (self , instance , * args , ** kwargs ) -> _ReturnType : ...
305
+
306
+
301
307
@final # noqa: WPS214
302
308
class _TypeClass ( # noqa: WPS214
303
309
Generic [_InstanceType , _SignatureType , _AssociatedType , _Fullname ],
@@ -323,7 +329,7 @@ class _TypeClass( # noqa: WPS214
323
329
'_dispatch_cache' ,
324
330
)
325
331
326
- _dispatch_cache : Dict [type , Callable ]
332
+ _dispatch_cache : Dict [type , Callback ]
327
333
_cache_token : Optional [object ]
328
334
329
335
def __init__ (
@@ -601,7 +607,7 @@ def _dispatch(self, instance, instance_type: type) -> Optional[Callable]:
601
607
602
608
return _find_impl (instance_type , self ._exact_types )
603
609
604
- def _dispatch_delegate (self , instance ) -> Optional [Callable ]:
610
+ def _dispatch_delegate (self , instance ) -> Optional [Callback ]:
605
611
for delegate , callback in self ._delegates .items ():
606
612
if isinstance (instance , delegate ):
607
613
return callback
0 commit comments