11from __future__ import annotations
22
3- import itertools
4- from abc import ABC
3+ from abc import ABC , abstractmethod
54from collections import OrderedDict , deque
65from collections .abc import (
76 AsyncGenerator ,
4544
4645from type_analyzer import MatchingTypesConfig , iter_matching_types , matching_types
4746
48- from injection ._core .common .asynchronous import (
49- Caller ,
50- HiddenCaller ,
51- SimpleAwaitable ,
52- )
47+ from injection ._core .common .asynchronous import Caller , SimpleAwaitable
5348from injection ._core .common .event import Event , EventChannel , EventListener
5449from injection ._core .common .invertible import Invertible , SimpleInvertible
55- from injection ._core .common .key import new_short_key
5650from injection ._core .common .lazy import Lazy
5751from injection ._core .common .threading import get_lock
5852from injection ._core .common .type import (
5953 InputType ,
6054 TypeInfo ,
6155 get_yield_hints ,
56+ iter_flat_types ,
6257 iter_return_types ,
6358)
6459from injection ._core .injectables import (
9489 SkipInjectable ,
9590)
9691
97- """
98- Events
99- """
100-
10192
10293@dataclass (frozen = True , slots = True )
10394class ModuleEvent (Event , ABC ):
@@ -154,11 +145,6 @@ def __str__(self) -> str:
154145 )
155146
156147
157- """
158- Module
159- """
160-
161-
162148class Priority (StrEnum ):
163149 LOW = "low"
164150 HIGH = "high"
@@ -187,7 +173,7 @@ class _ScopedContext[**P, T]:
187173
188174@dataclass (eq = False , frozen = True , slots = True )
189175class Module (EventListener , InjectionProvider ): # type: ignore[misc]
190- name : str = field (default_factory = lambda : f"anonymous@ { new_short_key () } " )
176+ name : str | None = field (default = None )
191177 __channel : EventChannel = field (
192178 default_factory = EventChannel ,
193179 init = False ,
@@ -730,9 +716,10 @@ def default(cls) -> Module:
730716 def __build_key_types (input_cls : Any ) -> frozenset [Any ]:
731717 config = MatchingTypesConfig (ignore_none = True )
732718 return frozenset (
733- itertools .chain .from_iterable (
734- iter_matching_types (cls , config ) for cls in iter_return_types (input_cls )
735- )
719+ matching_type
720+ for cls in iter_flat_types (input_cls )
721+ for return_type in iter_return_types (cls )
722+ for matching_type in iter_matching_types (return_type , config )
736723 )
737724
738725 @staticmethod
@@ -748,11 +735,6 @@ def mod(name: str | None = None, /) -> Module:
748735 return Module .from_name (name )
749736
750737
751- """
752- InjectedFunction
753- """
754-
755-
756738@dataclass (repr = False , frozen = True , slots = True )
757739class Dependencies :
758740 lazy_mapping : Lazy [Mapping [str , Injectable [Any ]]]
@@ -786,8 +768,7 @@ def items(self, exclude: Container[str]) -> Iterator[tuple[str, Injectable[Any]]
786768
787769 @classmethod
788770 def from_iterable (cls , iterable : Iterable [tuple [str , Injectable [Any ]]]) -> Self :
789- lazy_mapping = Lazy (lambda : dict (iterable ))
790- return cls (lazy_mapping )
771+ return cls (Lazy (lambda : dict (iterable )))
791772
792773 @classmethod
793774 def empty (cls ) -> Self :
@@ -970,7 +951,7 @@ def __run_tasks(self) -> None:
970951 task ()
971952
972953
973- class InjectedFunction [** P , T ](HiddenCaller [ P , T ], ABC ):
954+ class InjectedFunction [** P , T ](ABC ):
974955 __slots__ = ("__dict__" , "__injection_metadata__" )
975956
976957 __injection_metadata__ : InjectMetadata [P , T ]
@@ -985,10 +966,6 @@ def __repr__(self) -> str: # pragma: no cover
985966 def __str__ (self ) -> str : # pragma: no cover
986967 return str (self .__injection_metadata__ .wrapped )
987968
988- @property
989- def __injection_hidden_caller__ (self ) -> Caller [P , T ]:
990- return self .__injection_metadata__
991-
992969 def __get__ (
993970 self ,
994971 instance : object | None = None ,
@@ -1002,6 +979,10 @@ def __get__(
1002979 def __set_name__ (self , owner : type , name : str ) -> None :
1003980 self .__injection_metadata__ .set_owner (owner )
1004981
982+ @abstractmethod
983+ def __call__ (self , / , * args : P .args , ** kwargs : P .kwargs ) -> T :
984+ raise NotImplementedError
985+
1005986
1006987class AsyncInjectedFunction [** P , T ](InjectedFunction [P , Awaitable [T ]]):
1007988 __slots__ = ()
0 commit comments