11from __future__ import annotations
22
3+ import itertools
34from abc import ABC , abstractmethod
45from collections import OrderedDict , deque
56from collections .abc import (
4243 runtime_checkable ,
4344)
4445
46+ from type_analyzer import MatchingTypesConfig , iter_matching_types
47+
4548from injection ._core .common .asynchronous import (
4649 AsyncCaller ,
4750 Caller ,
5962 TypeInfo ,
6063 get_return_types ,
6164 get_yield_hint ,
62- standardize_types ,
6365)
6466from injection ._core .injectables import (
6567 AsyncCMScopedInjectable ,
@@ -229,7 +231,6 @@ class Updater[T]:
229231 classes : Iterable [InputType [T ]]
230232 injectable : Injectable [T ]
231233 mode : Mode
232- ignore_none_type : bool
233234
234235 def make_record (self ) -> Record [T ]:
235236 return Record (self .injectable , self .mode )
@@ -241,13 +242,11 @@ def with_basics(
241242 / ,
242243 injectable : Injectable [T ],
243244 mode : Mode | ModeStr ,
244- ignore_none_type : bool = False ,
245245 ) -> Self :
246246 return cls (
247247 classes = get_return_types (on ),
248248 injectable = injectable ,
249249 mode = Mode (mode ),
250- ignore_none_type = ignore_none_type ,
251250 )
252251
253252
@@ -263,9 +262,9 @@ class Locator(Broker):
263262 )
264263
265264 def __getitem__ [T ](self , cls : InputType [T ], / ) -> Injectable [T ]:
266- for input_class in self .__standardize_inputs ((cls ,)):
265+ for key_type in self .__iter_key_types ((cls ,)):
267266 try :
268- record = self .__records [input_class ]
267+ record = self .__records [key_type ]
269268 except KeyError :
270269 continue
271270
@@ -275,8 +274,7 @@ def __getitem__[T](self, cls: InputType[T], /) -> Injectable[T]:
275274
276275 def __contains__ (self , cls : InputType [Any ], / ) -> bool :
277276 return any (
278- input_class in self .__records
279- for input_class in self .__standardize_inputs ((cls ,))
277+ key_type in self .__records for key_type in self .__iter_key_types ((cls ,))
280278 )
281279
282280 @property
@@ -289,8 +287,8 @@ def __injectables(self) -> frozenset[Injectable[Any]]:
289287
290288 def update [T ](self , updater : Updater [T ]) -> Self :
291289 record = updater .make_record ()
292- classes = self .__reduce_classes (updater )
293- 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 ))
294292
295293 if records :
296294 event = LocatorDependenciesUpdated (self , records .keys (), record .mode )
@@ -335,6 +333,21 @@ def __prepare_for_updating[T](
335333
336334 yield cls , record
337335
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+
338351 @staticmethod
339352 def __keep_new_record [T ](
340353 new : Record [T ],
@@ -351,21 +364,6 @@ def __keep_new_record[T](
351364
352365 return new_mode .rank > existing_mode .rank
353366
354- @staticmethod
355- def __reduce_classes [T ](updater : Updater [T ]) -> frozenset [TypeDef [T ]]:
356- return frozenset (
357- standardize_types (
358- * updater .classes ,
359- ignore_none_type = updater .ignore_none_type ,
360- )
361- )
362-
363- @staticmethod
364- def __standardize_inputs [T ](
365- classes : Iterable [InputType [T ]],
366- ) -> Iterator [InputType [T ]]:
367- return standardize_types (* classes , with_origin = True )
368-
369367
370368"""
371369Module
@@ -564,10 +562,9 @@ def reserve_scoped_slot[T](
564562 scope_name : str ,
565563 * ,
566564 mode : Mode | ModeStr = Mode .get_default (),
567- ignore_none_type : bool = False ,
568565 ) -> SlotKey [T ]:
569566 injectable = ScopedSlotInjectable (cls , scope_name )
570- updater = Updater .with_basics (cls , injectable , mode , ignore_none_type )
567+ updater = Updater .with_basics (cls , injectable , mode )
571568 self .update (updater )
572569 return injectable .key
573570
0 commit comments