anydi 0.37.1__py3-none-any.whl → 0.37.3__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
@@ -86,11 +86,13 @@ class Container:
86
86
  modules: Sequence[Module | type[Module] | Callable[[Container], None] | str]
87
87
  | None = None,
88
88
  strict: bool = False,
89
+ default_scope: Scope = "transient",
89
90
  testing: bool = False,
90
91
  logger: logging.Logger | None = None,
91
92
  ) -> None:
92
93
  self._providers: dict[type[Any], Provider] = {}
93
94
  self._strict = strict
95
+ self._default_scope = default_scope
94
96
  self._testing = testing
95
97
  self._logger = logger or logging.getLogger(__name__)
96
98
  self._resources: dict[str, list[type[Any]]] = defaultdict(list)
@@ -121,6 +123,11 @@ class Container:
121
123
  """Check if strict mode is enabled."""
122
124
  return self._strict
123
125
 
126
+ @property
127
+ def default_scope(self) -> Scope:
128
+ """Get the default scope."""
129
+ return self._default_scope
130
+
124
131
  @property
125
132
  def testing(self) -> bool:
126
133
  """Check if testing mode is enabled."""
@@ -221,7 +228,7 @@ class Container:
221
228
  # Try to detect scope
222
229
  if scope is None:
223
230
  scope = self._detect_scope(interface, **defaults)
224
- scope = scope or "transient"
231
+ scope = scope or self.default_scope
225
232
  provider = Provider(call=interface, scope=scope, interface=interface)
226
233
  return self._register_provider(provider, False, **defaults)
227
234
  raise
@@ -622,7 +629,7 @@ class Container:
622
629
 
623
630
  # Try to get instance from defaults
624
631
  if parameter.name in defaults:
625
- instance = defaults[parameter.name]
632
+ return defaults[parameter.name]
626
633
 
627
634
  # Try to get instance from context
628
635
  elif context and parameter.annotation in context:
@@ -635,7 +642,7 @@ class Container:
635
642
  except LookupError:
636
643
  if parameter.default is inspect.Parameter.empty:
637
644
  raise
638
- instance = parameter.default
645
+ return parameter.default
639
646
 
640
647
  # Wrap the instance in a proxy for testing
641
648
  if self.testing:
@@ -666,7 +673,7 @@ class Container:
666
673
 
667
674
  # Try to get instance from defaults
668
675
  if parameter.name in defaults:
669
- instance = defaults[parameter.name]
676
+ return defaults[parameter.name]
670
677
 
671
678
  # Try to get instance from context
672
679
  elif context and parameter.annotation in context:
@@ -679,7 +686,7 @@ class Container:
679
686
  except LookupError:
680
687
  if parameter.default is inspect.Parameter.empty:
681
688
  raise
682
- instance = parameter.default
689
+ return parameter.default
683
690
 
684
691
  # Wrap the instance in a proxy for testing
685
692
  if self.testing:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.37.1
3
+ Version: 0.37.3
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
1
  anydi/__init__.py,sha256=OfRg2EfXD65pHTGQKhfkABMwUhw5LvsuTQV_Tv4V4wk,501
2
- anydi/_container.py,sha256=6dr2sOSkx8GRdqzlokHB5McfBNOWp_9ozyyiS5dpxoE,38320
2
+ anydi/_container.py,sha256=yH1DsSQFkbfxGaDFs47nr-iXLE_Wwgv6QMTGWrRb8cE,38524
3
3
  anydi/_context.py,sha256=7LV_SL4QWkJeiG7_4D9PZ5lmU-MPzhofxC95zCgY9Gc,2651
4
4
  anydi/_provider.py,sha256=1IyxHO83NHjsPDHLDIZtW1pJ7i8VpWD3EM4T6duw9zA,7661
5
5
  anydi/_types.py,sha256=fdO4xNXtGMxVArmlfDkFYbyR895ixkBTW6V8lMceN7Q,1562
@@ -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.37.1.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
- anydi-0.37.1.dist-info/METADATA,sha256=9pkB0M7YtPuvIXxskF0h7roe7FY_R90rHZ6772w2LSI,5103
27
- anydi-0.37.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
- anydi-0.37.1.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
- anydi-0.37.1.dist-info/RECORD,,
25
+ anydi-0.37.3.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
+ anydi-0.37.3.dist-info/METADATA,sha256=8QjGkBnTAht-DDMytibrHIM_kSnm3bQSUiDt8IUW2pc,5103
27
+ anydi-0.37.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
+ anydi-0.37.3.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
+ anydi-0.37.3.dist-info/RECORD,,
File without changes