4343 runtime_checkable ,
4444)
4545
46- from type_analyzer import MatchingTypesConfig , matching_types
46+ from type_analyzer import MatchingTypesConfig , iter_matching_types
4747
4848from injection ._core .common .asynchronous import (
4949 AsyncCaller ,
@@ -262,9 +262,9 @@ class Locator(Broker):
262262 )
263263
264264 def __getitem__ [T ](self , cls : InputType [T ], / ) -> Injectable [T ]:
265- for input_class in self .__standardize_inputs ((cls ,)):
265+ for key_type in self .__iter_key_types ((cls ,)):
266266 try :
267- record = self .__records [input_class ]
267+ record = self .__records [key_type ]
268268 except KeyError :
269269 continue
270270
@@ -274,8 +274,7 @@ def __getitem__[T](self, cls: InputType[T], /) -> Injectable[T]:
274274
275275 def __contains__ (self , cls : InputType [Any ], / ) -> bool :
276276 return any (
277- input_class in self .__records
278- for input_class in self .__standardize_inputs ((cls ,))
277+ key_type in self .__records for key_type in self .__iter_key_types ((cls ,))
279278 )
280279
281280 @property
@@ -288,8 +287,8 @@ def __injectables(self) -> frozenset[Injectable[Any]]:
288287
289288 def update [T ](self , updater : Updater [T ]) -> Self :
290289 record = updater .make_record ()
291- classes = self .__reduce_classes (updater )
292- records = dict (self .__prepare_for_updating (classes , record ))
290+ key_types = self .__build_key_types (updater . classes )
291+ records = dict (self .__prepare_for_updating (key_types , record ))
293292
294293 if records :
295294 event = LocatorDependenciesUpdated (self , records .keys (), record .mode )
@@ -334,6 +333,21 @@ def __prepare_for_updating[T](
334333
335334 yield cls , record
336335
336+ @staticmethod
337+ def __build_key_types [T ](classes : Iterable [InputType [T ]]) -> frozenset [TypeDef [T ]]:
338+ config = MatchingTypesConfig (ignore_none = True )
339+ return frozenset (
340+ itertools .chain .from_iterable (
341+ iter_matching_types (cls , config ) for cls in classes
342+ )
343+ )
344+
345+ @staticmethod
346+ def __iter_key_types [T ](classes : Iterable [InputType [T ]]) -> Iterator [InputType [T ]]:
347+ config = MatchingTypesConfig (with_origin = True , with_type_alias_value = True )
348+ for cls in classes :
349+ yield from iter_matching_types (cls , config )
350+
337351 @staticmethod
338352 def __keep_new_record [T ](
339353 new : Record [T ],
@@ -350,28 +364,6 @@ def __keep_new_record[T](
350364
351365 return new_mode .rank > existing_mode .rank
352366
353- @staticmethod
354- def __reduce_classes [T ](updater : Updater [T ]) -> frozenset [TypeDef [T ]]:
355- config = MatchingTypesConfig (ignore_none = True )
356- return frozenset (
357- itertools .chain .from_iterable (
358- matching_types (cls , config ) for cls in updater .classes
359- )
360- )
361-
362- @staticmethod
363- def __standardize_inputs [T ](
364- classes : Iterable [InputType [T ]],
365- ) -> Iterator [InputType [T ]]:
366- config = MatchingTypesConfig (
367- with_bases = True ,
368- with_origin = True ,
369- with_type_alias_value = True ,
370- )
371-
372- for cls in classes :
373- yield from matching_types (cls , config )
374-
375367
376368"""
377369Module
0 commit comments