Skip to content

Commit 63f184b

Browse files
committed
Fixed stubs, added stubtest.
1 parent 03e120f commit 63f184b

7 files changed

Lines changed: 30 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async-nats = "0.46"
1818
bytes = "1.11.1"
1919
futures-util = "0.3.32"
2020
log = "0.4.29"
21-
pyo3 = { version = "0.28", features = ["abi3"] }
21+
pyo3 = { version = "0.28", features = ["abi3", "experimental-inspect"] }
2222
pyo3-async-runtimes = { version = "0.28", features = ["tokio-runtime"] }
2323
pyo3-log = "0.13.3"
2424
thiserror = "2.0.18"

python/natsrpy/_natsrpy_rs/__init__.pyi

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ class Nats:
5050
def __new__(
5151
cls,
5252
/,
53-
addrs: list[str] = ["nats://localhost:4222"],
53+
addrs: list[str] | None = None,
5454
user_and_pass: tuple[str, str] | None = None,
5555
nkey: str | None = None,
5656
token: str | None = None,
5757
custom_inbox_prefix: str | None = None,
58-
read_buffer_capacity: int = 65535,
59-
sender_capacity: int = 128,
58+
read_buffer_capacity: int = ..., # 65535 bytes
59+
sender_capacity: int = ..., # 128 bytes
6060
max_reconnects: int | None = None,
61-
connection_timeout: float | timedelta = ...,
62-
request_timeout: float | timedelta = ...,
61+
connection_timeout: float | timedelta = ..., # 5 sec
62+
request_timeout: float | timedelta = ..., # 10 sec
6363
) -> Self: ...
6464
async def startup(self) -> None: ...
6565
async def shutdown(self) -> None: ...
@@ -78,8 +78,8 @@ class Nats:
7878
payload: bytes | str | bytearray | memoryview,
7979
*,
8080
headers: dict[str, Any] | None = None,
81-
reply: str | None = None,
82-
err_on_disconnect: bool = False,
81+
inbox: str | None = None,
82+
timeout: float | timedelta | None = None,
8383
) -> None: ...
8484
async def drain(self) -> None: ...
8585
async def flush(self) -> None: ...
@@ -95,6 +95,16 @@ class Nats:
9595
subject: str,
9696
callback: None = None,
9797
) -> IteratorSubscription: ...
98-
async def jetstream(self) -> js.JetStream: ...
98+
async def jetstream(
99+
self,
100+
*,
101+
domain: str | None = None,
102+
api_prefix: str | None = None,
103+
timeout: timedelta | None = None,
104+
ack_timeout: timedelta | None = None,
105+
concurrency_limit: int | None = None,
106+
max_ack_inflight: int | None = None,
107+
backpressure_on_inflight: bool | None = None,
108+
) -> js.JetStream: ...
99109

100110
__all__ = ["CallbackSubscription", "IteratorSubscription", "Message", "Nats", "js"]

python/natsrpy/_natsrpy_rs/js/object_store.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class ObjectStore:
3939
self,
4040
name: str,
4141
writer: Writer[bytes],
42-
chunk_size: int | None = 24576,
42+
chunk_size: int | None = ..., # 24MB
4343
) -> None: ...
4444
async def put(
4545
self,
4646
name: str,
4747
value: bytes | str,
48-
chunk_size: int = 24576,
48+
chunk_size: int = ..., # 24MB
4949
description: str | None = None,
5050
headers: dict[str, str | list[str]] | None = None,
5151
metadata: dict[str, str] | None = None,

src/js/consumers/push/consumer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl MessagesIterator {
6060
slf
6161
}
6262

63+
#[pyo3(signature=(timeout=None))]
6364
pub fn next<'py>(
6465
&self,
6566
py: Python<'py>,

src/js/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub mod stream;
1010
pub mod pymod {
1111
// Classes
1212
#[pymodule_export]
13-
pub use super::jetstream::JetStream;
13+
pub use super::jetstream::{JetStream, Publication};
14+
1415
#[pymodule_export]
1516
pub use super::message::JetStreamMessage;
1617

src/js/stream.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl Source {
353353
start_sequence = None,
354354
start_time=None,
355355
domain=None,
356-
subject_transforms = vec![]
356+
subject_transforms = None
357357
))]
358358
pub fn __new__(
359359
name: String,
@@ -362,7 +362,7 @@ impl Source {
362362
start_sequence: Option<u64>,
363363
start_time: Option<i64>,
364364
domain: Option<String>,
365-
subject_transforms: Vec<Bound<'_, SubjectTransform>>,
365+
subject_transforms: Option<Vec<Bound<'_, SubjectTransform>>>,
366366
) -> NatsrpyResult<Self> {
367367
Ok(Self {
368368
name,
@@ -371,6 +371,7 @@ impl Source {
371371
start_sequence,
372372
filter_subject,
373373
subject_transforms: subject_transforms
374+
.unwrap_or_default()
374375
.into_iter()
375376
.map(|val| val.borrow().deref().clone())
376377
.collect(),

src/nats_cls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl NatsCls {
3737
#[new]
3838
#[pyo3(signature = (
3939
/,
40-
addrs=vec![String::from("nats://localhost:4222")],
40+
addrs=None,
4141
user_and_pass=None,
4242
nkey=None,
4343
token=None,
@@ -49,7 +49,7 @@ impl NatsCls {
4949
request_timeout=TimeValue::FloatSecs(10.0),
5050
))]
5151
fn __new__(
52-
addrs: Vec<String>,
52+
addrs: Option<Vec<String>>,
5353
user_and_pass: Option<(String, String)>,
5454
nkey: Option<String>,
5555
token: Option<String>,
@@ -71,7 +71,7 @@ impl NatsCls {
7171
max_reconnects,
7272
connection_timeout,
7373
request_timeout,
74-
addr: addrs,
74+
addr: addrs.unwrap_or_else(|| vec![String::from("nats://localhost:4222")]),
7575
}
7676
}
7777

0 commit comments

Comments
 (0)