python-injection 0.18.13__py3-none-any.whl → 0.18.14__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.
injection/__init__.pyi CHANGED
@@ -115,7 +115,7 @@ class Module:
115
115
  parameter type annotations. If applied to a class, the dependencies resolved
116
116
  will be those of the `__init__` method.
117
117
 
118
- With `threadsafe=True`, the injection logic is wrapped in a `threading.Lock`.
118
+ With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
119
119
  """
120
120
 
121
121
  def injectable[**P, T](
@@ -171,18 +171,18 @@ class Module:
171
171
  registered.
172
172
  """
173
173
 
174
- def constant[T](
174
+ def constant[**P, T](
175
175
  self,
176
- wrapped: type[T] = ...,
176
+ wrapped: _Recipe[P, T] = ...,
177
177
  /,
178
178
  *,
179
179
  on: _TypeInfo[T] = ...,
180
180
  mode: Mode | ModeStr = ...,
181
181
  ) -> Any:
182
182
  """
183
- Decorator applicable to a class. It is used to indicate how the constant is
184
- constructed. At injection time, the injected instance will always be the same.
185
- Unlike `@singleton`, dependencies will not be resolved.
183
+ Decorator applicable to a class or function. It is used to indicate how the
184
+ constant is constructed. At injection time, the injected instance will always
185
+ be the same. Unlike `@singleton`, dependencies will not be resolved.
186
186
  """
187
187
 
188
188
  def set_constant[T](
injection/_core/module.py CHANGED
@@ -503,15 +503,15 @@ class Module(Broker, EventListener):
503
503
 
504
504
  return decorator(wrapped) if wrapped else decorator
505
505
 
506
- def constant[T](
506
+ def constant[**P, T](
507
507
  self,
508
- wrapped: type[T] | None = None,
508
+ wrapped: Recipe[P, T] | None = None,
509
509
  /,
510
510
  *,
511
511
  on: TypeInfo[T] = (),
512
512
  mode: Mode | ModeStr = Mode.get_default(),
513
513
  ) -> Any:
514
- def decorator(wp: type[T]) -> type[T]:
514
+ def decorator(wp: Recipe[P, T]) -> Recipe[P, T]:
515
515
  lazy_instance = lazy(wp)
516
516
  self.injectable(
517
517
  lambda: ~lazy_instance,
@@ -1087,7 +1087,7 @@ class InjectMetadata[**P, T](Caller[P, T], EventListener):
1087
1087
  return decorator(wrapped) if wrapped else decorator
1088
1088
 
1089
1089
  @singledispatchmethod
1090
- def on_event(self, event: Event, /) -> ContextManager[None] | None: # type: ignore[override]
1090
+ def on_event(self, event: Event, /) -> ContextManager[None] | None:
1091
1091
  return None
1092
1092
 
1093
1093
  @on_event.register
injection/loaders.py CHANGED
@@ -164,8 +164,11 @@ class ProfileLoader:
164
164
 
165
165
  def load(self, name: str, /) -> LoadedProfile:
166
166
  self.init()
167
- target_module = self.__init_subsets_for(mod(name))
168
- self.module.use(target_module, priority=Priority.HIGH)
167
+
168
+ if not self.__is_default_module(name):
169
+ target_module = self.__init_subsets_for(mod(name))
170
+ self.module.use(target_module, priority=Priority.HIGH)
171
+
169
172
  return _UserLoadedProfile(self, name)
170
173
 
171
174
  def _unload(self, name: str, /) -> None:
@@ -182,6 +185,9 @@ class ProfileLoader:
182
185
 
183
186
  return module
184
187
 
188
+ def __is_default_module(self, module_name: str) -> bool:
189
+ return module_name == self.module.name
190
+
185
191
  def __is_initialized(self, module: Module) -> bool:
186
192
  return module.name in self.__initialized_modules
187
193
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.18.13
3
+ Version: 0.18.14
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -14,6 +14,8 @@ Classifier: Operating System :: OS Independent
14
14
  Classifier: Programming Language :: Python
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
17
19
  Classifier: Topic :: Software Development :: Libraries
18
20
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
21
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -27,11 +29,10 @@ Description-Content-Type: text/markdown
27
29
  # python-injection
28
30
 
29
31
  [![CI](https://github.com/100nm/python-injection/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-injection)
30
- [![PyPI](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection)
32
+ [![PyPI - Version](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection)
33
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/python-injection.svg?color=blue)](https://pypistats.org/packages/python-injection)
31
34
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
32
35
 
33
- Fast and easy dependency injection framework.
34
-
35
36
  ## Installation
36
37
 
37
38
  ⚠️ _Requires Python 3.12 or higher_
@@ -40,12 +41,22 @@ Fast and easy dependency injection framework.
40
41
  pip install python-injection
41
42
  ```
42
43
 
44
+ ## Features
45
+
46
+ * Automatic dependency resolution based on type hints.
47
+ * Support for multiple dependency lifetimes: `transient`, `singleton`, `constant`, and `scoped`.
48
+ * Works seamlessly in both `async` and `sync` environments.
49
+ * Separation of dependency sets using modules.
50
+ * Runtime switching between different sets of dependencies.
51
+ * Centralized setup logic using entrypoints.
52
+ * Built-in type annotation for easy integration with [`FastAPI`](https://github.com/fastapi/fastapi).
53
+ * Lazy dependency resolution for optimized performance.
54
+
43
55
  ## Motivations
44
56
 
45
57
  1. Easy to use
46
58
  2. No impact on class and function definitions
47
- 3. Easily interchangeable dependencies _(depending on the runtime environment, for example)_
48
- 4. No prerequisites
59
+ 3. No tedious configuration
49
60
 
50
61
  ## Quick start
51
62
 
@@ -90,5 +101,6 @@ if __name__ == "__main__":
90
101
  * [**Advanced usage**](https://github.com/100nm/python-injection/tree/prod/documentation/advanced-usage.md)
91
102
  * [**Loaders**](https://github.com/100nm/python-injection/tree/prod/documentation/loaders.md)
92
103
  * [**Entrypoint**](https://github.com/100nm/python-injection/tree/prod/documentation/entrypoint.md)
93
- * [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations.md)
104
+ * [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations)
105
+ * [**FastAPI**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations/fastapi.md)
94
106
  * [**Concrete example**](https://github.com/100nm/python-injection-example)
@@ -1,13 +1,13 @@
1
1
  injection/__init__.py,sha256=7ZRUlO5EEPWO7IlbYHD-8DOX-cg4Np4nYq5fpw-U56o,1259
2
- injection/__init__.pyi,sha256=65zhAK9LhuUXhftk7YDq2JJZ2zlPtNQ6UfrXaKcQgcA,10940
2
+ injection/__init__.pyi,sha256=94F3A7lPmEyaJtsetVQpmS33LiY-BpymOLcFA6xvFBk,10964
3
3
  injection/entrypoint.py,sha256=12b0_zHAFxHCerAoJTIHkhqi3mLkgheECYAaCUZv_DU,4751
4
4
  injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
5
- injection/loaders.py,sha256=EWnbcFdiHJBIALm1foHpPi5clZiAHpVstgKXV0dofiw,7091
5
+ injection/loaders.py,sha256=gKlJfe9nXCuB8r6j0RF9_2FHC6YplM8GQYsgRqyxYw8,7257
6
6
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  injection/_core/descriptors.py,sha256=RRng9lx-ET6An1d_244rAv4iLUTQUGvDh1ugLfImuW8,794
9
9
  injection/_core/injectables.py,sha256=Rg1nxDkbcpeX4ELohrNVMguPhN36SNQuD0JKfyfL6bI,6192
10
- injection/_core/module.py,sha256=aSUHKLFJ63yx6FgJ6AKpDccaZ-H1YpKQyoaKxb4YXfk,32414
10
+ injection/_core/module.py,sha256=lQFhfc9vDCiENkMvgkCzc-wW50uEl2bjKKBfRlR6nv8,32408
11
11
  injection/_core/scope.py,sha256=NY6YWcIIXqBKTjXVsqsahxbw-bPJiL0CwHp6CyjBGJo,8753
12
12
  injection/_core/slots.py,sha256=g9TG6CbqRzCsjg01iPyfRtTTUCJnnJOwcj9mJabH0dc,37
13
13
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -23,7 +23,7 @@ injection/ext/fastapi.py,sha256=YdCVO1WgZRhv0CFrDnIdsbeRprtcHb-snIL4B4mpLnk,1388
23
23
  injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
24
24
  injection/testing/__init__.py,sha256=bJ7WXBXrw4rHc91AFVFnOwFLWOlpvX9Oh2SnRQ_NESo,919
25
25
  injection/testing/__init__.pyi,sha256=raGsGlxwbz3jkzJwA_5oCIE1emWINjT2UuwzbnqRb-0,577
26
- python_injection-0.18.13.dist-info/METADATA,sha256=O90MunVYtSYyTrFbbDrdhDFKfbp5i9rPsUdnal4jxGs,3398
27
- python_injection-0.18.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
- python_injection-0.18.13.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
29
- python_injection-0.18.13.dist-info/RECORD,,
26
+ python_injection-0.18.14.dist-info/METADATA,sha256=jtUZE1HuKfARdckxvXvKbw-xSnBuLEq0KTi5gmZZx2c,4155
27
+ python_injection-0.18.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
+ python_injection-0.18.14.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
29
+ python_injection-0.18.14.dist-info/RECORD,,