anydi 0.54.1__py3-none-any.whl → 0.55.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
anydi/testing.py CHANGED
@@ -1,18 +1,15 @@
1
1
  import contextlib
2
2
  import logging
3
3
  from collections.abc import Iterable, Iterator, Sequence
4
- from typing import Any, TypeVar
4
+ from typing import Any
5
5
 
6
6
  import wrapt # type: ignore
7
7
  from typing_extensions import Self, type_repr
8
8
 
9
9
  from ._container import Container
10
- from ._context import InstanceContext
11
10
  from ._module import ModuleDef
12
- from ._provider import Provider, ProviderDef, ProviderParameter
13
- from ._scope import Scope
14
-
15
- T = TypeVar("T")
11
+ from ._provider import ProviderDef
12
+ from ._types import NOT_SET
16
13
 
17
14
 
18
15
  class TestContainer(Container):
@@ -23,11 +20,11 @@ class TestContainer(Container):
23
20
  *,
24
21
  providers: Sequence[ProviderDef] | None = None,
25
22
  modules: Iterable[ModuleDef] | None = None,
26
- default_scope: Scope = "transient",
27
23
  logger: logging.Logger | None = None,
28
24
  ) -> None:
29
25
  super().__init__(providers=providers, modules=modules, logger=logger)
30
26
  self._override_instances: dict[Any, Any] = {}
27
+ self._revisions: dict[Any, int] = {}
31
28
 
32
29
  @classmethod
33
30
  def from_container(cls, container: Container) -> Self:
@@ -53,54 +50,23 @@ class TestContainer(Container):
53
50
  f"The provider interface `{type_repr(interface)}` not registered."
54
51
  )
55
52
  self._override_instances[interface] = instance
53
+ self._touch_revision(interface)
56
54
  try:
57
55
  yield
58
56
  finally:
59
57
  self._override_instances.pop(interface, None)
58
+ self._touch_revision(interface)
60
59
 
61
- def _resolve_or_create(
62
- self, interface: Any, create: bool, /, **defaults: Any
63
- ) -> Any:
64
- """Internal method to handle instance resolution and creation."""
65
- instance = super()._resolve_or_create(interface, create, **defaults)
66
- return self._patch_resolver(interface, instance)
67
-
68
- async def _aresolve_or_create(
69
- self, interface: Any, create: bool, /, **defaults: Any
70
- ) -> Any:
71
- """Internal method to handle instance resolution and creation asynchronously."""
72
- instance = await super()._aresolve_or_create(interface, create, **defaults)
73
- return self._patch_resolver(interface, instance)
74
-
75
- def _get_provider_instance(
76
- self,
77
- provider: Provider,
78
- parameter: ProviderParameter,
79
- context: InstanceContext | None,
80
- /,
81
- **defaults: Any,
82
- ) -> Any:
83
- """Retrieve an instance of a dependency from the scoped context."""
84
- instance = super()._get_provider_instance(
85
- provider, parameter, context, **defaults
86
- )
87
- return InstanceProxy(instance, interface=parameter.annotation)
60
+ def _touch_revision(self, interface: Any) -> None:
61
+ self._revisions[interface] = self._revisions.get(interface, 0) + 1
88
62
 
89
- async def _aget_provider_instance(
90
- self,
91
- provider: Provider,
92
- parameter: ProviderParameter,
93
- context: InstanceContext | None,
94
- /,
95
- **defaults: Any,
96
- ) -> Any:
97
- """Asynchronously retrieve an instance of a dependency from the context."""
98
- instance = await super()._aget_provider_instance(
99
- provider, parameter, context, **defaults
100
- )
101
- return InstanceProxy(instance, interface=parameter.annotation)
63
+ def _hook_override_for(self, interface: Any) -> Any:
64
+ return self._override_instances.get(interface, NOT_SET)
65
+
66
+ def _hook_wrap_dependency(self, annotation: Any, value: Any) -> Any:
67
+ return InstanceProxy(value, interface=annotation)
102
68
 
103
- def _patch_resolver(self, interface: Any, instance: Any) -> Any:
69
+ def _hook_post_resolve(self, interface: Any, instance: Any) -> Any: # noqa: C901
104
70
  """Patch the test resolver for the instance."""
105
71
  if interface in self._override_instances:
106
72
  return self._override_instances[interface]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.54.1
3
+ Version: 0.55.1
4
4
  Summary: Dependency Injection library
5
5
  Keywords: dependency injection,dependencies,di,async,asyncio,application
6
6
  Author: Anton Ruhlov
@@ -35,21 +35,15 @@ Description-Content-Type: text/markdown
35
35
 
36
36
  # AnyDI
37
37
 
38
- <p align="center">
39
- <i>Modern, lightweight Dependency Injection library using type annotations.</i>
40
- </p>
41
-
42
- <p align="center">
43
- <a href="https://github.com/antonrh/anydi/actions/workflows/ci.yml" target="_blank">
44
- <img src="https://github.com/antonrh/anydi/actions/workflows/ci.yml/badge.svg" alt="CI">
45
- </a>
46
- <a href="https://codecov.io/gh/antonrh/anydi" target="_blank">
47
- <img src="https://codecov.io/gh/antonrh/anydi/branch/main/graph/badge.svg?token=67CLD19I0C" alt="Coverage">
48
- </a>
49
- <a href="https://anydi.readthedocs.io/en/latest/?badge=latest" target="_blank">
50
- <img src="https://readthedocs.org/projects/anydi/badge/?version=latest" alt="Documentation">
51
- </a>
52
- </p>
38
+ <div style="text-align: center;">
39
+
40
+ Modern, lightweight Dependency Injection library using type annotations.
41
+
42
+ [![CI](https://github.com/antonrh/anydi/actions/workflows/ci.yml/badge.svg)](https://github.com/antonrh/anydi/actions/workflows/ci.yml)
43
+ [![Coverage](https://codecov.io/gh/antonrh/anydi/branch/main/graph/badge.svg)](https://codecov.io/gh/antonrh/anydi)
44
+ [![Documentation](https://readthedocs.org/projects/anydi/badge/?version=latest)](https://anydi.readthedocs.io/en/latest/)
45
+
46
+ </div>
53
47
 
54
48
  ---
55
49
  Documentation
@@ -0,0 +1,24 @@
1
+ anydi/__init__.py,sha256=Cz-beqReX0d05SFDmYcrzIs3FqQkWAwpy1Aqzd5db34,547
2
+ anydi/_async_lock.py,sha256=3dwZr0KthXFYha0XKMyXf8jMmGb1lYoNC0O5w29V9ic,1104
3
+ anydi/_container.py,sha256=6C8LM9PxMahKnu7YLMGJ50dPzYLRknZ9G9RKwyB18wE,24853
4
+ anydi/_context.py,sha256=-9QqeMWo9OpZVXZxZCQgIsswggl3Ch7lgx1KiFX_ezc,3752
5
+ anydi/_decorators.py,sha256=J3W261ZAG7q4XKm4tbAv1wsWr9ysx9_5MUbUvSJB_MQ,2809
6
+ anydi/_module.py,sha256=2kN5uEXLd2Dsc58gz5IWK43wJewr_QgIVGSO3iWp798,2609
7
+ anydi/_provider.py,sha256=OV1WFHTYv7W2U0XDk_Kql1r551Vhq8o-pUV5ep1HQcU,1574
8
+ anydi/_resolver.py,sha256=olWUYp0PfsWUt7hp2MW69734T29ck6fu3s7Nk4-U7rU,25183
9
+ anydi/_scanner.py,sha256=oycIC9kw9fsIG9qgtRHeBkj3HjmcLK0FTqWLXTLLSWE,3636
10
+ anydi/_types.py,sha256=l3xQ0Zn15gRAwvBoQ9PRfCBigi2rrtSqGV-C50xXrLw,1780
11
+ anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ anydi/ext/django/__init__.py,sha256=Ve8lncLU9dPY_Vjt4zihPgsSxwAtFHACn0XvBM5JG8k,367
13
+ anydi/ext/fastapi.py,sha256=FflFBdK-moyv9Vsfem4NyNt8jgPwFLweeCl5cfU0Iks,2348
14
+ anydi/ext/faststream.py,sha256=dJPInvi0JUx-SS8H4aBRl3u-PAW6S_TqqfxVOl3D1L0,1929
15
+ anydi/ext/pydantic_settings.py,sha256=0GQjw7QpQlT5p6GxFClXYdtc6J42PClmAnRWPEzMjvY,1488
16
+ anydi/ext/pytest_plugin.py,sha256=Es1K1S6_2gIdTUYkbw2d1aZcHnjJutGFafVsLPGcVJc,4684
17
+ anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ anydi/ext/starlette/middleware.py,sha256=MxnzshAs-CMvjJp0r457k52MzBL8O4KAuClnF6exBdU,803
19
+ anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ anydi/testing.py,sha256=JNXA-XGjkU7PMturkzDzumDcLlnYOLzCtBUQ9HyQMLM,4309
21
+ anydi-0.55.1.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
22
+ anydi-0.55.1.dist-info/entry_points.txt,sha256=AgOcQYM5KyS4D37QcYb00tiid0QA-pD1VrjHHq4QAps,44
23
+ anydi-0.55.1.dist-info/METADATA,sha256=TEL8yqko7Et9BJW8uiUq8r-Hjjj5PcYYXBS91eHTuPE,4799
24
+ anydi-0.55.1.dist-info/RECORD,,
anydi/_scope.py DELETED
@@ -1,9 +0,0 @@
1
- from typing import Literal
2
-
3
- Scope = Literal["transient", "singleton", "request"]
4
-
5
- ALLOWED_SCOPES: dict[Scope, list[Scope]] = {
6
- "singleton": ["singleton"],
7
- "request": ["request", "singleton"],
8
- "transient": ["transient", "request", "singleton"],
9
- }
@@ -1,24 +0,0 @@
1
- anydi/__init__.py,sha256=KjjYm-1yAFxiPYaMs1WRJMtxE0q_vdX7ZRLQR1fFGs8,567
2
- anydi/_async.py,sha256=lrKTrqMC81POFbea3kaC9KkY3sp0DaenuVPvwOg88xA,1472
3
- anydi/_container.py,sha256=zNDS22G52JlCPvrRM0fD4FvzP3rvvipqYyRhDXcMjKU,35233
4
- anydi/_context.py,sha256=_9hKjimFZhnVs_lllon0111az8-KtwzBRpxnNoOy3Z0,3075
5
- anydi/_decorators.py,sha256=yxY876_2fzC30UIb4-4mR-J5ToQN3BH61E2cFH-iX8Y,2809
6
- anydi/_module.py,sha256=2kN5uEXLd2Dsc58gz5IWK43wJewr_QgIVGSO3iWp798,2609
7
- anydi/_provider.py,sha256=HwbAIJzj6jV0qlA2lzOmueVdScJAAB9Yzu5leboKCUs,2386
8
- anydi/_scan.py,sha256=BLayc0NY_NYicr-ApX7Ztco9sd0izSZKGB-pUktui_s,3637
9
- anydi/_scope.py,sha256=PFHjPb2-n0vhRo9mvD_craTFfoJBzR3y-N3_0apL5Q0,258
10
- anydi/_typing.py,sha256=I0Qt3Ec6ki6ZXf0Krm-LUIPRvzvyUUHfKdvmQijBErQ,1718
11
- anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- anydi/ext/django/__init__.py,sha256=Ve8lncLU9dPY_Vjt4zihPgsSxwAtFHACn0XvBM5JG8k,367
13
- anydi/ext/fastapi.py,sha256=pdYumpXMAw2VjlDlb8u3R_RQi6htRieiZKsSA-9BSdA,2349
14
- anydi/ext/faststream.py,sha256=CEuGjVZRbgSjkeV1rSp6xWggGYoKnBDeo3PiPgKtxuc,1930
15
- anydi/ext/pydantic_settings.py,sha256=0GQjw7QpQlT5p6GxFClXYdtc6J42PClmAnRWPEzMjvY,1488
16
- anydi/ext/pytest_plugin.py,sha256=Es1K1S6_2gIdTUYkbw2d1aZcHnjJutGFafVsLPGcVJc,4684
17
- anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- anydi/ext/starlette/middleware.py,sha256=MxnzshAs-CMvjJp0r457k52MzBL8O4KAuClnF6exBdU,803
19
- anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- anydi/testing.py,sha256=X_zQqwqhqTbzp4YL9b9b2CQ0ag7gHO1cH-ASRVmVFoU,5523
21
- anydi-0.54.1.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
22
- anydi-0.54.1.dist-info/entry_points.txt,sha256=AgOcQYM5KyS4D37QcYb00tiid0QA-pD1VrjHHq4QAps,44
23
- anydi-0.54.1.dist-info/METADATA,sha256=0l58D93hIjXzIhJuWMXJ0ofEYzMbixoMI4gfphGhfjs,5022
24
- anydi-0.54.1.dist-info/RECORD,,
File without changes