python-injection 0.8.4.post0__py3-none-any.whl → 0.8.4.post2__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.

Potentially problematic release.


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

injection/__init__.pyi CHANGED
@@ -16,8 +16,8 @@ from typing import (
16
16
 
17
17
  from .common.invertible import Invertible
18
18
 
19
- _In_T = TypeVar("_In_T", covariant=False)
20
- _Co_T = TypeVar("_Co_T", covariant=True)
19
+ _T = TypeVar("_T")
20
+ _T_co = TypeVar("_T_co", covariant=True)
21
21
 
22
22
  default_module: Final[Module] = ...
23
23
 
@@ -88,24 +88,24 @@ class Module:
88
88
 
89
89
  def set_constant(
90
90
  self,
91
- instance: _In_T,
91
+ instance: _T,
92
92
  on: type | Iterable[type] | UnionType = ...,
93
93
  *,
94
94
  mode: InjectableMode | Literal["fallback", "normal", "override"] = ...,
95
- ) -> _In_T:
95
+ ) -> _T:
96
96
  """
97
97
  Function for registering a specific instance to be injected. This is useful for
98
98
  registering global variables. The difference with the singleton decorator is
99
99
  that no dependencies are resolved, so the module doesn't need to be locked.
100
100
  """
101
101
 
102
- def resolve(self, cls: type[_In_T]) -> _In_T:
102
+ def resolve(self, cls: type[_T]) -> _T:
103
103
  """
104
104
  Function used to retrieve an instance associated with the type passed in
105
105
  parameter or an exception will be raised.
106
106
  """
107
107
 
108
- def get_instance(self, cls: type[_In_T]) -> _In_T | None:
108
+ def get_instance(self, cls: type[_T]) -> _T | None:
109
109
  """
110
110
  Function used to retrieve an instance associated with the type passed in
111
111
  parameter or return `None`.
@@ -113,10 +113,10 @@ class Module:
113
113
 
114
114
  def get_lazy_instance(
115
115
  self,
116
- cls: type[_In_T],
116
+ cls: type[_T],
117
117
  *,
118
118
  cache: bool = ...,
119
- ) -> Invertible[_In_T | None]:
119
+ ) -> Invertible[_T | None]:
120
120
  """
121
121
  Function used to retrieve an instance associated with the type passed in
122
122
  parameter or `None`. Return a `Invertible` object. To access the instance
@@ -177,13 +177,13 @@ class ModulePriority(str, Enum):
177
177
  HIGH = ...
178
178
 
179
179
  @runtime_checkable
180
- class Injectable(Protocol[_Co_T]):
181
- def __init__(self, factory: Callable[[], _Co_T] = ..., /): ...
180
+ class Injectable(Protocol[_T_co]):
181
+ def __init__(self, factory: Callable[[], _T_co] = ..., /): ...
182
182
  @property
183
183
  def is_locked(self) -> bool: ...
184
184
  def unlock(self): ...
185
185
  @abstractmethod
186
- def get_instance(self) -> _Co_T: ...
186
+ def get_instance(self) -> _T_co: ...
187
187
 
188
188
  @final
189
189
  class InjectableMode(str, Enum):
@@ -5,19 +5,19 @@ from typing import Protocol, TypeVar, runtime_checkable
5
5
 
6
6
  __all__ = ("Invertible", "SimpleInvertible")
7
7
 
8
- _T = TypeVar("_T", covariant=True)
8
+ _T_co = TypeVar("_T_co", covariant=True)
9
9
 
10
10
 
11
11
  @runtime_checkable
12
- class Invertible(Protocol[_T]):
12
+ class Invertible(Protocol[_T_co]):
13
13
  @abstractmethod
14
- def __invert__(self) -> _T:
14
+ def __invert__(self) -> _T_co:
15
15
  raise NotImplementedError
16
16
 
17
17
 
18
18
  @dataclass(repr=False, eq=False, frozen=True, slots=True)
19
- class SimpleInvertible(Invertible[_T]):
20
- callable: Callable[[], _T]
19
+ class SimpleInvertible(Invertible[_T_co]):
20
+ callable: Callable[[], _T_co]
21
21
 
22
- def __invert__(self) -> _T:
22
+ def __invert__(self) -> _T_co:
23
23
  return self.callable()
injection/core/module.py CHANGED
@@ -48,8 +48,8 @@ __all__ = ("Injectable", "Mode", "Module", "Priority")
48
48
 
49
49
  _logger = logging.getLogger(__name__)
50
50
 
51
- _In_T = TypeVar("_In_T", covariant=False)
52
- _Co_T = TypeVar("_Co_T", covariant=True)
51
+ _T = TypeVar("_T")
52
+ _T_co = TypeVar("_T_co", covariant=True)
53
53
 
54
54
 
55
55
  """
@@ -135,10 +135,10 @@ Injectables
135
135
 
136
136
 
137
137
  @runtime_checkable
138
- class Injectable(Protocol[_Co_T]):
138
+ class Injectable(Protocol[_T_co]):
139
139
  __slots__ = ()
140
140
 
141
- def __init__(self, __factory: Callable[[], _Co_T] = None, /):
141
+ def __init__(self, __factory: Callable[[], _T_co] = None, /):
142
142
  pass
143
143
 
144
144
  @property
@@ -149,23 +149,23 @@ class Injectable(Protocol[_Co_T]):
149
149
  return
150
150
 
151
151
  @abstractmethod
152
- def get_instance(self) -> _Co_T:
152
+ def get_instance(self) -> _T_co:
153
153
  raise NotImplementedError
154
154
 
155
155
 
156
156
  @dataclass(repr=False, frozen=True, slots=True)
157
- class BaseInjectable(Injectable[_In_T], ABC):
158
- factory: Callable[[], _In_T]
157
+ class BaseInjectable(Injectable[_T], ABC):
158
+ factory: Callable[[], _T]
159
159
 
160
160
 
161
- class NewInjectable(BaseInjectable[_In_T]):
161
+ class NewInjectable(BaseInjectable[_T]):
162
162
  __slots__ = ()
163
163
 
164
- def get_instance(self) -> _In_T:
164
+ def get_instance(self) -> _T:
165
165
  return self.factory()
166
166
 
167
167
 
168
- class SingletonInjectable(BaseInjectable[_In_T]):
168
+ class SingletonInjectable(BaseInjectable[_T]):
169
169
  __slots__ = ("__dict__",)
170
170
 
171
171
  __INSTANCE_KEY: ClassVar[str] = "$instance"
@@ -181,7 +181,7 @@ class SingletonInjectable(BaseInjectable[_In_T]):
181
181
  def unlock(self):
182
182
  self.cache.clear()
183
183
 
184
- def get_instance(self) -> _In_T:
184
+ def get_instance(self) -> _T:
185
185
  with suppress(KeyError):
186
186
  return self.cache[self.__INSTANCE_KEY]
187
187
 
@@ -193,8 +193,8 @@ class SingletonInjectable(BaseInjectable[_In_T]):
193
193
 
194
194
 
195
195
  @dataclass(repr=False, frozen=True, slots=True)
196
- class ShouldBeInjectable(Injectable[_In_T]):
197
- cls: type[_In_T]
196
+ class ShouldBeInjectable(Injectable[_T]):
197
+ cls: type[_T]
198
198
 
199
199
  def get_instance(self) -> NoReturn:
200
200
  raise InjectionError(f"`{format_type(self.cls)}` should be an injectable.")
@@ -210,7 +210,7 @@ class Broker(Protocol):
210
210
  __slots__ = ()
211
211
 
212
212
  @abstractmethod
213
- def __getitem__(self, cls: type[_In_T] | UnionType, /) -> Injectable[_In_T]:
213
+ def __getitem__(self, cls: type[_T] | UnionType, /) -> Injectable[_T]:
214
214
  raise NotImplementedError
215
215
 
216
216
  @abstractmethod
@@ -259,7 +259,7 @@ class Container(Broker):
259
259
  __records: dict[type, Record] = field(default_factory=dict, init=False)
260
260
  __channel: EventChannel = field(default_factory=EventChannel, init=False)
261
261
 
262
- def __getitem__(self, cls: type[_In_T] | UnionType, /) -> Injectable[_In_T]:
262
+ def __getitem__(self, cls: type[_T] | UnionType, /) -> Injectable[_T]:
263
263
  for cls in get_origins(cls):
264
264
  try:
265
265
  injectable, _ = self.__records[cls]
@@ -372,7 +372,7 @@ class Module(EventListener, Broker):
372
372
  def __post_init__(self):
373
373
  self.__container.add_listener(self)
374
374
 
375
- def __getitem__(self, cls: type[_In_T] | UnionType, /) -> Injectable[_In_T]:
375
+ def __getitem__(self, cls: type[_T] | UnionType, /) -> Injectable[_T]:
376
376
  for broker in self.__brokers:
377
377
  with suppress(KeyError):
378
378
  return broker[cls]
@@ -431,11 +431,11 @@ class Module(EventListener, Broker):
431
431
 
432
432
  def set_constant(
433
433
  self,
434
- instance: _In_T,
434
+ instance: _T,
435
435
  on: type | Iterable[type] | UnionType = (),
436
436
  *,
437
437
  mode: Mode | ModeStr = Mode.get_default(),
438
- ) -> _In_T:
438
+ ) -> _T:
439
439
  cls = type(instance)
440
440
  self.injectable(
441
441
  lambda: instance,
@@ -468,11 +468,11 @@ class Module(EventListener, Broker):
468
468
 
469
469
  return decorator(wrapped) if wrapped else decorator
470
470
 
471
- def resolve(self, cls: type[_In_T]) -> _In_T:
471
+ def resolve(self, cls: type[_T]) -> _T:
472
472
  injectable = self[cls]
473
473
  return injectable.get_instance()
474
474
 
475
- def get_instance(self, cls: type[_In_T]) -> _In_T | None:
475
+ def get_instance(self, cls: type[_T]) -> _T | None:
476
476
  try:
477
477
  return self.resolve(cls)
478
478
  except KeyError:
@@ -480,10 +480,10 @@ class Module(EventListener, Broker):
480
480
 
481
481
  def get_lazy_instance(
482
482
  self,
483
- cls: type[_In_T],
483
+ cls: type[_T],
484
484
  *,
485
485
  cache: bool = False,
486
- ) -> Invertible[_In_T | None]:
486
+ ) -> Invertible[_T | None]:
487
487
  if cache:
488
488
  return Lazy(lambda: self.get_instance(cls))
489
489
 
injection/py.typed ADDED
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-injection
3
- Version: 0.8.4.post0
3
+ Version: 0.8.4.post2
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Home-page: https://github.com/100nm/python-injection
6
6
  License: MIT
@@ -1,19 +1,20 @@
1
1
  injection/__init__.py,sha256=Bf6S99E2srD3752xlJf3uAdiGIzY2YHOZafcwEiwY70,739
2
- injection/__init__.pyi,sha256=U3HBDYYrlxiwqMBIVVzgbI7VREP2N8_5Ysimzh6LmZo,5960
2
+ injection/__init__.pyi,sha256=fNTW5TUZQmaxPooaa_vJ_nyR_-DqZ13hSWHh_TsdeOo,5913
3
3
  injection/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  injection/common/event.py,sha256=TvkFv-5zF_oUTPhh5U0BKD5HanvCJKHA0H7yceMRy5c,1261
5
- injection/common/invertible.py,sha256=bG-_0u8T13lrZbauHoa8n7KzXg0Acpi3hurIIKhlqes,574
5
+ injection/common/invertible.py,sha256=BZnkDg_NZDsTXGca5w5Wg_nYE3oRO_Wlodi2XtE55ck,595
6
6
  injection/common/lazy.py,sha256=1C34uoG229Gl0DEUcD9-eQrL4K_oIofOLzdQ1SiY6rw,1401
7
7
  injection/common/queue.py,sha256=mV0AGxp5aYMr438MxmoIsZcV5jmqi5x_GD2S-utrnzA,1443
8
8
  injection/common/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  injection/common/tools/threading.py,sha256=RAtzBFLVNJMflWIHxrP83fjafnFq8_JLgFoYQg8nVyE,182
10
10
  injection/common/tools/type.py,sha256=05fD5UkUI1kPoFWEjQz4j266SYfJQMK-Ti88JXNxb_M,1276
11
11
  injection/core/__init__.py,sha256=zuf0ubI2dHnbjn1059eduhS-ACIkkROa6-dhp10krh0,22
12
- injection/core/module.py,sha256=xdH0w4deIFhOU34oKd-T7wS-dB3AicN89gCChKSjWIM,20596
12
+ injection/core/module.py,sha256=jofZzYk_-1Rsfj-fDrPs-64RfVXvnMCWcKk2NSCsyTk,20507
13
13
  injection/exceptions.py,sha256=f2lVSTAx-Nv89s0skn15y-sCkr656ROuWYs-XlrcEn8,683
14
14
  injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  injection/integrations/blacksheep.py,sha256=dFXzrxkJRy9z44CcwG0ROYshT3zUZTVyuQkRy390RvU,765
16
+ injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
17
  injection/utils.py,sha256=_79aiciimZpuoUTz5lojKySUMMzpkU-e7SotiHIFTI8,676
17
- python_injection-0.8.4.post0.dist-info/METADATA,sha256=HvubVzCGY3UkGSOMRW77CNn8GBQGlnwm1ayxJB-n2IM,3678
18
- python_injection-0.8.4.post0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
19
- python_injection-0.8.4.post0.dist-info/RECORD,,
18
+ python_injection-0.8.4.post2.dist-info/METADATA,sha256=V-_8VSQ0z_JX5t32nfkbXOuJA-9b7ykveITH1S54gHQ,3678
19
+ python_injection-0.8.4.post2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
20
+ python_injection-0.8.4.post2.dist-info/RECORD,,