python-cq 0.7.3__tar.gz → 0.7.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-cq
3
- Version: 0.7.3
3
+ Version: 0.7.4
4
4
  Summary: Lightweight CQRS library for async Python projects.
5
5
  Project-URL: Repository, https://github.com/100nm/python-cq
6
6
  Author: remimd
@@ -1,4 +1,4 @@
1
- from typing import Any
1
+ from typing import Any, Final
2
2
 
3
3
  import injection
4
4
 
@@ -22,23 +22,24 @@ type QueryBus[T] = Bus[Query, T]
22
22
  AnyCommandBus = CommandBus[Any]
23
23
 
24
24
 
25
- command_handler: HandlerDecorator[Command, Any] = HandlerDecorator(
25
+ command_handler: Final[HandlerDecorator[Command, Any]] = HandlerDecorator(
26
26
  SingleHandlerManager(),
27
27
  )
28
- event_handler: HandlerDecorator[Event, None] = HandlerDecorator(
28
+ event_handler: Final[HandlerDecorator[Event, None]] = HandlerDecorator(
29
29
  MultipleHandlerManager(),
30
30
  )
31
- query_handler: HandlerDecorator[Query, Any] = HandlerDecorator(
31
+ query_handler: Final[HandlerDecorator[Query, Any]] = HandlerDecorator(
32
32
  SingleHandlerManager(),
33
33
  )
34
34
 
35
35
 
36
36
  @injection.injectable(inject=False, mode="fallback")
37
- def new_command_bus() -> CommandBus: # type: ignore[type-arg]
37
+ def new_command_bus(*, threadsafe: bool | None = None) -> CommandBus: # type: ignore[type-arg]
38
38
  bus = SimpleBus(command_handler.manager)
39
39
  transaction_scope_middleware = InjectionScopeMiddleware(
40
40
  CQScope.TRANSACTION,
41
41
  exist_ok=True,
42
+ threadsafe=threadsafe,
42
43
  )
43
44
  bus.add_middlewares(transaction_scope_middleware)
44
45
  return bus
@@ -21,11 +21,13 @@ class InjectionScopeMiddleware:
21
21
 
22
22
  async def __call__(self, *args: Any, **kwargs: Any) -> MiddlewareResult[Any]:
23
23
  async with AsyncExitStack() as stack:
24
- context_manager = adefine_scope(self.scope_name, threadsafe=self.threadsafe)
24
+ cm = adefine_scope(self.scope_name, threadsafe=self.threadsafe)
25
25
  try:
26
- await stack.enter_async_context(context_manager)
26
+ await stack.enter_async_context(cm)
27
+
27
28
  except ScopeAlreadyDefinedError:
28
29
  if not self.exist_ok:
29
30
  raise
30
- del context_manager
31
+
32
+ del cm
31
33
  yield
@@ -21,7 +21,7 @@ test = [
21
21
 
22
22
  [project]
23
23
  name = "python-cq"
24
- version = "0.7.3"
24
+ version = "0.7.4"
25
25
  description = "Lightweight CQRS library for async Python projects."
26
26
  license = "MIT"
27
27
  license-files = ["LICENSE"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes