@@ -560,7 +560,7 @@ def inject[**P, T](
560
560
wrapped : Callable [P , T ] | None = None ,
561
561
/ ,
562
562
* ,
563
- threadsafe : bool = False ,
563
+ threadsafe : bool | None = None ,
564
564
) -> Any :
565
565
def decorator (wp : Callable [P , T ]) -> Callable [P , T ]:
566
566
if isclass (wp ):
@@ -576,22 +576,22 @@ def make_injected_function[**P, T](
576
576
self ,
577
577
wrapped : Callable [P , T ],
578
578
/ ,
579
- threadsafe : bool = ...,
579
+ threadsafe : bool | None = ...,
580
580
) -> SyncInjectedFunction [P , T ]: ...
581
581
582
582
@overload
583
583
def make_injected_function [** P , T ](
584
584
self ,
585
585
wrapped : Callable [P , Awaitable [T ]],
586
586
/ ,
587
- threadsafe : bool = ...,
587
+ threadsafe : bool | None = ...,
588
588
) -> AsyncInjectedFunction [P , T ]: ...
589
589
590
590
def make_injected_function [** P , T ](
591
591
self ,
592
592
wrapped : Callable [P , T ],
593
593
/ ,
594
- threadsafe : bool = False ,
594
+ threadsafe : bool | None = None ,
595
595
) -> InjectedFunction [P , T ]:
596
596
metadata = InjectMetadata (wrapped , threadsafe )
597
597
@@ -609,7 +609,7 @@ def make_async_factory[T](
609
609
self ,
610
610
wrapped : type [T ],
611
611
/ ,
612
- threadsafe : bool = False ,
612
+ threadsafe : bool | None = None ,
613
613
) -> Callable [..., Awaitable [T ]]:
614
614
factory : InjectedFunction [..., T ] = self .make_injected_function (
615
615
wrapped ,
@@ -621,13 +621,18 @@ async def afind_instance[T](
621
621
self ,
622
622
cls : InputType [T ],
623
623
* ,
624
- threadsafe : bool = False ,
624
+ threadsafe : bool | None = None ,
625
625
) -> T :
626
626
with get_lock (threadsafe ):
627
627
injectable = self [cls ]
628
628
return await injectable .aget_instance ()
629
629
630
- def find_instance [T ](self , cls : InputType [T ], * , threadsafe : bool = False ) -> T :
630
+ def find_instance [T ](
631
+ self ,
632
+ cls : InputType [T ],
633
+ * ,
634
+ threadsafe : bool | None = None ,
635
+ ) -> T :
631
636
with get_lock (threadsafe ):
632
637
injectable = self [cls ]
633
638
return injectable .get_instance ()
@@ -638,7 +643,7 @@ async def aget_instance[T, Default](
638
643
cls : InputType [T ],
639
644
default : Default ,
640
645
* ,
641
- threadsafe : bool = ...,
646
+ threadsafe : bool | None = ...,
642
647
) -> T | Default : ...
643
648
644
649
@overload
@@ -647,15 +652,15 @@ async def aget_instance[T](
647
652
cls : InputType [T ],
648
653
default : T = ...,
649
654
* ,
650
- threadsafe : bool = ...,
655
+ threadsafe : bool | None = ...,
651
656
) -> T : ...
652
657
653
658
async def aget_instance [T , Default ](
654
659
self ,
655
660
cls : InputType [T ],
656
661
default : Default = NotImplemented ,
657
662
* ,
658
- threadsafe : bool = False ,
663
+ threadsafe : bool | None = None ,
659
664
) -> T | Default :
660
665
try :
661
666
return await self .afind_instance (cls , threadsafe = threadsafe )
@@ -668,7 +673,7 @@ def get_instance[T, Default](
668
673
cls : InputType [T ],
669
674
default : Default ,
670
675
* ,
671
- threadsafe : bool = ...,
676
+ threadsafe : bool | None = ...,
672
677
) -> T | Default : ...
673
678
674
679
@overload
@@ -677,15 +682,15 @@ def get_instance[T](
677
682
cls : InputType [T ],
678
683
default : T = ...,
679
684
* ,
680
- threadsafe : bool = ...,
685
+ threadsafe : bool | None = ...,
681
686
) -> T : ...
682
687
683
688
def get_instance [T , Default ](
684
689
self ,
685
690
cls : InputType [T ],
686
691
default : Default = NotImplemented ,
687
692
* ,
688
- threadsafe : bool = False ,
693
+ threadsafe : bool | None = None ,
689
694
) -> T | Default :
690
695
try :
691
696
return self .find_instance (cls , threadsafe = threadsafe )
@@ -698,7 +703,7 @@ def aget_lazy_instance[T, Default](
698
703
cls : InputType [T ],
699
704
default : Default ,
700
705
* ,
701
- threadsafe : bool = ...,
706
+ threadsafe : bool | None = ...,
702
707
) -> Awaitable [T | Default ]: ...
703
708
704
709
@overload
@@ -707,15 +712,15 @@ def aget_lazy_instance[T](
707
712
cls : InputType [T ],
708
713
default : T = ...,
709
714
* ,
710
- threadsafe : bool = ...,
715
+ threadsafe : bool | None = ...,
711
716
) -> Awaitable [T ]: ...
712
717
713
718
def aget_lazy_instance [T , Default ](
714
719
self ,
715
720
cls : InputType [T ],
716
721
default : Default = NotImplemented ,
717
722
* ,
718
- threadsafe : bool = False ,
723
+ threadsafe : bool | None = None ,
719
724
) -> Awaitable [T | Default ]:
720
725
function = self .make_injected_function (
721
726
lambda instance = default : instance ,
@@ -730,7 +735,7 @@ def get_lazy_instance[T, Default](
730
735
cls : InputType [T ],
731
736
default : Default ,
732
737
* ,
733
- threadsafe : bool = ...,
738
+ threadsafe : bool | None = ...,
734
739
) -> Invertible [T | Default ]: ...
735
740
736
741
@overload
@@ -739,15 +744,15 @@ def get_lazy_instance[T](
739
744
cls : InputType [T ],
740
745
default : T = ...,
741
746
* ,
742
- threadsafe : bool = ...,
747
+ threadsafe : bool | None = ...,
743
748
) -> Invertible [T ]: ...
744
749
745
750
def get_lazy_instance [T , Default ](
746
751
self ,
747
752
cls : InputType [T ],
748
753
default : Default = NotImplemented ,
749
754
* ,
750
- threadsafe : bool = False ,
755
+ threadsafe : bool | None = None ,
751
756
) -> Invertible [T | Default ]:
752
757
function = self .make_injected_function (
753
758
lambda instance = default : instance ,
@@ -1013,7 +1018,12 @@ class InjectMetadata[**P, T](Caller[P, T], EventListener):
1013
1018
__tasks : deque [Callable [..., Any ]]
1014
1019
__wrapped : Callable [P , T ]
1015
1020
1016
- def __init__ (self , wrapped : Callable [P , T ], / , threadsafe : bool ) -> None :
1021
+ def __init__ (
1022
+ self ,
1023
+ wrapped : Callable [P , T ],
1024
+ / ,
1025
+ threadsafe : bool | None = None ,
1026
+ ) -> None :
1017
1027
self .__dependencies = Dependencies .empty ()
1018
1028
self .__lock = get_lock (threadsafe )
1019
1029
self .__owner = None
0 commit comments