Skip to content

Commit d72d07c

Browse files
committed
Improve type annotations in providers
1 parent 009a86d commit d72d07c

File tree

1 file changed

+65
-71
lines changed

1 file changed

+65
-71
lines changed

src/dependency_injector/providers.pyi

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Object(Provider[T]):
8989
def __init__(self, provides: Optional[T] = None) -> None: ...
9090
@property
9191
def provides(self) -> Optional[T]: ...
92-
def set_provides(self, provides: Optional[T]) -> Object: ...
92+
def set_provides(self, provides: Optional[T]) -> _Self: ...
9393

9494
class Self(Provider[T]):
9595
def __init__(self, container: Optional[T] = None) -> None: ...
@@ -102,7 +102,7 @@ class Delegate(Provider[Provider]):
102102
def __init__(self, provides: Optional[Provider] = None) -> None: ...
103103
@property
104104
def provides(self) -> Optional[Provider]: ...
105-
def set_provides(self, provides: Optional[Provider]) -> Delegate: ...
105+
def set_provides(self, provides: Optional[Provider]) -> _Self: ...
106106

107107
class Aggregate(Provider[T]):
108108
def __init__(
@@ -128,7 +128,7 @@ class Aggregate(Provider[T]):
128128
self,
129129
provider_dict: Optional[Mapping[Any, Provider[T]]] = None,
130130
**provider_kwargs: Provider[T],
131-
) -> Aggregate[T]: ...
131+
) -> _Self: ...
132132

133133
class Dependency(Provider[T]):
134134
def __init__(
@@ -139,10 +139,10 @@ class Dependency(Provider[T]):
139139
def __getattr__(self, name: str) -> Any: ...
140140
@property
141141
def instance_of(self) -> Type[T]: ...
142-
def set_instance_of(self, instance_of: Type[T]) -> Dependency[T]: ...
142+
def set_instance_of(self, instance_of: Type[T]) -> _Self: ...
143143
@property
144144
def default(self) -> Provider[T]: ...
145-
def set_default(self, default: Optional[Union[Provider, Any]]) -> Dependency[T]: ...
145+
def set_default(self, default: Optional[Union[Provider, Any]]) -> _Self: ...
146146
@property
147147
def is_defined(self) -> bool: ...
148148
def provided_by(self, provider: Provider) -> OverridingContext[P]: ...
@@ -166,28 +166,28 @@ class DependenciesContainer(Object):
166166
def parent_name(self) -> Optional[str]: ...
167167
def assign_parent(self, parent: ProviderParent) -> None: ...
168168

169-
class Callable(Provider[T]):
169+
class Callable(Provider[T_Any]):
170170
def __init__(
171171
self,
172-
provides: Optional[Union[_Callable[..., T], str]] = None,
172+
provides: Optional[Union[_Callable[..., T_Any], str]] = None,
173173
*args: Injection,
174174
**kwargs: Injection,
175175
) -> None: ...
176176
@property
177-
def provides(self) -> Optional[_Callable[..., T]]: ...
177+
def provides(self) -> Optional[_Callable[..., T_Any]]: ...
178178
def set_provides(
179-
self, provides: Optional[Union[_Callable[..., T], str]]
180-
) -> Callable[T]: ...
179+
self, provides: Optional[Union[_Callable[..., T_Any], str]]
180+
) -> _Self: ...
181181
@property
182182
def args(self) -> Tuple[Injection]: ...
183-
def add_args(self, *args: Injection) -> Callable[T]: ...
184-
def set_args(self, *args: Injection) -> Callable[T]: ...
185-
def clear_args(self) -> Callable[T]: ...
183+
def add_args(self, *args: Injection) -> _Self: ...
184+
def set_args(self, *args: Injection) -> _Self: ...
185+
def clear_args(self) -> _Self: ...
186186
@property
187187
def kwargs(self) -> _Dict[str, Injection]: ...
188-
def add_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
189-
def set_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
190-
def clear_kwargs(self) -> Callable[T]: ...
188+
def add_kwargs(self, **kwargs: Injection) -> _Self: ...
189+
def set_kwargs(self, **kwargs: Injection) -> _Self: ...
190+
def clear_kwargs(self) -> _Self: ...
191191

192192
class DelegatedCallable(Callable[T]): ...
193193

@@ -209,7 +209,7 @@ class CoroutineDelegate(Delegate):
209209
class ConfigurationOption(Provider[Any]):
210210
UNDEFINED: object
211211
def __init__(self, name: Tuple[str], root: Configuration) -> None: ...
212-
def __enter__(self) -> ConfigurationOption: ...
212+
def __enter__(self) -> _Self: ...
213213
def __exit__(self, *exc_info: Any) -> None: ...
214214
def __getattr__(self, item: str) -> ConfigurationOption: ...
215215
def __getitem__(self, item: Union[str, Provider]) -> ConfigurationOption: ...
@@ -274,30 +274,26 @@ class Configuration(Object[Any]):
274274
json_files: Optional[_Iterable[Union[Path, str]]] = None,
275275
pydantic_settings: Optional[_Iterable[PydanticSettings]] = None,
276276
) -> None: ...
277-
def __enter__(self) -> Configuration: ...
277+
def __enter__(self) -> _Self: ...
278278
def __exit__(self, *exc_info: Any) -> None: ...
279279
def __getattr__(self, item: str) -> ConfigurationOption: ...
280280
def __getitem__(self, item: Union[str, Provider]) -> ConfigurationOption: ...
281281
def get_name(self) -> str: ...
282-
def set_name(self, name: str) -> Configuration: ...
282+
def set_name(self, name: str) -> _Self: ...
283283
def get_default(self) -> _Dict[Any, Any]: ...
284-
def set_default(self, default: _Dict[Any, Any]): ...
284+
def set_default(self, default: _Dict[Any, Any]) -> _Self: ...
285285
def get_strict(self) -> bool: ...
286-
def set_strict(self, strict: bool) -> Configuration: ...
286+
def set_strict(self, strict: bool) -> _Self: ...
287287
def get_children(self) -> _Dict[str, ConfigurationOption]: ...
288-
def set_children(
289-
self, children: _Dict[str, ConfigurationOption]
290-
) -> Configuration: ...
288+
def set_children(self, children: _Dict[str, ConfigurationOption]) -> _Self: ...
291289
def get_ini_files(self) -> _List[Union[Path, str]]: ...
292-
def set_ini_files(self, files: _Iterable[Union[Path, str]]) -> Configuration: ...
290+
def set_ini_files(self, files: _Iterable[Union[Path, str]]) -> _Self: ...
293291
def get_yaml_files(self) -> _List[Union[Path, str]]: ...
294-
def set_yaml_files(self, files: _Iterable[Union[Path, str]]) -> Configuration: ...
292+
def set_yaml_files(self, files: _Iterable[Union[Path, str]]) -> _Self: ...
295293
def get_json_files(self) -> _List[Union[Path, str]]: ...
296-
def set_json_files(self, files: _Iterable[Union[Path, str]]) -> Configuration: ...
294+
def set_json_files(self, files: _Iterable[Union[Path, str]]) -> _Self: ...
297295
def get_pydantic_settings(self) -> _List[PydanticSettings]: ...
298-
def set_pydantic_settings(
299-
self, settings: _Iterable[PydanticSettings]
300-
) -> Configuration: ...
296+
def set_pydantic_settings(self, settings: _Iterable[PydanticSettings]) -> _Self: ...
301297
def load(self, required: bool = False, envs_required: bool = False) -> None: ...
302298
def get(self, selector: str) -> Any: ...
303299
def set(self, selector: str, value: Any) -> OverridingContext[P]: ...
@@ -349,22 +345,22 @@ class Factory(Provider[T]):
349345
def provides(self) -> Optional[_Callable[..., T]]: ...
350346
def set_provides(
351347
self, provides: Optional[Union[_Callable[..., T], str]]
352-
) -> Factory[T]: ...
348+
) -> _Self: ...
353349
@property
354350
def args(self) -> Tuple[Injection]: ...
355-
def add_args(self, *args: Injection) -> Factory[T]: ...
356-
def set_args(self, *args: Injection) -> Factory[T]: ...
357-
def clear_args(self) -> Factory[T]: ...
351+
def add_args(self, *args: Injection) -> _Self: ...
352+
def set_args(self, *args: Injection) -> _Self: ...
353+
def clear_args(self) -> _Self: ...
358354
@property
359355
def kwargs(self) -> _Dict[str, Injection]: ...
360-
def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
361-
def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
362-
def clear_kwargs(self) -> Factory[T]: ...
356+
def add_kwargs(self, **kwargs: Injection) -> _Self: ...
357+
def set_kwargs(self, **kwargs: Injection) -> _Self: ...
358+
def clear_kwargs(self) -> _Self: ...
363359
@property
364-
def attributes(self) -> _Dict[Any, Injection]: ...
365-
def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
366-
def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
367-
def clear_attributes(self) -> Factory[T]: ...
360+
def attributes(self) -> _Dict[str, Injection]: ...
361+
def add_attributes(self, **kwargs: Injection) -> _Self: ...
362+
def set_attributes(self, **kwargs: Injection) -> _Self: ...
363+
def clear_attributes(self) -> _Self: ...
368364

369365
class DelegatedFactory(Factory[T]): ...
370366

@@ -398,22 +394,22 @@ class BaseSingleton(Provider[T]):
398394
def provides(self) -> Optional[_Callable[..., T]]: ...
399395
def set_provides(
400396
self, provides: Optional[Union[_Callable[..., T], str]]
401-
) -> BaseSingleton[T]: ...
397+
) -> _Self: ...
402398
@property
403399
def args(self) -> Tuple[Injection]: ...
404-
def add_args(self, *args: Injection) -> BaseSingleton[T]: ...
405-
def set_args(self, *args: Injection) -> BaseSingleton[T]: ...
406-
def clear_args(self) -> BaseSingleton[T]: ...
400+
def add_args(self, *args: Injection) -> _Self: ...
401+
def set_args(self, *args: Injection) -> _Self: ...
402+
def clear_args(self) -> _Self: ...
407403
@property
408404
def kwargs(self) -> _Dict[str, Injection]: ...
409-
def add_kwargs(self, **kwargs: Injection) -> BaseSingleton[T]: ...
410-
def set_kwargs(self, **kwargs: Injection) -> BaseSingleton[T]: ...
411-
def clear_kwargs(self) -> BaseSingleton[T]: ...
412-
@property
413-
def attributes(self) -> _Dict[Any, Injection]: ...
414-
def add_attributes(self, **kwargs: Injection) -> BaseSingleton[T]: ...
415-
def set_attributes(self, **kwargs: Injection) -> BaseSingleton[T]: ...
416-
def clear_attributes(self) -> BaseSingleton[T]: ...
405+
def add_kwargs(self, **kwargs: Injection) -> _Self: ...
406+
def set_kwargs(self, **kwargs: Injection) -> _Self: ...
407+
def clear_kwargs(self) -> _Self: ...
408+
@property
409+
def attributes(self) -> _Dict[str, Injection]: ...
410+
def add_attributes(self, **kwargs: Injection) -> _Self: ...
411+
def set_attributes(self, **kwargs: Injection) -> _Self: ...
412+
def clear_attributes(self) -> _Self: ...
417413
def reset(self) -> SingletonResetContext[BS]: ...
418414
def full_reset(self) -> SingletonFullResetContext[BS]: ...
419415

@@ -435,9 +431,9 @@ class List(Provider[_List]):
435431
def __init__(self, *args: Injection): ...
436432
@property
437433
def args(self) -> Tuple[Injection]: ...
438-
def add_args(self, *args: Injection) -> List[T]: ...
439-
def set_args(self, *args: Injection) -> List[T]: ...
440-
def clear_args(self) -> List[T]: ...
434+
def add_args(self, *args: Injection) -> _Self: ...
435+
def set_args(self, *args: Injection) -> _Self: ...
436+
def clear_args(self) -> _Self: ...
441437

442438
class Dict(Provider[_Dict]):
443439
def __init__(
@@ -447,11 +443,11 @@ class Dict(Provider[_Dict]):
447443
def kwargs(self) -> _Dict[Any, Injection]: ...
448444
def add_kwargs(
449445
self, dict_: Optional[Mapping[Any, Injection]] = None, **kwargs: Injection
450-
) -> Dict: ...
446+
) -> _Self: ...
451447
def set_kwargs(
452448
self, dict_: Optional[Mapping[Any, Injection]] = None, **kwargs: Injection
453-
) -> Dict: ...
454-
def clear_kwargs(self) -> Dict: ...
449+
) -> _Self: ...
450+
def clear_kwargs(self) -> _Self: ...
455451

456452
class Resource(Provider[T]):
457453
@overload
@@ -512,17 +508,17 @@ class Resource(Provider[T]):
512508
) -> None: ...
513509
@property
514510
def provides(self) -> Optional[_Callable[..., Any]]: ...
515-
def set_provides(self, provides: Optional[Any]) -> Resource[T]: ...
511+
def set_provides(self, provides: Optional[Any]) -> _Self: ...
516512
@property
517513
def args(self) -> Tuple[Injection]: ...
518-
def add_args(self, *args: Injection) -> Resource[T]: ...
519-
def set_args(self, *args: Injection) -> Resource[T]: ...
520-
def clear_args(self) -> Resource[T]: ...
514+
def add_args(self, *args: Injection) -> _Self: ...
515+
def set_args(self, *args: Injection) -> _Self: ...
516+
def clear_args(self) -> _Self: ...
521517
@property
522518
def kwargs(self) -> _Dict[str, Injection]: ...
523-
def add_kwargs(self, **kwargs: Injection) -> Resource[T]: ...
524-
def set_kwargs(self, **kwargs: Injection) -> Resource[T]: ...
525-
def clear_kwargs(self) -> Resource[T]: ...
519+
def add_kwargs(self, **kwargs: Injection) -> _Self: ...
520+
def set_kwargs(self, **kwargs: Injection) -> _Self: ...
521+
def clear_kwargs(self) -> _Self: ...
526522
@property
527523
def initialized(self) -> bool: ...
528524
def init(self) -> Optional[Awaitable[T]]: ...
@@ -563,9 +559,7 @@ class ProvidedInstanceFluentInterface:
563559
def call(self, *args: Injection, **kwargs: Injection) -> MethodCaller: ...
564560
@property
565561
def provides(self) -> Optional[Provider]: ...
566-
def set_provides(
567-
self, provides: Optional[Provider]
568-
) -> ProvidedInstanceFluentInterface: ...
562+
def set_provides(self, provides: Optional[Provider]) -> _Self: ...
569563

570564
class ProvidedInstance(Provider, ProvidedInstanceFluentInterface):
571565
def __init__(self, provides: Optional[Provider] = None) -> None: ...
@@ -576,15 +570,15 @@ class AttributeGetter(Provider, ProvidedInstanceFluentInterface):
576570
) -> None: ...
577571
@property
578572
def name(self) -> Optional[str]: ...
579-
def set_name(self, name: Optional[str]) -> ProvidedInstanceFluentInterface: ...
573+
def set_name(self, name: Optional[str]) -> _Self: ...
580574

581575
class ItemGetter(Provider, ProvidedInstanceFluentInterface):
582576
def __init__(
583577
self, provides: Optional[Provider] = None, name: Optional[str] = None
584578
) -> None: ...
585579
@property
586580
def name(self) -> Optional[str]: ...
587-
def set_name(self, name: Optional[str]) -> ProvidedInstanceFluentInterface: ...
581+
def set_name(self, name: Optional[str]) -> _Self: ...
588582

589583
class MethodCaller(Provider, ProvidedInstanceFluentInterface):
590584
def __init__(

0 commit comments

Comments
 (0)