anydi 0.64.0__tar.gz → 0.65.0__tar.gz

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.
Files changed (26) hide show
  1. {anydi-0.64.0 → anydi-0.65.0}/PKG-INFO +1 -1
  2. {anydi-0.64.0 → anydi-0.65.0}/anydi/_container.py +5 -0
  3. {anydi-0.64.0 → anydi-0.65.0}/anydi/_resolver.py +34 -16
  4. {anydi-0.64.0 → anydi-0.65.0}/pyproject.toml +1 -1
  5. {anydi-0.64.0 → anydi-0.65.0}/README.md +0 -0
  6. {anydi-0.64.0 → anydi-0.65.0}/anydi/__init__.py +0 -0
  7. {anydi-0.64.0 → anydi-0.65.0}/anydi/_async_lock.py +0 -0
  8. {anydi-0.64.0 → anydi-0.65.0}/anydi/_context.py +0 -0
  9. {anydi-0.64.0 → anydi-0.65.0}/anydi/_decorators.py +0 -0
  10. {anydi-0.64.0 → anydi-0.65.0}/anydi/_injector.py +0 -0
  11. {anydi-0.64.0 → anydi-0.65.0}/anydi/_marker.py +0 -0
  12. {anydi-0.64.0 → anydi-0.65.0}/anydi/_module.py +0 -0
  13. {anydi-0.64.0 → anydi-0.65.0}/anydi/_provider.py +0 -0
  14. {anydi-0.64.0 → anydi-0.65.0}/anydi/_scanner.py +0 -0
  15. {anydi-0.64.0 → anydi-0.65.0}/anydi/_types.py +0 -0
  16. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/__init__.py +0 -0
  17. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/django/__init__.py +0 -0
  18. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/fastapi.py +0 -0
  19. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/faststream.py +0 -0
  20. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/pydantic_settings.py +0 -0
  21. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/pytest_plugin.py +0 -0
  22. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/starlette/__init__.py +0 -0
  23. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/starlette/middleware.py +0 -0
  24. {anydi-0.64.0 → anydi-0.65.0}/anydi/ext/typer.py +0 -0
  25. {anydi-0.64.0 → anydi-0.65.0}/anydi/py.typed +0 -0
  26. {anydi-0.64.0 → anydi-0.65.0}/anydi/testing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.64.0
3
+ Version: 0.65.0
4
4
  Summary: Dependency Injection library
5
5
  Keywords: dependency injection,dependencies,di,async,asyncio,application
6
6
  Author: Anton Ruhlov
@@ -553,6 +553,11 @@ class Container:
553
553
  )
554
554
 
555
555
  self._set_provider(provider)
556
+
557
+ # Clear cached resolvers when overriding
558
+ if override:
559
+ self._resolver.clear_caches()
560
+
556
561
  return provider
557
562
 
558
563
  def _validate_provider_scope(
@@ -62,6 +62,13 @@ class Resolver:
62
62
  def add_unresolved(self, interface: Any) -> None:
63
63
  self._unresolved_interfaces.add(interface)
64
64
 
65
+ def clear_caches(self) -> None:
66
+ """Clear all cached resolvers."""
67
+ self._cache.clear()
68
+ self._async_cache.clear()
69
+ self._override_cache.clear()
70
+ self._async_override_cache.clear()
71
+
65
72
  def get_cached(self, interface: Any, *, is_async: bool) -> CompiledResolver | None:
66
73
  """Get cached resolver if it exists."""
67
74
  if self.override_mode:
@@ -83,9 +90,14 @@ class Resolver:
83
90
  return cache[provider.interface]
84
91
 
85
92
  # Recursively compile dependencies first
86
- for p in provider.parameters:
87
- if p.provider is not None:
88
- self.compile(p.provider, is_async=is_async)
93
+ for param in provider.parameters:
94
+ if param.provider is not None:
95
+ # Look up the current provider to handle overrides
96
+ current_provider = self._container.providers.get(param.annotation)
97
+ if current_provider is not None:
98
+ self.compile(current_provider, is_async=is_async)
99
+ else:
100
+ self.compile(param.provider, is_async=is_async)
89
101
 
90
102
  # Compile the resolver and creator functions
91
103
  compiled = self._compile_resolver(
@@ -155,23 +167,29 @@ class Resolver:
155
167
  else (self._async_cache if is_async else self._cache)
156
168
  )
157
169
 
158
- for idx, p in enumerate(provider.parameters):
159
- param_annotations[idx] = p.annotation
160
- param_defaults[idx] = p.default
161
- param_has_default[idx] = p.has_default
162
- param_names[idx] = p.name
163
- param_shared_scopes[idx] = p.shared_scope
164
-
165
- if p.provider is not None:
166
- compiled = cache.get(p.provider.interface)
170
+ for idx, param in enumerate(provider.parameters):
171
+ param_annotations[idx] = param.annotation
172
+ param_defaults[idx] = param.default
173
+ param_has_default[idx] = param.has_default
174
+ param_names[idx] = param.name
175
+ param_shared_scopes[idx] = param.shared_scope
176
+
177
+ if param.provider is not None:
178
+ # Look up the current provider from the container to handle overrides
179
+ current_provider = self._container.providers.get(param.annotation)
180
+ if current_provider is not None:
181
+ compiled = cache.get(current_provider.interface)
182
+ else:
183
+ # Fallback to the original provider if not in container
184
+ compiled = cache.get(param.provider.interface)
167
185
  if compiled is None:
168
- compiled = self.compile(p.provider, is_async=is_async)
169
- cache[p.provider.interface] = compiled
186
+ compiled = self.compile(param.provider, is_async=is_async)
187
+ cache[param.provider.interface] = compiled
170
188
  param_resolvers[idx] = compiled.resolve
171
189
 
172
190
  unresolved_message = (
173
- f"You are attempting to get the parameter `{p.name}` with the "
174
- f"annotation `{type_repr(p.annotation)}` as a dependency into "
191
+ f"You are attempting to get the parameter `{param.name}` with the "
192
+ f"annotation `{type_repr(param.annotation)}` as a dependency into "
175
193
  f"`{type_repr(provider.call)}` which is not registered or set in the "
176
194
  "scoped context."
177
195
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "anydi"
3
- version = "0.64.0"
3
+ version = "0.65.0"
4
4
  description = "Dependency Injection library"
5
5
  authors = [{ name = "Anton Ruhlov", email = "antonruhlov@gmail.com" }]
6
6
  requires-python = ">=3.10.0, <3.15"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes