2020from typing import (
2121 cast ,
2222 get_type_hints ,
23+ overload ,
2324)
2425
2526T = TypeVar ("T" )
@@ -31,10 +32,16 @@ class ContainerProtocol(Protocol):
3132 and tell if a type is configured.
3233 """
3334
34- def register (self , obj_type : Type | str , * args , ** kwargs ):
35+ def register (self , obj_type : Type | str , * args , ** kwargs ) -> None :
3536 """Registers a type in the container, with optional arguments."""
3637
37- def resolve (self , obj_type : Type [T ] | str , * args , ** kwargs ) -> T :
38+ @overload
39+ def resolve (self , obj_type : Type [T ], * args , ** kwargs ) -> T : ...
40+
41+ @overload
42+ def resolve (self , obj_type : str , * args , ** kwargs ) -> Any : ...
43+
44+ def resolve (self , obj_type : Type [T ] | str , * args , ** kwargs ) -> Any :
3845 """Activates an instance of the given type, with optional arguments."""
3946
4047 def __contains__ (self , item ) -> bool :
@@ -934,13 +941,31 @@ def register(
934941 self .add_transient (obj_type , sub_type )
935942 return self
936943
944+ @overload
945+ def resolve (
946+ self ,
947+ obj_type : Type [T ],
948+ scope : Any = None ,
949+ * args ,
950+ ** kwargs ,
951+ ) -> T : ...
952+
953+ @overload
954+ def resolve (
955+ self ,
956+ obj_type : str ,
957+ scope : Any = None ,
958+ * args ,
959+ ** kwargs ,
960+ ) -> Any : ...
961+
937962 def resolve (
938963 self ,
939964 obj_type : Type [T ] | str ,
940965 scope : Any = None ,
941966 * args ,
942967 ** kwargs ,
943- ) -> T :
968+ ) -> Any :
944969 """
945970 Resolves a service by type, obtaining an instance of that type.
946971 """
0 commit comments