anydi 0.55.0__tar.gz → 0.55.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.55.0
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
@@ -339,6 +339,7 @@ class Container:
339
339
  default=default,
340
340
  has_default=has_default,
341
341
  provider=sub_provider,
342
+ shared_scope=sub_provider.scope == scope and scope != "transient",
342
343
  )
343
344
  )
344
345
 
@@ -389,10 +390,10 @@ class Container:
389
390
  @staticmethod
390
391
  def _validate_provider_scope(scope: Scope, name: str, is_resource: bool) -> None:
391
392
  """Validate the provider scope."""
392
- if scope not in (allowed_scopes := get_args(Scope)):
393
+ if scope not in ALLOWED_SCOPES:
393
394
  raise ValueError(
394
395
  f"The provider `{name}` scope is invalid. Only the following "
395
- f"scopes are supported: {', '.join(allowed_scopes)}. "
396
+ f"scopes are supported: {', '.join(ALLOWED_SCOPES)}. "
396
397
  "Please use one of the supported scopes when registering a provider."
397
398
  )
398
399
  if scope == "transient" and is_resource:
@@ -40,6 +40,7 @@ class ProviderParameter:
40
40
  default: Any
41
41
  has_default: bool
42
42
  provider: Provider | None = None
43
+ shared_scope: bool = False
43
44
 
44
45
 
45
46
  @dataclass(frozen=True, slots=True)
@@ -81,6 +81,7 @@ class Resolver:
81
81
  param_defaults: list[Any] = [None] * num_params
82
82
  param_has_default: list[bool] = [False] * num_params
83
83
  param_names: list[str] = [""] * num_params
84
+ param_shared_scopes: list[bool] = [False] * num_params
84
85
  unresolved_messages: list[str] = [""] * num_params
85
86
 
86
87
  cache = self._async_cache if is_async else self._cache
@@ -90,6 +91,7 @@ class Resolver:
90
91
  param_defaults[idx] = p.default
91
92
  param_has_default[idx] = p.has_default
92
93
  param_names[idx] = p.name
94
+ param_shared_scopes[idx] = p.shared_scope
93
95
 
94
96
  if p.provider is not None:
95
97
  compiled = cache.get(p.provider.interface)
@@ -191,7 +193,8 @@ class Resolver:
191
193
  )
192
194
  create_lines.append(
193
195
  f" arg_{idx} = "
194
- f"await compiled[0](container, context)"
196
+ f"await compiled[0](container, "
197
+ f"context if _param_shared_scopes[{idx}] else None)"
195
198
  )
196
199
  else:
197
200
  create_lines.append(
@@ -212,7 +215,8 @@ class Resolver:
212
215
  )
213
216
  create_lines.append(
214
217
  f" arg_{idx} = "
215
- f"compiled[0](container, context)"
218
+ f"compiled[0](container, "
219
+ f"context if _param_shared_scopes[{idx}] else None)"
216
220
  )
217
221
  create_lines.append(" except LookupError:")
218
222
  create_lines.append(
@@ -227,11 +231,14 @@ class Resolver:
227
231
  if is_async:
228
232
  create_lines.append(
229
233
  f" arg_{idx} = await resolver("
230
- f"container, context)"
234
+ f"container, "
235
+ f"context if _param_shared_scopes[{idx}] else None)"
231
236
  )
232
237
  else:
233
238
  create_lines.append(
234
- f" arg_{idx} = resolver(container, context)"
239
+ f" arg_{idx} = resolver("
240
+ f"container, "
241
+ f"context if _param_shared_scopes[{idx}] else None)"
235
242
  )
236
243
  create_lines.append(" else:")
237
244
  create_lines.append(f" arg_{idx} = cached")
@@ -539,6 +546,7 @@ class Resolver:
539
546
  "_param_defaults": param_defaults,
540
547
  "_param_has_default": param_has_default,
541
548
  "_param_resolvers": param_resolvers,
549
+ "_param_shared_scopes": param_shared_scopes,
542
550
  "_unresolved_messages": unresolved_messages,
543
551
  "_unresolved_interfaces": self._unresolved_interfaces,
544
552
  "_NOT_SET": NOT_SET,
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "anydi"
3
- version = "0.55.0"
3
+ version = "0.55.1"
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