python-injection 0.14.0__py3-none-any.whl → 0.14.0.post0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
injection/__init__.pyi CHANGED
@@ -281,7 +281,7 @@ class Module:
281
281
  module: Module,
282
282
  *,
283
283
  priority: Priority | PriorityStr = ...,
284
- ) -> Iterator[None]:
284
+ ) -> Iterator[Self]:
285
285
  """
286
286
  Context manager or decorator for temporary use of a module.
287
287
  """
@@ -305,7 +305,7 @@ class Module:
305
305
  """
306
306
 
307
307
  @contextmanager
308
- def load_profile(self, *names: str) -> Iterator[None]: ...
308
+ def load_profile(self, *names: str) -> Iterator[Self]: ...
309
309
  async def all_ready(self) -> None: ...
310
310
  def add_logger(self, logger: Logger) -> Self: ...
311
311
  @classmethod
injection/_core/hook.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import itertools
2
+ from collections import deque
2
3
  from collections.abc import Callable, Generator, Iterator
3
4
  from dataclasses import dataclass, field
4
5
  from inspect import isclass, isgeneratorfunction
@@ -13,8 +14,8 @@ type HookFunction[**P, T] = Callable[P, T] | HookGeneratorFunction[P, T]
13
14
 
14
15
  @dataclass(eq=False, frozen=True, slots=True)
15
16
  class Hook[**P, T]:
16
- __functions: list[HookFunction[P, T]] = field(
17
- default_factory=list,
17
+ __functions: deque[HookFunction[P, T]] = field(
18
+ default_factory=deque,
18
19
  init=False,
19
20
  repr=False,
20
21
  )
@@ -35,7 +36,7 @@ class Hook[**P, T]:
35
36
  return iter(self.__functions)
36
37
 
37
38
  def add(self, *functions: HookFunction[P, T]) -> Self:
38
- self.__functions.extend(reversed(functions))
39
+ self.__functions.extendleft(functions)
39
40
  return self
40
41
 
41
42
  @classmethod
injection/_core/module.py CHANGED
@@ -739,11 +739,11 @@ class Module(Broker, EventListener):
739
739
  module: Module,
740
740
  *,
741
741
  priority: Priority | PriorityStr = Priority.get_default(),
742
- ) -> Iterator[None]:
742
+ ) -> Iterator[Self]:
743
743
  self.use(module, priority=priority)
744
744
 
745
745
  try:
746
- yield
746
+ yield self
747
747
  finally:
748
748
  self.stop_using(module)
749
749
 
@@ -762,7 +762,7 @@ class Module(Broker, EventListener):
762
762
 
763
763
  return self
764
764
 
765
- def load_profile(self, *names: str) -> ContextManager[None]:
765
+ def load_profile(self, *names: str) -> ContextManager[Self]:
766
766
  modules = tuple(self.from_name(name) for name in names)
767
767
 
768
768
  for module in modules:
@@ -773,8 +773,8 @@ class Module(Broker, EventListener):
773
773
  del module, modules
774
774
 
775
775
  @contextmanager
776
- def cleaner() -> Iterator[None]:
777
- yield
776
+ def cleaner() -> Iterator[Self]:
777
+ yield self
778
778
  self.unlock().init_modules()
779
779
 
780
780
  return cleaner()
injection/_core/scope.py CHANGED
@@ -121,11 +121,8 @@ def _bind_scope(name: str, scope: Scope, shared: bool) -> Iterator[None]:
121
121
  f"Scope `{name}` is already defined in the current context."
122
122
  )
123
123
 
124
- strategy = (
125
- state.bind_shared_scope(scope) if shared else state.bind_contextual_scope(scope)
126
- )
127
-
128
- with strategy:
124
+ strategy = state.bind_shared_scope if shared else state.bind_contextual_scope
125
+ with strategy(scope):
129
126
  yield
130
127
 
131
128
 
@@ -1,6 +1,6 @@
1
1
  from typing import ContextManager, Final
2
2
 
3
- from injection import mod
3
+ from injection import Module, mod
4
4
  from injection.utils import load_profile
5
5
 
6
6
  __all__ = (
@@ -23,5 +23,5 @@ test_scoped = mod(_TEST_PROFILE_NAME).scoped
23
23
  test_singleton = mod(_TEST_PROFILE_NAME).singleton
24
24
 
25
25
 
26
- def load_test_profile(*names: str) -> ContextManager[None]:
26
+ def load_test_profile(*names: str) -> ContextManager[Module]:
27
27
  return load_profile(_TEST_PROFILE_NAME, *names)
@@ -11,7 +11,7 @@ test_injectable = __MODULE.injectable
11
11
  test_scoped = __MODULE.scoped
12
12
  test_singleton = __MODULE.singleton
13
13
 
14
- def load_test_profile(*names: str) -> ContextManager[None]:
14
+ def load_test_profile(*names: str) -> ContextManager[Module]:
15
15
  """
16
16
  Context manager or decorator for temporary use test module.
17
17
  """
injection/utils.py CHANGED
@@ -5,13 +5,13 @@ from pkgutil import walk_packages
5
5
  from types import ModuleType as PythonModule
6
6
  from typing import ContextManager
7
7
 
8
+ from injection import Module, mod
8
9
  from injection import __name__ as injection_package_name
9
- from injection import mod
10
10
 
11
11
  __all__ = ("load_modules_with_keywords", "load_packages", "load_profile")
12
12
 
13
13
 
14
- def load_profile(*names: str) -> ContextManager[None]:
14
+ def load_profile(*names: str) -> ContextManager[Module]:
15
15
  """
16
16
  Injection module initialization function based on profile name.
17
17
  A profile name is equivalent to an injection module name.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.14.0
3
+ Version: 0.14.0.post0
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -78,6 +78,9 @@ if __name__ == "__main__":
78
78
 
79
79
  ## Resources
80
80
 
81
+ > ⚠️ The package isn't threadsafe, for better performance in single-threaded applications and those using `asyncio`.
82
+ > So remember to use `threading.Lock` if you're writing a multithreaded program.
83
+
81
84
  * [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)
82
85
  * [**Scoped dependencies**](https://github.com/100nm/python-injection/tree/prod/documentation/scoped-dependencies.md)
83
86
  * [**Testing**](https://github.com/100nm/python-injection/tree/prod/documentation/testing.md)
@@ -1,14 +1,14 @@
1
1
  injection/__init__.py,sha256=X0vIAoN4MDlhR7YIkup1qHgqbOkwZ3PWgdSi7h-udaM,1049
2
- injection/__init__.pyi,sha256=f3EhwOaJCnf37YZQdANvbUsAq360zn-62zFLNLJxvoQ,9916
2
+ injection/__init__.pyi,sha256=T95sTJol0Tmzlajb5rqJd020CBMYrHXvFDPUmbazD8I,9916
3
3
  injection/exceptions.py,sha256=T__732aXxWWUz0sKc39ySteyolCS5tpqQC0oCnzUF2E,917
4
4
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- injection/utils.py,sha256=s4wwe98owmgVIkxzAg-mu9yvFISWOzz1AvF7eF7-2xY,2752
5
+ injection/utils.py,sha256=Lr0qHaq3_1AkUoAaw2XmMNie_alwYTeTrRlO22FeCnk,2762
6
6
  injection/_core/__init__.py,sha256=XERocCxCZBxPGIaOR37yeiQOZyvjHQ6a4rgRmlkUSuU,1367
7
7
  injection/_core/descriptors.py,sha256=7fSHlgAqmgR_Uta8KocBapOt1Xyj2dI7RY9ZdoStTzw,726
8
- injection/_core/hook.py,sha256=Qv505pr3kjOE6UitftlLh9JKX9OCNqZBRtHbFha1gqM,3130
8
+ injection/_core/hook.py,sha256=bXTMd3NiltV2yEweSJWOjNybKQwX_L7N4oE1v24BQK8,3156
9
9
  injection/_core/injectables.py,sha256=GIumNp0TXf8Voxe1sCPhcqq2gyw4E_hl7I45IJ_tyHE,4512
10
- injection/_core/module.py,sha256=kotXKuOFv8Gt31J1R8nSgVnu-83_MhIV4B5Etu8_kzo,30968
11
- injection/_core/scope.py,sha256=uZps_kQsXDL9tXRzF1ECK8ua3cdEXiIAxrrhPt8JNqg,5461
10
+ injection/_core/module.py,sha256=xd55CGCpDjNc9ZW_iwVLpejgKIAJaRTVK860ZqmIPGY,30978
11
+ injection/_core/scope.py,sha256=pwOqVKOUM_ZteNScgp-hLqyOHg5Ew75jWlfWLLD2PU8,5437
12
12
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  injection/_core/common/asynchronous.py,sha256=9bQDVRE6eqo9K0d5H9RzyFalf0WGoGP7cDrKDGbvZPI,1500
14
14
  injection/_core/common/event.py,sha256=XjzV8gxtGlGvzZs_ykvoC60qmdpd3RN08Eiqz5QUwes,1236
@@ -18,8 +18,8 @@ injection/_core/common/lazy.py,sha256=6xh5h0lmaNvl32V0WoX4VCTsNJ3zUJdWVqpLJ_YeII
18
18
  injection/_core/common/type.py,sha256=QbBBhJp7i1p6gLzWX0TgofvfG7yDH-gHfEQcssVZeHo,2186
19
19
  injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  injection/integrations/fastapi.py,sha256=YHSs85_3m6TUVtOwUcV157b3UZJQIw_aXWAg199a-YE,594
21
- injection/testing/__init__.py,sha256=ALcKuDYNdslmpgqotZzSWrXAW0kNNFUs9nzfO1ZgIGc,783
22
- injection/testing/__init__.pyi,sha256=6rv5NOYHEaiKMd82E1IIc8lFlLV9ttY57DLiMqGTXt8,482
23
- python_injection-0.14.0.dist-info/METADATA,sha256=A25sC1rCj-HHSw-Sf57IIyHLhiPuDXUt53BdLBpKPnY,2996
24
- python_injection-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
- python_injection-0.14.0.dist-info/RECORD,,
21
+ injection/testing/__init__.py,sha256=Bh3JqEXw62-JnUnspOXr2jpjGXZJ_K_K9CgfD7dPZeQ,793
22
+ injection/testing/__init__.pyi,sha256=1h9zNGghxlo4D1jAx5s8EHk54mn7o-qO7WgJa6hwX6U,484
23
+ python_injection-0.14.0.post0.dist-info/METADATA,sha256=AfarVqsSo7GAgTtjjhEUG2xFoincSsfvLOfGDwf9ZDs,3205
24
+ python_injection-0.14.0.post0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ python_injection-0.14.0.post0.dist-info/RECORD,,