python-injection 0.20.0__tar.gz → 0.21.1__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.
Files changed (31) hide show
  1. {python_injection-0.20.0 → python_injection-0.21.1}/PKG-INFO +1 -1
  2. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/asfunction.py +6 -16
  3. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/type.py +2 -2
  4. {python_injection-0.20.0 → python_injection-0.21.1}/pyproject.toml +1 -1
  5. {python_injection-0.20.0 → python_injection-0.21.1}/.gitignore +0 -0
  6. {python_injection-0.20.0 → python_injection-0.21.1}/LICENSE +0 -0
  7. {python_injection-0.20.0 → python_injection-0.21.1}/README.md +0 -0
  8. {python_injection-0.20.0 → python_injection-0.21.1}/injection/__init__.py +0 -0
  9. {python_injection-0.20.0 → python_injection-0.21.1}/injection/__init__.pyi +0 -0
  10. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/__init__.py +0 -0
  11. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/__init__.py +0 -0
  12. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/asynchronous.py +0 -0
  13. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/event.py +0 -0
  14. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/invertible.py +0 -0
  15. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/key.py +0 -0
  16. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/lazy.py +0 -0
  17. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/common/threading.py +0 -0
  18. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/descriptors.py +0 -0
  19. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/injectables.py +0 -0
  20. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/module.py +0 -0
  21. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/scope.py +0 -0
  22. {python_injection-0.20.0 → python_injection-0.21.1}/injection/_core/slots.py +0 -0
  23. {python_injection-0.20.0 → python_injection-0.21.1}/injection/entrypoint.py +0 -0
  24. {python_injection-0.20.0 → python_injection-0.21.1}/injection/exceptions.py +0 -0
  25. {python_injection-0.20.0 → python_injection-0.21.1}/injection/ext/__init__.py +0 -0
  26. {python_injection-0.20.0 → python_injection-0.21.1}/injection/ext/fastapi.py +0 -0
  27. {python_injection-0.20.0 → python_injection-0.21.1}/injection/ext/fastapi.pyi +0 -0
  28. {python_injection-0.20.0 → python_injection-0.21.1}/injection/loaders.py +0 -0
  29. {python_injection-0.20.0 → python_injection-0.21.1}/injection/py.typed +0 -0
  30. {python_injection-0.20.0 → python_injection-0.21.1}/injection/testing/__init__.py +0 -0
  31. {python_injection-0.20.0 → python_injection-0.21.1}/injection/testing/__init__.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.20.0
3
+ Version: 0.21.1
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -1,22 +1,12 @@
1
- from abc import abstractmethod
2
1
  from collections.abc import Callable
3
2
  from functools import wraps
4
3
  from inspect import iscoroutinefunction
5
- from typing import Any, Protocol, runtime_checkable
4
+ from typing import Any
6
5
 
7
6
  from injection._core.common.asynchronous import Caller
8
7
  from injection._core.module import Module, mod
9
8
 
10
- type AsFunctionWrappedType[**P, T] = type[AsFunctionCallable[P, T]]
11
-
12
-
13
- @runtime_checkable
14
- class AsFunctionCallable[**P, T](Protocol):
15
- __slots__ = ()
16
-
17
- @abstractmethod
18
- def call(self, *args: P.args, **kwargs: P.kwargs) -> T:
19
- raise NotImplementedError
9
+ type AsFunctionWrappedType[**P, T] = type[Callable[P, T]]
20
10
 
21
11
 
22
12
  def asfunction[**P, T](
@@ -29,8 +19,8 @@ def asfunction[**P, T](
29
19
  module = module or mod()
30
20
 
31
21
  def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]:
32
- fake_method = wp.call.__get__(NotImplemented)
33
- factory: Caller[..., AsFunctionCallable[P, T]] = module.make_injected_function(
22
+ fake_method = wp.__call__.__get__(NotImplemented, wp)
23
+ factory: Caller[..., Callable[P, T]] = module.make_injected_function(
34
24
  wp,
35
25
  threadsafe=threadsafe,
36
26
  ).__inject_metadata__
@@ -42,14 +32,14 @@ def asfunction[**P, T](
42
32
  @wraps(fake_method)
43
33
  async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
44
34
  self = await factory.acall()
45
- return await self.call(*args, **kwargs) # type: ignore[misc]
35
+ return await self(*args, **kwargs) # type: ignore[misc]
46
36
 
47
37
  else:
48
38
 
49
39
  @wraps(fake_method)
50
40
  def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
51
41
  self = factory.call()
52
- return self.call(*args, **kwargs)
42
+ return self(*args, **kwargs)
53
43
 
54
44
  wrapper.__name__ = wp.__name__
55
45
  wrapper.__qualname__ = wp.__qualname__
@@ -9,7 +9,7 @@ from collections.abc import (
9
9
  Iterable,
10
10
  Iterator,
11
11
  )
12
- from inspect import isfunction
12
+ from inspect import isclass, isfunction
13
13
  from types import GenericAlias, UnionType
14
14
  from typing import (
15
15
  Annotated,
@@ -33,7 +33,7 @@ type TypeInfo[T] = (
33
33
 
34
34
  def get_return_types(*args: TypeInfo[Any]) -> Iterator[InputType[Any]]:
35
35
  for arg in args:
36
- if isinstance(arg, Collection):
36
+ if isinstance(arg, Collection) and not isclass(arg):
37
37
  inner_args = arg
38
38
 
39
39
  elif isfunction(arg) and (return_type := get_return_hint(arg)):
@@ -30,7 +30,7 @@ test = [
30
30
 
31
31
  [project]
32
32
  name = "python-injection"
33
- version = "0.20.0"
33
+ version = "0.21.1"
34
34
  description = "Fast and easy dependency injection framework."
35
35
  license = "MIT"
36
36
  license-files = ["LICENSE"]