26
26
)
27
27
28
28
from injection .common .event import Event , EventChannel , EventListener
29
- from injection .common .lazy import LazyMapping
29
+ from injection .common .lazy import Lazy , LazyMapping
30
30
from injection .exceptions import (
31
31
ModuleCircularUseError ,
32
32
ModuleError ,
@@ -515,13 +515,11 @@ def decorator(wp):
515
515
return decorator (wrapped ) if wrapped else decorator
516
516
517
517
def __decorator (self , function : Callable [..., Any ], / ) -> Callable [..., Any ]:
518
- signature = inspect .signature (function , eval_str = True )
519
- binder = Binder (signature ).update (self .__module )
520
- self .__module .add_listener (binder )
518
+ lazy_binder = Lazy [Binder ](lambda : self .__new_binder (function ))
521
519
522
520
@wraps (function )
523
521
def wrapper (* args , ** kwargs ):
524
- arguments = binder .bind (* args , ** kwargs )
522
+ arguments = lazy_binder . value .bind (* args , ** kwargs )
525
523
return function (* arguments .args , ** arguments .kwargs )
526
524
527
525
return wrapper
@@ -531,6 +529,12 @@ def __class_decorator(self, cls: type, /) -> type:
531
529
type .__setattr__ (cls , "__init__" , self .__decorator (init_function ))
532
530
return cls
533
531
532
+ def __new_binder (self , function : Callable [..., Any ]) -> Binder :
533
+ signature = inspect .signature (function , eval_str = True )
534
+ binder = Binder (signature ).update (self .__module )
535
+ self .__module .add_listener (binder )
536
+ return binder
537
+
534
538
535
539
@final
536
540
@dataclass (repr = False , frozen = True , slots = True )
@@ -552,7 +556,7 @@ def decorator(wp):
552
556
if auto_inject :
553
557
wp = self .__module .inject (wp )
554
558
555
- @lambda function : function ()
559
+ @lambda fn : fn ()
556
560
def references ():
557
561
if reference := self .__get_reference (wp ):
558
562
yield reference
0 commit comments