anydi 0.36.1a4__py3-none-any.whl → 0.37.0__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/_container.py CHANGED
@@ -556,7 +556,7 @@ class Container:
556
556
  return context.enter(cm)
557
557
 
558
558
  instance = provider.call(**provider_kwargs)
559
- if context is not None and is_context_manager(instance):
559
+ if context is not None and provider.is_class and is_context_manager(instance):
560
560
  context.enter(instance)
561
561
  return instance
562
562
 
@@ -569,10 +569,7 @@ class Container:
569
569
  )
570
570
 
571
571
  if provider.is_coroutine:
572
- instance = await provider.call(**provider_kwargs)
573
- if context is not None and is_async_context_manager(instance):
574
- await context.aenter(instance)
575
- return instance
572
+ return await provider.call(**provider_kwargs)
576
573
 
577
574
  if provider.is_async_generator:
578
575
  if context is None:
@@ -593,7 +590,11 @@ class Container:
593
590
  return await run_async(_create)
594
591
 
595
592
  instance = await run_async(provider.call, **provider_kwargs)
596
- if context is not None and is_async_context_manager(instance):
593
+ if (
594
+ context is not None
595
+ and provider.is_class
596
+ and is_async_context_manager(instance)
597
+ ):
597
598
  await context.aenter(instance)
598
599
  return instance
599
600
 
@@ -787,6 +788,10 @@ class Container:
787
788
  """
788
789
  Override the provider for the specified interface with a specific instance.
789
790
  """
791
+ if not self.testing:
792
+ raise RuntimeError(
793
+ "The `override` method can only be used in testing mode."
794
+ )
790
795
  if not self.is_registered(interface) and self.strict:
791
796
  raise LookupError(
792
797
  f"The provider interface `{get_full_qualname(interface)}` "
anydi/_provider.py CHANGED
@@ -38,6 +38,7 @@ class Provider:
38
38
  "_kind",
39
39
  "_interface",
40
40
  "_parameters",
41
+ "_is_class",
41
42
  "_is_coroutine",
42
43
  "_is_generator",
43
44
  "_is_async_generator",
@@ -57,6 +58,7 @@ class Provider:
57
58
  # Detect the kind of callable provider
58
59
  self._detect_kind()
59
60
 
61
+ self._is_class = self._kind == CallableKind.CLASS
60
62
  self._is_coroutine = self._kind == CallableKind.COROUTINE
61
63
  self._is_generator = self._kind == CallableKind.GENERATOR
62
64
  self._is_async_generator = self._kind == CallableKind.ASYNC_GENERATOR
@@ -107,6 +109,11 @@ class Provider:
107
109
  def parameters(self) -> list[inspect.Parameter]:
108
110
  return self._parameters
109
111
 
112
+ @property
113
+ def is_class(self) -> bool:
114
+ """Check if the provider is a class."""
115
+ return self._is_class
116
+
110
117
  @property
111
118
  def is_coroutine(self) -> bool:
112
119
  """Check if the provider is a coroutine."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.36.1a4
3
+ Version: 0.37.0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  anydi/__init__.py,sha256=OfRg2EfXD65pHTGQKhfkABMwUhw5LvsuTQV_Tv4V4wk,501
2
- anydi/_container.py,sha256=LSa1IMR8JeAtA5im9EWU8NOKqSCDjKmxXRt9mVXPAf4,38251
2
+ anydi/_container.py,sha256=-hk-6rzRZeMdxnVFqPkEehTlk0yF2DYjm1n1wGHsTLY,38338
3
3
  anydi/_context.py,sha256=7LV_SL4QWkJeiG7_4D9PZ5lmU-MPzhofxC95zCgY9Gc,2651
4
- anydi/_provider.py,sha256=W42y8wbsnWbb9B9gI-pnEa-lsz68nK0VIm55CJW3pWg,7457
4
+ anydi/_provider.py,sha256=1IyxHO83NHjsPDHLDIZtW1pJ7i8VpWD3EM4T6duw9zA,7661
5
5
  anydi/_types.py,sha256=Vttj9GTp9g0KKpK-uqolLfVZJPIM7f7_YL8bPlablcQ,1539
6
6
  anydi/_utils.py,sha256=INI0jNIXrJ6LS4zqJymMO2yUEobpxmBGASf4G_vR6AU,4378
7
7
  anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -22,8 +22,8 @@ anydi/ext/pytest_plugin.py,sha256=ShGhiZnP1KyMHhnc9Ci1RKAuHVhw628OTS2P2BLEOfc,50
22
22
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  anydi/ext/starlette/middleware.py,sha256=9CQtGg5ZzUz2gFSzJr8U4BWzwNjK8XMctm3n52M77Z0,792
24
24
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- anydi-0.36.1a4.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
- anydi-0.36.1a4.dist-info/METADATA,sha256=cDcue6lJu_2S7GNsR8ryi_C_lAti0rSKuXZebraSXRA,5066
27
- anydi-0.36.1a4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
- anydi-0.36.1a4.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
- anydi-0.36.1a4.dist-info/RECORD,,
25
+ anydi-0.37.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
+ anydi-0.37.0.dist-info/METADATA,sha256=kBDlCMavWC9DuKj2TnoeZroVJZg7DCdWzKzvAMkEkkk,5064
27
+ anydi-0.37.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
+ anydi-0.37.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
+ anydi-0.37.0.dist-info/RECORD,,