33from collections .abc import Awaitable , Callable , Iterator
44from dataclasses import dataclass , field
55from functools import partial
6- from inspect import Parameter , getmro , isclass
6+ from inspect import Parameter , isclass
77from inspect import signature as inspect_signature
88from typing import TYPE_CHECKING , Any , Protocol , Self , overload , runtime_checkable
99
1010import injection
11+ from type_analyzer import MatchingTypesConfig , matching_types
1112
1213type HandlerType [** P , T ] = type [Handler [P , T ]]
1314type HandlerFactory [** P , T ] = Callable [..., Awaitable [Handler [P , T ]]]
@@ -49,7 +50,7 @@ def handlers_from(
4950 self ,
5051 input_type : type [I ],
5152 ) -> Iterator [Callable [[I ], Awaitable [O ]]]:
52- for it in getmro (input_type ):
53+ for it in _standardize_input_type (input_type ):
5354 for factory in self .__factories .get (it , ()):
5455 yield _make_handle_function (factory )
5556
@@ -69,7 +70,7 @@ def handlers_from(
6970 self ,
7071 input_type : type [I ],
7172 ) -> Iterator [Callable [[I ], Awaitable [O ]]]:
72- for it in getmro (input_type ):
73+ for it in _standardize_input_type (input_type ):
7374 factory = self .__factories .get (it , None )
7475 if factory is not None :
7576 yield _make_handle_function (factory )
@@ -170,6 +171,15 @@ def _resolve_input_type[I, O](handler_type: HandlerType[[I], O]) -> type[I]:
170171 )
171172
172173
174+ def _standardize_input_type (input_type : Any ) -> tuple [Any , ...]:
175+ config = MatchingTypesConfig (
176+ with_bases = True ,
177+ with_origin = True ,
178+ with_type_alias_value = True ,
179+ )
180+ return matching_types (input_type , config )
181+
182+
173183def _make_handle_function [I , O ](
174184 factory : HandlerFactory [[I ], O ],
175185) -> Callable [[I ], Awaitable [O ]]:
0 commit comments