anydi 0.27.0a8__py3-none-any.whl → 0.28.0__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.
anydi/_container.py CHANGED
@@ -429,9 +429,9 @@ class Container:
429
429
  exc_type: type[BaseException] | None,
430
430
  exc_val: BaseException | None,
431
431
  exc_tb: types.TracebackType | None,
432
- ) -> None:
432
+ ) -> bool:
433
433
  """Exit the singleton context."""
434
- self.close()
434
+ return self._singleton_context.__exit__(exc_type, exc_val, exc_tb)
435
435
 
436
436
  def start(self) -> None:
437
437
  """Start the singleton context."""
@@ -464,9 +464,9 @@ class Container:
464
464
  exc_type: type[BaseException] | None,
465
465
  exc_val: BaseException | None,
466
466
  exc_tb: types.TracebackType | None,
467
- ) -> None:
467
+ ) -> bool:
468
468
  """Exit the singleton context."""
469
- await self.aclose()
469
+ return await self._singleton_context.__aexit__(exc_type, exc_val, exc_tb)
470
470
 
471
471
  async def astart(self) -> None:
472
472
  """Start the singleton context asynchronously."""
anydi/_context.py CHANGED
@@ -195,6 +195,14 @@ class ResourceScopedContext(ScopedContext):
195
195
  """
196
196
  return interface in self._instances
197
197
 
198
+ def _create_instance(self, provider: Provider) -> Any:
199
+ """Create an instance using the provider."""
200
+ instance = super()._create_instance(provider)
201
+ # Enter the context manager if the instance is closable.
202
+ if hasattr(instance, "__enter__") and hasattr(instance, "__exit__"):
203
+ self._stack.enter_context(instance)
204
+ return instance
205
+
198
206
  def _create_resource(self, provider: Provider) -> Any:
199
207
  """Create a resource using the provider.
200
208
 
@@ -208,6 +216,14 @@ class ResourceScopedContext(ScopedContext):
208
216
  cm = contextlib.contextmanager(provider.obj)(*args, **kwargs)
209
217
  return self._stack.enter_context(cm)
210
218
 
219
+ async def _acreate_instance(self, provider: Provider) -> Any:
220
+ """Create an instance asynchronously using the provider."""
221
+ instance = await super()._acreate_instance(provider)
222
+ # Enter the context manager if the instance is closable.
223
+ if hasattr(instance, "__aenter__") and hasattr(instance, "__aexit__"):
224
+ await self._async_stack.enter_async_context(instance)
225
+ return instance
226
+
211
227
  async def _acreate_resource(self, provider: Provider) -> Any:
212
228
  """Create a resource asynchronously using the provider.
213
229
 
@@ -243,7 +259,7 @@ class ResourceScopedContext(ScopedContext):
243
259
  exc_type: type[BaseException] | None,
244
260
  exc_val: BaseException | None,
245
261
  exc_tb: TracebackType | None,
246
- ) -> None:
262
+ ) -> bool:
247
263
  """Exit the context.
248
264
 
249
265
  Args:
@@ -251,8 +267,7 @@ class ResourceScopedContext(ScopedContext):
251
267
  exc_val: The exception instance, if any.
252
268
  exc_tb: The traceback, if any.
253
269
  """
254
- self.close()
255
- return
270
+ return self._stack.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value]
256
271
 
257
272
  @abc.abstractmethod
258
273
  def start(self) -> None:
@@ -262,7 +277,7 @@ class ResourceScopedContext(ScopedContext):
262
277
 
263
278
  def close(self) -> None:
264
279
  """Close the scoped context."""
265
- self._stack.close()
280
+ self._stack.__exit__(None, None, None)
266
281
 
267
282
  async def __aenter__(self) -> Self:
268
283
  """Enter the context asynchronously.
@@ -278,7 +293,7 @@ class ResourceScopedContext(ScopedContext):
278
293
  exc_type: type[BaseException] | None,
279
294
  exc_val: BaseException | None,
280
295
  exc_tb: TracebackType | None,
281
- ) -> None:
296
+ ) -> bool:
282
297
  """Exit the context asynchronously.
283
298
 
284
299
  Args:
@@ -286,8 +301,9 @@ class ResourceScopedContext(ScopedContext):
286
301
  exc_val: The exception instance, if any.
287
302
  exc_tb: The traceback, if any.
288
303
  """
289
- await self.aclose()
290
- return
304
+ return await run_async(
305
+ self.__exit__, exc_type, exc_val, exc_tb
306
+ ) or await self._async_stack.__aexit__(exc_type, exc_val, exc_tb)
291
307
 
292
308
  @abc.abstractmethod
293
309
  async def astart(self) -> None:
@@ -295,8 +311,7 @@ class ResourceScopedContext(ScopedContext):
295
311
 
296
312
  async def aclose(self) -> None:
297
313
  """Close the scoped context asynchronously."""
298
- await run_async(self._stack.close)
299
- await self._async_stack.aclose()
314
+ await self.__aexit__(None, None, None)
300
315
 
301
316
 
302
317
  @final
anydi/_utils.py CHANGED
@@ -6,7 +6,7 @@ import builtins
6
6
  import functools
7
7
  import inspect
8
8
  import sys
9
- from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar, cast
9
+ from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar
10
10
 
11
11
  from typing_extensions import ParamSpec, get_args, get_origin
12
12
 
@@ -16,17 +16,6 @@ except ImportError:
16
16
  anyio = None # type: ignore[assignment]
17
17
 
18
18
 
19
- if sys.version_info < (3, 9): # pragma: nocover
20
-
21
- def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
22
- return type_._evaluate(globalns, localns) # noqa
23
-
24
- else:
25
-
26
- def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
27
- return cast(Any, type_)._evaluate(globalns, localns, set()) # noqa
28
-
29
-
30
19
  T = TypeVar("T")
31
20
  P = ParamSpec("P")
32
21
 
@@ -62,6 +51,12 @@ def is_builtin_type(tp: type[Any]) -> bool:
62
51
  return tp.__module__ == builtins.__name__
63
52
 
64
53
 
54
+ def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
55
+ if sys.version_info < (3, 9):
56
+ return type_._evaluate(globalns, localns)
57
+ return type_._evaluate(globalns, localns, recursive_guard=frozenset())
58
+
59
+
65
60
  def get_typed_annotation(
66
61
  annotation: Any,
67
62
  globalns: dict[str, Any],
@@ -70,10 +65,12 @@ def get_typed_annotation(
70
65
  ) -> Any:
71
66
  """Get the typed annotation of a parameter."""
72
67
  if isinstance(annotation, str):
73
- if sys.version_info < (3, 9):
74
- annotation = ForwardRef(annotation)
75
- else:
68
+ if sys.version_info >= (3, 10, 2):
76
69
  annotation = ForwardRef(annotation, module=module, is_class=is_class)
70
+ elif sys.version_info >= (3, 10, 0):
71
+ annotation = ForwardRef(annotation, module=module)
72
+ else:
73
+ annotation = ForwardRef(annotation)
77
74
  annotation = evaluate_forwardref(annotation, globalns, {})
78
75
  return annotation
79
76
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.27.0a8
3
+ Version: 0.28.0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -22,7 +22,6 @@ Classifier: Programming Language :: Python :: 3.10
22
22
  Classifier: Programming Language :: Python :: 3.11
23
23
  Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Programming Language :: Python :: 3 :: Only
25
- Classifier: Programming Language :: Python :: 3.7
26
25
  Classifier: Topic :: Internet
27
26
  Classifier: Topic :: Software Development
28
27
  Classifier: Topic :: Software Development :: Libraries
@@ -33,7 +32,7 @@ Provides-Extra: async
33
32
  Provides-Extra: docs
34
33
  Requires-Dist: anyio (>=3.6.2,<4.0.0) ; extra == "async"
35
34
  Requires-Dist: mkdocs (>=1.4.2,<2.0.0) ; extra == "docs"
36
- Requires-Dist: mkdocs-material (>=9.5.21,<10.0.0) ; extra == "docs"
35
+ Requires-Dist: mkdocs-material (>=9.5.29,<10.0.0) ; extra == "docs"
37
36
  Requires-Dist: typing-extensions (>=4.12.1,<5.0.0)
38
37
  Project-URL: Repository, https://github.com/antonrh/anydi
39
38
  Description-Content-Type: text/markdown
@@ -1,11 +1,11 @@
1
1
  anydi/__init__.py,sha256=aeaBp5vq09sG-e9sqqs9qpUtUIDNfOdFPrlAfE5Ku9E,584
2
- anydi/_container.py,sha256=OjzwZPiQuf9ouyhmIqlNht99pHa77hjZ0sM_n_GovW0,28947
3
- anydi/_context.py,sha256=AVml53KyrQL4yyoJZkU2pbNzQwtg-1Jyt7m6R_0l6_8,11740
2
+ anydi/_container.py,sha256=-vpiYl2Tx2QK9wl74DiF5qLFRudJ3e78TqEyuyOrthE,29055
3
+ anydi/_context.py,sha256=Wm4DT8Ie_TPchWmIBe8Q9f90dQrGd5lY8H5K85rStgY,12706
4
4
  anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
5
5
  anydi/_module.py,sha256=E1TfLud_Af-MPB83PxIzHVA1jlDW2FGaRP_il1a6y3Y,3675
6
6
  anydi/_scanner.py,sha256=cyEk-K2Q8ssZStq8GrxMeEcCuAZMw-RXrjlgWEevKCs,6667
7
7
  anydi/_types.py,sha256=i8xFxz8pmFj7SGqwOwae_P9VtiRie6DVLwfaLibLwhc,3653
8
- anydi/_utils.py,sha256=zP4UvO1aVQJTB8pFNUWAcncvSiuhcg4xNdRU7CoLrqw,3871
8
+ anydi/_utils.py,sha256=q6vEI3_vmZ5sMNau2E5EVk3uMG5geDnXYOW83-vW08M,3857
9
9
  anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  anydi/ext/_utils.py,sha256=2kxLPTMM9Ro3s6-knbqYzONlqRB3hMcwZFFRQGHcFUg,2691
11
11
  anydi/ext/django/__init__.py,sha256=QI1IABCVgSDTUoh7M9WMECKXwB3xvh04HfQ9TOWw1Mk,223
@@ -23,8 +23,8 @@ anydi/ext/pytest_plugin.py,sha256=3OWphc4nEzla46_8KR7LXtwGns5eol_YlUWfTf4Cr2Q,39
23
23
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
25
25
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- anydi-0.27.0a8.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
27
- anydi-0.27.0a8.dist-info/METADATA,sha256=-yLzaxlmDc16XJOD6PfNlbXPvsbY3QmS-0b4yT1DYjE,5163
28
- anydi-0.27.0a8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
- anydi-0.27.0a8.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
30
- anydi-0.27.0a8.dist-info/RECORD,,
26
+ anydi-0.28.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
27
+ anydi-0.28.0.dist-info/METADATA,sha256=0z7X_RPJ0ilu3uOJvsSIBjuXLyf27UUXpfhdZ6zTZvE,5111
28
+ anydi-0.28.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
+ anydi-0.28.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
30
+ anydi-0.28.0.dist-info/RECORD,,