Skip to content

Commit cc16524

Browse files
committed
Fixed stub problems.
1 parent 125e65b commit cc16524

8 files changed

Lines changed: 146 additions & 60 deletions

File tree

python/natsrpy/_natsrpy_rs/__init__.pyi

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,36 @@ from collections.abc import Awaitable, Callable
22
from datetime import timedelta
33
from typing import Any, final, overload
44

5-
from natsrpy._natsrpy_rs.js import JetStream
6-
from natsrpy._natsrpy_rs.message import Message
75
from typing_extensions import Self
86

7+
from . import js
8+
9+
@final
10+
class Message:
11+
"""
12+
Simple NATS message.
13+
14+
Attributes:
15+
subject: subject where message was published
16+
reply: subject where reply should be sent, if any
17+
payload: message payload
18+
headers: dictionary of message headers,
19+
every value can be a simple value or a list.
20+
status: status is used for reply messages to indicate the status of the reply.
21+
It is None for regular messages.
22+
description: message description is used for reply messages to
23+
provide additional information about the status.
24+
length: a length of the message payload in bytes.
25+
"""
26+
27+
subject: str
28+
reply: str | None
29+
payload: bytes
30+
headers: dict[str, Any]
31+
status: int | None
32+
description: str | None
33+
length: int
34+
935
@final
1036
class IteratorSubscription:
1137
def __aiter__(self) -> IteratorSubscription: ...
@@ -69,6 +95,6 @@ class Nats:
6995
subject: str,
7096
callback: None = None,
7197
) -> IteratorSubscription: ...
72-
async def jetstream(self) -> JetStream: ...
98+
async def jetstream(self) -> js.JetStream: ...
7399

74-
__all__ = ["CallbackSubscription", "IteratorSubscription", "Message", "Nats"]
100+
__all__ = ["CallbackSubscription", "IteratorSubscription", "Message", "Nats", "js"]

python/natsrpy/_natsrpy_rs/js/__init__.pyi

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
from datetime import datetime, timedelta
2-
from typing import Any, Literal, overload
2+
from typing import Any, Literal, final, overload
33

4+
from . import consumers, kv, managers, object_store, stream
45
from .managers import KVManager, ObjectStoreManager, StreamsManager
56

7+
__all__ = [
8+
"JetStream",
9+
"JetStreamMessage",
10+
"Publication",
11+
"consumers",
12+
"kv",
13+
"managers",
14+
"object_store",
15+
"stream",
16+
]
17+
18+
@final
619
class Publication:
720
stream: str
821
sequence: int
922
domain: str
1023
duplicate: bool
1124
value: str | None
1225

26+
@final
1327
class JetStream:
1428
@overload
1529
async def publish(
@@ -48,6 +62,7 @@ class JetStream:
4862
@property
4963
def object_store(self) -> ObjectStoreManager: ...
5064

65+
@final
5166
class JetStreamMessage:
5267
@property
5368
def subject(self) -> str: ...

python/natsrpy/_natsrpy_rs/js/consumers.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
from datetime import timedelta
2+
from typing import final
23

34
from natsrpy._natsrpy_rs.js import JetStreamMessage
45
from typing_extensions import Self
56

7+
__all__ = [
8+
"AckPolicy",
9+
"DeliverPolicy",
10+
"MessagesIterator",
11+
"PriorityPolicy",
12+
"PullConsumer",
13+
"PullConsumerConfig",
14+
"PushConsumer",
15+
"PushConsumerConfig",
16+
"ReplayPolicy",
17+
]
18+
19+
@final
620
class DeliverPolicy:
721
ALL: DeliverPolicy
822
LAST: DeliverPolicy
@@ -11,21 +25,25 @@ class DeliverPolicy:
1125
BY_START_TIME: DeliverPolicy
1226
LAST_PER_SUBJECT: DeliverPolicy
1327

28+
@final
1429
class AckPolicy:
1530
EXPLICIT: AckPolicy
1631
NONE: AckPolicy
1732
ALL: AckPolicy
1833

34+
@final
1935
class ReplayPolicy:
2036
INSTANT: ReplayPolicy
2137
ORIGINAL: ReplayPolicy
2238

39+
@final
2340
class PriorityPolicy:
2441
NONE: PriorityPolicy
2542
OVERFLOW: PriorityPolicy
2643
PINNED_CLIENT: PriorityPolicy
2744
PRIORITIZED: PriorityPolicy
2845

46+
@final
2947
class PullConsumerConfig:
3048
name: str | None
3149
durable_name: str | None
@@ -88,6 +106,7 @@ class PullConsumerConfig:
88106
pause_until: int | None = None,
89107
) -> Self: ...
90108

109+
@final
91110
class PushConsumerConfig:
92111
deliver_subject: str
93112
name: str | None
@@ -148,6 +167,7 @@ class PushConsumerConfig:
148167
pause_until: int | None = None,
149168
) -> Self: ...
150169

170+
@final
151171
class MessagesIterator:
152172
def __aiter__(self) -> MessagesIterator: ...
153173
async def __anext__(self) -> JetStreamMessage: ...
@@ -156,9 +176,11 @@ class MessagesIterator:
156176
timeout: float | timedelta | None = None,
157177
) -> JetStreamMessage: ...
158178

179+
@final
159180
class PushConsumer:
160181
async def messages(self) -> MessagesIterator: ...
161182

183+
@final
162184
class PullConsumer:
163185
async def fetch(
164186
self,

python/natsrpy/_natsrpy_rs/js/kv.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
from typing import final
2+
13
from natsrpy._natsrpy_rs.js.stream import Placement, Republish, Source, StorageType
24
from typing_extensions import Self
35

6+
__all__ = [
7+
"KVConfig",
8+
"KeyValue",
9+
]
10+
11+
@final
412
class KVConfig:
513
"""
614
KV bucket config.
@@ -43,6 +51,7 @@ class KVConfig:
4351
limit_markers: float | None = None,
4452
) -> Self: ...
4553

54+
@final
4655
class KeyValue:
4756
@property
4857
def stream_name(self) -> str: ...

python/natsrpy/_natsrpy_rs/js/managers.pyi

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import timedelta
2-
from typing import overload
2+
from typing import final, overload
33

44
from .consumers import (
55
PullConsumer,
@@ -11,20 +11,30 @@ from .kv import KeyValue, KVConfig
1111
from .object_store import ObjectStore, ObjectStoreConfig
1212
from .stream import Stream, StreamConfig
1313

14+
__all__ = [
15+
"ConsumersManager",
16+
"KVManager",
17+
"ObjectStoreManager",
18+
"StreamsManager",
19+
]
20+
21+
@final
1422
class StreamsManager:
1523
async def create(self, config: StreamConfig) -> Stream: ...
1624
async def create_or_update(self, config: StreamConfig) -> Stream: ...
1725
async def get(self, name: str) -> Stream: ...
1826
async def delete(self, name: str) -> bool: ...
1927
async def update(self, config: StreamConfig) -> Stream: ...
2028

29+
@final
2130
class KVManager:
2231
async def create(self, config: KVConfig) -> KeyValue: ...
2332
async def create_or_update(self, config: KVConfig) -> KeyValue: ...
2433
async def get(self, bucket: str) -> KeyValue: ...
2534
async def delete(self, bucket: str) -> bool: ...
2635
async def update(self, config: KVConfig) -> KeyValue: ...
2736

37+
@final
2838
class ConsumersManager:
2939
@overload
3040
async def create(self, config: PullConsumerConfig) -> PullConsumer: ...
@@ -40,6 +50,7 @@ class ConsumersManager:
4050
async def pause(self, name: str, delay: float | timedelta) -> bool: ...
4151
async def resume(self, name: str) -> bool: ...
4252

53+
@final
4354
class ObjectStoreManager:
4455
async def create(self, config: ObjectStoreConfig) -> ObjectStore: ...
4556
async def get(self, bucket: str) -> ObjectStore: ...

python/natsrpy/_natsrpy_rs/js/object_store.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
from datetime import timedelta
2+
from typing import final
23

34
from typing_extensions import Self, Writer
45

56
from .stream import Placement, StorageType
67

8+
__all__ = [
9+
"ObjectStore",
10+
"ObjectStoreConfig",
11+
]
12+
13+
@final
714
class ObjectStoreConfig:
815
bucket: str
916
description: str | None
@@ -26,18 +33,19 @@ class ObjectStoreConfig:
2633
placement: Placement | None = None,
2734
) -> Self: ...
2835

36+
@final
2937
class ObjectStore:
3038
async def get(
3139
self,
3240
name: str,
3341
writer: Writer[bytes],
34-
chunk_size: int | None = 24576, # 24MB
42+
chunk_size: int | None = 24576,
3543
) -> None: ...
3644
async def put(
3745
self,
3846
name: str,
3947
value: bytes | str,
40-
chunk_size: int = 24576, # 24MB
48+
chunk_size: int = 24576,
4149
description: str | None = None,
4250
headers: dict[str, str | list[str]] | None = None,
4351
metadata: dict[str, str] | None = None,

0 commit comments

Comments
 (0)