python-injection 0.9.3.post0__tar.gz → 0.9.4.post0__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.

Potentially problematic release.


This version of python-injection might be problematic. Click here for more details.

Files changed (22) hide show
  1. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/PKG-INFO +13 -2
  2. python_injection-0.9.4.post0/injection/__init__.py +36 -0
  3. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/__init__.pyi +15 -10
  4. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/tools/type.py +3 -4
  5. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/core/module.py +2 -2
  6. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/integrations/blacksheep.py +3 -3
  7. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/testing/__init__.py +9 -14
  8. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/testing/__init__.pyi +5 -8
  9. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/pyproject.toml +18 -4
  10. python_injection-0.9.3.post0/injection/__init__.py +0 -29
  11. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/documentation/basic-usage.md +0 -0
  12. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/__init__.py +0 -0
  13. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/event.py +0 -0
  14. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/invertible.py +0 -0
  15. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/lazy.py +0 -0
  16. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/tools/__init__.py +0 -0
  17. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/common/tools/threading.py +0 -0
  18. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/core/__init__.py +0 -0
  19. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/exceptions.py +0 -0
  20. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/integrations/__init__.py +0 -0
  21. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/py.typed +0 -0
  22. {python_injection-0.9.3.post0 → python_injection-0.9.4.post0}/injection/utils.py +0 -0
@@ -1,15 +1,26 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-injection
3
- Version: 0.9.3.post0
3
+ Version: 0.9.4.post0
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Home-page: https://github.com/100nm/python-injection
6
6
  License: MIT
7
- Keywords: dependencies,inject,injection
7
+ Keywords: dependencies,dependency,inject,injection
8
8
  Author: remimd
9
9
  Requires-Python: >=3.12,<4
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
10
12
  Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
11
16
  Classifier: Programming Language :: Python :: 3
12
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Software Development :: Testing
23
+ Classifier: Typing :: Typed
13
24
  Project-URL: Repository, https://github.com/100nm/python-injection
14
25
  Description-Content-Type: text/markdown
15
26
 
@@ -0,0 +1,36 @@
1
+ from .core import Injectable, Module
2
+ from .core import Mode as InjectableMode
3
+ from .core import Priority as ModulePriority
4
+
5
+ __all__ = (
6
+ "Injectable",
7
+ "InjectableMode",
8
+ "Module",
9
+ "ModulePriority",
10
+ "find_instance",
11
+ "get_instance",
12
+ "get_lazy_instance",
13
+ "inject",
14
+ "injectable",
15
+ "mod",
16
+ "set_constant",
17
+ "should_be_injectable",
18
+ "singleton",
19
+ )
20
+
21
+
22
+ def mod(name: str = None, /) -> Module:
23
+ if name is None:
24
+ return Module.default()
25
+
26
+ return Module.from_name(name)
27
+
28
+
29
+ find_instance = mod().find_instance
30
+ get_instance = mod().get_instance
31
+ get_lazy_instance = mod().get_lazy_instance
32
+ inject = mod().inject
33
+ injectable = mod().injectable
34
+ set_constant = mod().set_constant
35
+ should_be_injectable = mod().should_be_injectable
36
+ singleton = mod().singleton
@@ -19,18 +19,23 @@ from .core import InjectableFactory
19
19
  from .core import ModeStr as InjectableModeStr
20
20
  from .core import PriorityStr as ModulePriorityStr
21
21
 
22
- _module: Module = ...
22
+ _: Module = ...
23
23
 
24
- get_instance = _module.get_instance
25
- get_lazy_instance = _module.get_lazy_instance
26
- inject = _module.inject
27
- injectable = _module.injectable
28
- set_constant = _module.set_constant
29
- should_be_injectable = _module.should_be_injectable
30
- singleton = _module.singleton
24
+ find_instance = _.find_instance
25
+ get_instance = _.get_instance
26
+ get_lazy_instance = _.get_lazy_instance
27
+ inject = _.inject
28
+ injectable = _.injectable
29
+ set_constant = _.set_constant
30
+ should_be_injectable = _.should_be_injectable
31
+ singleton = _.singleton
31
32
 
32
- del _module
33
+ del _
33
34
 
35
+ def mod(name: str = ..., /) -> Module:
36
+ """
37
+ Short syntax for `Module.from_name`.
38
+ """
34
39
  @final
35
40
  class Module:
36
41
  """
@@ -103,7 +108,7 @@ class Module:
103
108
  that no dependencies are resolved, so the module doesn't need to be locked.
104
109
  """
105
110
 
106
- def resolve[T](self, cls: type[T]) -> T:
111
+ def find_instance[T](self, cls: type[T]) -> T:
107
112
  """
108
113
  Function used to retrieve an instance associated with the type passed in
109
114
  parameter or an exception will be raised.
@@ -59,10 +59,9 @@ def analyze_types(*types: type | Any) -> Iterator[TypeReport[Any]]:
59
59
 
60
60
  def get_return_types(*args: TypeInfo[Any]) -> Iterator[type | UnionType]:
61
61
  for arg in args:
62
- if isinstance(arg, Iterable) and not isinstance(
63
- get_origin(arg) or arg,
64
- type | str,
65
- ):
62
+ origin = get_origin(arg) or arg
63
+
64
+ if isinstance(origin, Iterable) and not isinstance(origin, type | str):
66
65
  inner_args = arg
67
66
 
68
67
  elif isfunction(arg):
@@ -488,13 +488,13 @@ class Module(EventListener, Broker):
488
488
 
489
489
  return decorator(wrapped) if wrapped else decorator
490
490
 
491
- def resolve[T](self, cls: type[T]) -> T:
491
+ def find_instance[T](self, cls: type[T]) -> T:
492
492
  injectable = self[cls]
493
493
  return injectable.get_instance()
494
494
 
495
495
  def get_instance[T](self, cls: type[T]) -> T | None:
496
496
  try:
497
- return self.resolve(cls)
497
+ return self.find_instance(cls)
498
498
  except KeyError:
499
499
  return None
500
500
 
@@ -2,7 +2,7 @@ from typing import Any
2
2
 
3
3
  from rodi import ContainerProtocol
4
4
 
5
- from injection import Module
5
+ from injection import Module, mod
6
6
 
7
7
  __all__ = ("InjectionServices",)
8
8
 
@@ -15,7 +15,7 @@ class InjectionServices(ContainerProtocol):
15
15
  __slots__ = ("__module",)
16
16
 
17
17
  def __init__(self, module: Module = None):
18
- self.__module = module or Module.default()
18
+ self.__module = module or mod()
19
19
 
20
20
  def __contains__(self, item: Any) -> bool:
21
21
  return item in self.__module
@@ -25,4 +25,4 @@ class InjectionServices(ContainerProtocol):
25
25
  return self
26
26
 
27
27
  def resolve[T](self, obj_type: type[T] | Any, *args, **kwargs) -> T:
28
- return self.__module.resolve(obj_type)
28
+ return self.__module.find_instance(obj_type)
@@ -1,6 +1,7 @@
1
1
  from contextlib import contextmanager
2
+ from functools import partial
2
3
 
3
- from injection import Module, ModulePriority
4
+ from injection import Module, ModulePriority, mod
4
5
 
5
6
  __all__ = (
6
7
  "set_test_constant",
@@ -11,24 +12,18 @@ __all__ = (
11
12
  )
12
13
 
13
14
 
14
- def get_test_module() -> Module:
15
- return Module.from_name("testing")
15
+ testing_mod = partial(mod, "testing")
16
16
 
17
-
18
- _module = get_test_module()
19
-
20
- set_test_constant = _module.set_constant
21
- should_be_test_injectable = _module.should_be_injectable
22
- test_injectable = _module.injectable
23
- test_singleton = _module.singleton
24
-
25
- del _module
17
+ set_test_constant = testing_mod().set_constant
18
+ should_be_test_injectable = testing_mod().should_be_injectable
19
+ test_injectable = testing_mod().injectable
20
+ test_singleton = testing_mod().singleton
26
21
 
27
22
 
28
23
  @contextmanager
29
24
  def use_test_injectables(*, on: Module = None, test_module: Module = None):
30
- on = on or Module.default()
31
- test_module = test_module or get_test_module()
25
+ on = on or mod()
26
+ test_module = test_module or testing_mod()
32
27
 
33
28
  for module in (on, test_module):
34
29
  module.unlock()
@@ -1,16 +1,13 @@
1
1
  from contextlib import ContextDecorator
2
2
  from typing import ContextManager
3
3
 
4
+ import injection as _
4
5
  from injection import Module
5
6
 
6
- _module: Module = ...
7
-
8
- set_test_constant = _module.set_constant
9
- should_be_test_injectable = _module.should_be_injectable
10
- test_injectable = _module.injectable
11
- test_singleton = _module.singleton
12
-
13
- del _module
7
+ set_test_constant = _.set_constant
8
+ should_be_test_injectable = _.should_be_injectable
9
+ test_injectable = _.injectable
10
+ test_singleton = _.singleton
14
11
 
15
12
  def use_test_injectables(
16
13
  *,
@@ -1,13 +1,27 @@
1
1
  [tool.poetry]
2
2
  name = "python-injection"
3
- version = "0.9.3.post0"
3
+ version = "0.9.4.post0"
4
4
  description = "Fast and easy dependency injection framework."
5
- authors = ["remimd"]
6
- keywords = ["dependencies", "inject", "injection"]
7
5
  license = "MIT"
8
- packages = [{ include = "injection" }]
6
+ authors = ["remimd"]
9
7
  readme = "documentation/basic-usage.md"
10
8
  repository = "https://github.com/100nm/python-injection"
9
+ keywords = ["dependencies", "dependency", "inject", "injection"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Topic :: Software Development :: Libraries",
13
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
14
+ "Topic :: Software Development :: Libraries :: Python Modules",
15
+ "Topic :: Software Development :: Testing",
16
+ "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Operating System :: OS Independent",
20
+ "Intended Audience :: Developers",
21
+ "Natural Language :: English",
22
+ "Typing :: Typed",
23
+ ]
24
+ packages = [{ include = "injection" }]
11
25
 
12
26
  [tool.poetry.dependencies]
13
27
  python = ">=3.12, <4"
@@ -1,29 +0,0 @@
1
- from .core import Injectable, Module
2
- from .core import Mode as InjectableMode
3
- from .core import Priority as ModulePriority
4
-
5
- __all__ = (
6
- "Injectable",
7
- "InjectableMode",
8
- "Module",
9
- "ModulePriority",
10
- "get_instance",
11
- "get_lazy_instance",
12
- "inject",
13
- "injectable",
14
- "set_constant",
15
- "should_be_injectable",
16
- "singleton",
17
- )
18
-
19
- _module = Module.default()
20
-
21
- get_instance = _module.get_instance
22
- get_lazy_instance = _module.get_lazy_instance
23
- inject = _module.inject
24
- injectable = _module.injectable
25
- set_constant = _module.set_constant
26
- should_be_injectable = _module.should_be_injectable
27
- singleton = _module.singleton
28
-
29
- del _module