python-neva 3.4.0__py3-none-any.whl → 3.5.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.
neva/events/dispatcher.py CHANGED
@@ -1,5 +1,6 @@
1
1
  """Base implementation of the event dispatcher."""
2
2
 
3
+ import inspect
3
4
  from typing import override
4
5
 
5
6
  from neva.arch.application import Application
@@ -35,11 +36,9 @@ class EventDispatcher(contracts.EventDispatcher):
35
36
  event: The event about to be dispatched.
36
37
  """
37
38
  for hook in self._before_dispatch_hooks:
38
- match hook:
39
- case contracts.AsyncBeforeDispatchHook():
40
- await hook(event)
41
- case contracts.SyncBeforeDispatchHook():
42
- hook(event)
39
+ result = hook(event)
40
+ if inspect.isawaitable(result):
41
+ await result
43
42
 
44
43
  @override
45
44
  async def before_dispatch(self, hook: contracts.BeforeDispatchHook) -> None:
@@ -1,14 +1,24 @@
1
1
  """Type stub for App facade."""
2
2
 
3
- from typing import override
3
+ from contextlib import AbstractAsyncContextManager
4
+ from typing import Any, Self, override
4
5
 
5
6
  from neva.arch import Facade
7
+ from neva.arch.scopes import BaseScope
6
8
  from neva.support import Result
7
9
 
8
10
  class App(Facade):
9
11
  @classmethod
10
12
  @override
11
13
  def get_facade_accessor(cls) -> type: ...
14
+ @classmethod
15
+ async def make_async[T](cls, interface: type[T]) -> Result[T, str]:
16
+ """Resolve and instanciate a type from the container.
17
+
18
+ Returns:
19
+ Result containing the resolved type instance or an error message.
20
+ """
21
+
12
22
  @classmethod
13
23
  def make[T](cls, interface: type[T]) -> Result[T, str]:
14
24
  """Resolve an interface from the container by its alias.
@@ -23,3 +33,15 @@ class App(Facade):
23
33
  Result containing the resolved service instance or an error message.
24
34
 
25
35
  """
36
+
37
+ @classmethod
38
+ async def scope(
39
+ cls,
40
+ scope: BaseScope | None = None,
41
+ context: dict[type, Any] | None = None,
42
+ ) -> AbstractAsyncContextManager[Self]:
43
+ """Enter a new scope.
44
+
45
+ Yields:
46
+ The application instance with the new scope.
47
+ """
@@ -5,7 +5,7 @@ from contextlib import contextmanager
5
5
  from typing import TYPE_CHECKING, override
6
6
 
7
7
  from neva.arch import Facade
8
- from neva.events import EventDispatcher
8
+ from neva.events import contracts
9
9
 
10
10
 
11
11
  if TYPE_CHECKING:
@@ -23,7 +23,7 @@ class Event(Facade):
23
23
  Returns:
24
24
  EventDispatcher class.
25
25
  """
26
- return EventDispatcher
26
+ return contracts.EventDispatcher
27
27
 
28
28
  @classmethod
29
29
  def fake(cls) -> "EventFake":
@@ -13,10 +13,15 @@ class Event(Facade):
13
13
  @override
14
14
  def get_facade_accessor(cls) -> type: ...
15
15
  @classmethod
16
- async def dispatch(cls, event: contracts.Event) -> list[Result[None, str]]: ...
16
+ async def before_dispatch(cls, hook: contracts.BeforeDispatchHook) -> None:
17
+ """Register a hook to be called before listeners are invoked."""
18
+ @classmethod
19
+ async def dispatch(cls, event: contracts.Event) -> list[Result[None, str]]:
20
+ """Dispatch an event to all registered listeners."""
17
21
  @classmethod
18
22
  def listen[T: contracts.Event](
19
23
  cls,
20
24
  event_cls: type[T],
21
25
  listener_cls: type[contracts.EventListener[T]],
22
- ) -> None: ...
26
+ ) -> None:
27
+ """Register a listener for an event."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-neva
3
- Version: 3.4.0
3
+ Version: 3.5.0
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: aiosqlite>=0.20.0
@@ -21,7 +21,7 @@ neva/database/provider.py,sha256=l2be4Ri53RtQq1-qzohy3cqzJQpTaNzqXGVhXPKUCXc,167
21
21
  neva/database/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  neva/database/transaction.py,sha256=_0Dsao_vhCJT5YRUmrHOLb0uxvfdE-5k3n0yMPLC1o8,5167
23
23
  neva/events/__init__.py,sha256=Gpi5q-pNlIi-q23U2ZOsNf8Y9rB6AQtsBbbBFU0tkFc,776
24
- neva/events/dispatcher.py,sha256=5M8s3aVzx9lIViGkigtu1kq6gFbam4OKDajuWNGuqA0,4376
24
+ neva/events/dispatcher.py,sha256=KR5uDZbnNwrMCI6s9S_SoNrNHx2z2lugoHk1-g3fzXA,4288
25
25
  neva/events/event.py,sha256=q-KyyxNkU3AN2YSaujuNPIoXQMXhGOwClTap5y8fU5I,282
26
26
  neva/events/event_registry.py,sha256=IZnpR3oLyvt5K2pn9KMCBw5W4JP7Ok_zMKI2SgQoXVM,1945
27
27
  neva/events/listener.py,sha256=2d5RHVKO0pU-eL_evLReTG0DIoX9tZyOcn8PWLeECZo,1435
@@ -73,15 +73,15 @@ neva/support/strconv.py,sha256=cvYRtJVG3IuhQzZCqJD1nVm3g0wxRu-IIIFK16Mq7d8,1296
73
73
  neva/support/time.py,sha256=QYH1F38V33F1C-rlH1Xbrblnaue1-BnercFYUBMmq88,351
74
74
  neva/support/facade/__init__.py,sha256=aysM4AyDAxAgv8uZCka49t2vLHeVraTNAHeCIpXLd-s,465
75
75
  neva/support/facade/app.py,sha256=xdL9qpeQnJtAMomxfrImM82qM2YV2eQFsckmUNE2w7I,297
76
- neva/support/facade/app.pyi,sha256=QBk-1cRpcNPsxQM0cGT0IYU1B4DQeExhzf1w8Sbax2g,643
76
+ neva/support/facade/app.pyi,sha256=gTAKp_r8DUqOj-oggAyAuK1WvR2AzX63-G2U5NixHbM,1304
77
77
  neva/support/facade/config.py,sha256=cqmtwAekHE4qWH2LqzmY3BAbyAadvZYfPgLHyTcCnJE,358
78
78
  neva/support/facade/config.pyi,sha256=LpI6xwqURRlWPcohXBxTL-iWTHq3MMMNdu670Q_5jnk,2549
79
79
  neva/support/facade/crypt.py,sha256=BUx2woDla3TrvVOVRNzOg97zfCaXIOqIz5EdoN3BvlA,298
80
80
  neva/support/facade/crypt.pyi,sha256=_MV_qXDATaCs1pZTOw_-qPx_jjH_nG4-tUBOMX4nZIE,857
81
81
  neva/support/facade/db.py,sha256=mXMzuCKf390ICCBgzaub1ZoMqUBgOQByQYMEM3YnN_0,324
82
82
  neva/support/facade/db.pyi,sha256=UQFMgBuw0BGquMnuUNULC8Pdo7lDCVTCNkDaUmIZJhw,1911
83
- neva/support/facade/event.py,sha256=sRU-fxaRT59Fe-u2WTS5L9ncGkGLBndKa9gKbqwAq3M,1232
84
- neva/support/facade/event.pyi,sha256=AL_v8fxkvtd9KwbiWbVuUAcdZz0yzLn8xZROFa6lXLE,546
83
+ neva/support/facade/event.py,sha256=BkJoof1hYTxhMBOxLrq21NIgEPIiLBlj18Pttl0FHa8,1236
84
+ neva/support/facade/event.pyi,sha256=7R6osyTZbHt_zkCfQ-uZnTLfyZTeN1bi3exsgl3-36k,817
85
85
  neva/support/facade/hash.py,sha256=tGhsvfGovt-mcRXSjDKf4jt1n7ib0eDPXFvRUfVxLUc,292
86
86
  neva/support/facade/hash.pyi,sha256=jTs3E5ZF5cp76jrgH70DEog8gzfYIcIV2PrO9xskHyI,1656
87
87
  neva/support/facade/log.py,sha256=_uLoHB9tkpHkiqEJXazbaqfiKUOtv3NS71ZCZAprzOI,347
@@ -91,6 +91,6 @@ neva/testing/fakes.py,sha256=w2dnFaO6x14l0_si7iBNELMCxaFi8VsVOSQ6PmTlclE,2936
91
91
  neva/testing/fixtures.py,sha256=oiPa5ntUkW-SbySDvwEHXtti8NqSwI-R0CT1_ezTx_Y,1445
92
92
  neva/testing/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
93
  neva/testing/test_case.py,sha256=zJBZJeKI-sv-EOaXNuSJ0V2Zp_6hdk64W4dOh0eP8RI,3290
94
- python_neva-3.4.0.dist-info/METADATA,sha256=rW3P72J2ukVUItHYsF1EDWCu4SJzGqv--6PjnYDnO5o,846
95
- python_neva-3.4.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
96
- python_neva-3.4.0.dist-info/RECORD,,
94
+ python_neva-3.5.0.dist-info/METADATA,sha256=rcHS4PoUAyXqpkmfej_UhyUaBgnb5dV-x8ZbwMWbXFQ,846
95
+ python_neva-3.5.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
96
+ python_neva-3.5.0.dist-info/RECORD,,