engin 0.0.16__py3-none-any.whl → 0.0.17__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.
engin/_assembler.py CHANGED
@@ -228,7 +228,7 @@ class Assembler:
228
228
  yield from (
229
229
  child_provider
230
230
  for root_provider in root_providers
231
- for root_provider_param in root_provider.parameter_types
231
+ for root_provider_param in root_provider.parameter_type_ids
232
232
  for child_provider in self._resolve_providers(root_provider_param)
233
233
  )
234
234
  yield from root_providers
engin/_cli/_graph.py CHANGED
@@ -165,7 +165,7 @@ def _render_node(node: Dependency, render_block: bool = True) -> str:
165
165
  md += f"{_short_name(node.return_type_id)}"
166
166
  return f'{node_id}["`{md}`"]{style}'
167
167
  if isinstance(node, Entrypoint):
168
- entrypoint_type = node.parameter_types[0]
168
+ entrypoint_type = node.parameter_type_ids[0]
169
169
  md += f"{entrypoint_type}"
170
170
  return f'{node_id}[/"`{md}`"\\]{style}'
171
171
  if isinstance(node, Invoke):
engin/_dependency.py CHANGED
@@ -76,7 +76,7 @@ class Dependency(ABC, Option, Generic[P, T]):
76
76
  return f"{self._func.__module__}.{self._func.__name__}"
77
77
 
78
78
  @property
79
- def parameter_types(self) -> list[TypeId]:
79
+ def parameter_type_ids(self) -> list[TypeId]:
80
80
  parameters = list(self._signature.parameters.values())
81
81
  if not parameters:
82
82
  return []
@@ -136,7 +136,7 @@ class Entrypoint(Invoke):
136
136
  super().__init__(invocation=_noop)
137
137
 
138
138
  @property
139
- def parameter_types(self) -> list[TypeId]:
139
+ def parameter_type_ids(self) -> list[TypeId]:
140
140
  return [TypeId.from_type(self._type)]
141
141
 
142
142
  @property
@@ -153,7 +153,12 @@ class Entrypoint(Invoke):
153
153
 
154
154
  class Provide(Dependency[Any, T]):
155
155
  def __init__(
156
- self, builder: Func[P, T], *, scope: str | None = None, override: bool = False
156
+ self,
157
+ builder: Func[P, T],
158
+ *,
159
+ scope: str | None = None,
160
+ as_type: type | None = None,
161
+ override: bool = False,
157
162
  ) -> None:
158
163
  """
159
164
  Provide a type via a builder or factory function.
@@ -161,19 +166,26 @@ class Provide(Dependency[Any, T]):
161
166
  Args:
162
167
  builder: the builder function that returns the type.
163
168
  scope: (optional) associate this provider with a specific scope.
164
- override: (optional) allow this provider to override existing providers from
165
- the same package.
169
+ as_type: (optional) allows you to explicitly specify the provided type, e.g.
170
+ to type erase a concrete type, or to provide a mock implementation.
171
+ override: (optional) allow this provider to override other providers for the
172
+ same type from the same package.
166
173
  """
167
174
  super().__init__(func=builder)
168
175
  self._scope = scope
169
176
  self._override = override
177
+ self._explicit_type = as_type
178
+
179
+ if self._explicit_type is not None:
180
+ self._signature = self._signature.replace(return_annotation=self._explicit_type)
181
+
170
182
  self._is_multi = typing.get_origin(self.return_type) is list
171
183
 
172
184
  # Validate that the provider does to depend on its own output value, as this will
173
185
  # cause a recursion error and is undefined behaviour wise.
174
186
  if any(
175
187
  self.return_type == param.annotation
176
- for param in self.signature.parameters.values()
188
+ for param in self._signature.parameters.values()
177
189
  ):
178
190
  raise ValueError("A provider cannot depend on its own return type")
179
191
 
@@ -187,6 +199,8 @@ class Provide(Dependency[Any, T]):
187
199
 
188
200
  @property
189
201
  def return_type(self) -> type[T]:
202
+ if self._explicit_type is not None:
203
+ return self._explicit_type
190
204
  if isclass(self._func):
191
205
  return_type = self._func # __init__ returns self
192
206
  else:
@@ -253,23 +267,19 @@ class Supply(Provide, Generic[T]):
253
267
  function.
254
268
 
255
269
  Args:
256
- value: the value to Supply
257
- as_type: allows you to specify the provided type, useful for type erasing,
258
- e.g. Supply a concrete value but specify it as an interface or other
259
- abstraction.
260
- override: allow this provider to override existing providers from the same
261
- package.
270
+ value: the value to Supply.
271
+ as_type: (optional) allows you to explicitly specify the provided type, e.g.
272
+ to type erase a concrete type, or to provide a mock implementation.
273
+ override: (optional) allow this provider to override other providers for the
274
+ same type from the same package.
262
275
  """
263
276
  self._value = value
264
- self._type_hint = as_type
265
- if self._type_hint is not None:
266
- self._get_val.__annotations__["return"] = as_type
267
- super().__init__(builder=self._get_val, override=override)
277
+ super().__init__(builder=self._get_val, as_type=as_type, override=override)
268
278
 
269
279
  @property
270
280
  def return_type(self) -> type[T]:
271
- if self._type_hint is not None:
272
- return self._type_hint
281
+ if self._explicit_type is not None:
282
+ return self._explicit_type
273
283
  if isinstance(self._value, list):
274
284
  return list[type(self._value[0])] # type: ignore[misc,return-value]
275
285
  return type(self._value)
engin/_graph.py CHANGED
@@ -31,7 +31,7 @@ class DependencyGrapher:
31
31
  ) -> list[Node]:
32
32
  nodes: list[Node] = []
33
33
  for root in roots:
34
- for parameter in root.parameter_types:
34
+ for parameter in root.parameter_type_ids:
35
35
  provider = self._providers[parameter]
36
36
 
37
37
  # multiprovider
engin/ext/fastapi.py CHANGED
@@ -75,7 +75,7 @@ class _FastAPIDependencyGrapher(DependencyGrapher):
75
75
  ) -> list[Node]:
76
76
  nodes: list[Node] = []
77
77
  for root in roots:
78
- for parameter in root.parameter_types:
78
+ for parameter in root.parameter_type_ids:
79
79
  provider = self._providers[parameter]
80
80
 
81
81
  # multiprovider
@@ -162,7 +162,7 @@ class APIRouteDependency(Dependency):
162
162
  return self._route
163
163
 
164
164
  @property
165
- def parameter_types(self) -> list[TypeId]:
165
+ def parameter_type_ids(self) -> list[TypeId]:
166
166
  parameters = list(self._signature.parameters.values())
167
167
  if not parameters:
168
168
  return []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: engin
3
- Version: 0.0.16
3
+ Version: 0.0.17
4
4
  Summary: An async-first modular application framework
5
5
  Project-URL: Homepage, https://github.com/invokermain/engin
6
6
  Project-URL: Documentation, https://engin.readthedocs.io/en/latest/
@@ -1,10 +1,10 @@
1
1
  engin/__init__.py,sha256=rBTteMLAVKg4TJSaMElJUwz72BA_X7nBTREg-I-bWhA,584
2
- engin/_assembler.py,sha256=8rt16LGvPpXHtjSdEDQJ6XC6DVwSbr_4_Mcfcfnpf70,10949
2
+ engin/_assembler.py,sha256=r2Vr9UO7pHYvj71087PIJYT9lFBNPni3x34MtjMHN7A,10952
3
3
  engin/_block.py,sha256=8ysWrmHkWpTm6bmSc6jZVoO0Ax5Svu1HwxpZwAtIF_o,2617
4
- engin/_dependency.py,sha256=KM_d4TEu7NaoOSuIC7lRO7UvPzBFb0sxR74ZbInLMng,8561
4
+ engin/_dependency.py,sha256=5x4_0QvHtqv6R_brKHRc-INKE4oMh1JU8-9RCmulp4Q,8976
5
5
  engin/_engin.py,sha256=yIpZdeqvm8hv0RxOV0veFuvyu9xQ054JSaeuUWwHdOQ,7380
6
6
  engin/_exceptions.py,sha256=UzMppJWDk_Hx3qWAypcPVLw9OYCibqiZjLYeTl22zaE,1355
7
- engin/_graph.py,sha256=1pMB0cr--uS0XJycDb1rS_X45RBpoyA6NkKqbeSuz1Q,1628
7
+ engin/_graph.py,sha256=y1g7Lm_Zy5GPEgRsggCKV5DDaDzcwUl8v3IZCK8jyGI,1631
8
8
  engin/_introspect.py,sha256=VdREX6Lhhga5SnEP9G7mjHkgJR4mpqk_SMnmL2zTcqY,966
9
9
  engin/_lifecycle.py,sha256=cSWe3euZkmpxmUPFvph2lsTtvuZbxttEfBL-RnOI7lo,5325
10
10
  engin/_option.py,sha256=nZcdrehp1QwgxMUoIpsM0PJuu1q1pbXzhcVsetbsHpc,223
@@ -12,13 +12,13 @@ engin/_type_utils.py,sha256=Pmm4m1_WdevT5KTe8tzY_BseNxPyhu_nKsLGgyNcPpo,2247
12
12
  engin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  engin/_cli/__init__.py,sha256=lp1KiBpcgk_dZU5V9DjgLPwmp0ja444fwLH2CYCscNc,302
14
14
  engin/_cli/_graph.html,sha256=rR5dnDKoz7KtSff0ERCi2UKuoH_Z03MRYiXI_W03G5k,2430
15
- engin/_cli/_graph.py,sha256=2v-l5rEC4zm36SWgmzQ2UK-nIHofYpexTo3et55AtE0,5539
15
+ engin/_cli/_graph.py,sha256=YZ0awBLtWD5W6xrHO9ueMnk_EIsYM4_j_bmquiLsb2Y,5542
16
16
  engin/_cli/_utils.py,sha256=AQFtLO8qjYRCTQc9A8Z1HVf7eZr8iGWogxbYzsgIkS4,360
17
17
  engin/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  engin/ext/asgi.py,sha256=d5Z6gtMVWDZdAlvrTaMt987sKyiq__A0X4gJQ7IETmA,3247
19
- engin/ext/fastapi.py,sha256=e8UV521Mq9Iqr55CT7_jtd51iaIZjWlAacoqFBXsh-k,6356
20
- engin-0.0.16.dist-info/METADATA,sha256=1-9KPa3HdnKUM38_OD3yAdNHHTb4-cOBds8dlqedv9s,2354
21
- engin-0.0.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
- engin-0.0.16.dist-info/entry_points.txt,sha256=sW247zZUMxm0b5UKYvPuqQQljYDtU-j2zK3cu7gHwM0,41
23
- engin-0.0.16.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
24
- engin-0.0.16.dist-info/RECORD,,
19
+ engin/ext/fastapi.py,sha256=TGNf0LFLaTLMLlAycH7GgP_GcBld262v9xboGOwhvgE,6362
20
+ engin-0.0.17.dist-info/METADATA,sha256=1SUQZwsFr3neO0WJ_gLLv90kgJCcBNUbwWWi2zZZ77Q,2354
21
+ engin-0.0.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
+ engin-0.0.17.dist-info/entry_points.txt,sha256=sW247zZUMxm0b5UKYvPuqQQljYDtU-j2zK3cu7gHwM0,41
23
+ engin-0.0.17.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
24
+ engin-0.0.17.dist-info/RECORD,,
File without changes