Skip to content

Commit 4d181c2

Browse files
add Query.source_info() method;
update source info api to match zenoh-rust one;
1 parent e523df8 commit 4d181c2

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

Cargo.lock

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/query.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ impl Query {
190190
wait(py, build)
191191
}
192192

193+
#[getter]
194+
fn source_info(&self) -> PyResult<Option<SourceInfo>> {
195+
Ok(self.get_ref()?.source_info().cloned().map_into())
196+
}
197+
193198
fn drop(&mut self) {
194199
Python::with_gil(|gil| gil.allow_threads(|| drop(self.0.take())));
195200
}

src/sample.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ impl Sample {
9191
}
9292

9393
#[getter]
94-
fn source_info(&self) -> SourceInfo {
95-
self.0.source_info().clone().into()
94+
fn source_info(&self) -> Option<SourceInfo> {
95+
self.0.source_info().cloned().map_into()
9696
}
9797

9898
fn __repr__(&self) -> String {
@@ -105,20 +105,17 @@ wrapper!(zenoh::sample::SourceInfo: Clone);
105105
#[pymethods]
106106
impl SourceInfo {
107107
#[new]
108-
fn new(source_id: Option<EntityGlobalId>, source_sn: Option<SourceSn>) -> Self {
109-
Self(zenoh::sample::SourceInfo::new(
110-
source_id.map_into(),
111-
source_sn,
112-
))
108+
fn new(source_id: EntityGlobalId, source_sn: SourceSn) -> Self {
109+
Self(zenoh::sample::SourceInfo::new(source_id.into(), source_sn))
113110
}
114111

115112
#[getter]
116-
fn source_id(&self) -> Option<EntityGlobalId> {
117-
self.0.source_id().cloned().map_into()
113+
fn source_id(&self) -> EntityGlobalId {
114+
self.0.source_id().clone().into()
118115
}
119116

120117
#[getter]
121-
fn source_sn(&self) -> Option<SourceSn> {
118+
fn source_sn(&self) -> SourceSn {
122119
self.0.source_sn()
123120
}
124121
}

zenoh/__init__.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ class Query:
833833
See the class documentation for important details about which key expression to use for replies.
834834
"""
835835

836+
@_unstable
837+
@property
838+
def source_info(self) -> SourceInfo | None:
839+
"""Gets info on the source of this Query."""
840+
836841
def drop(self):
837842
"""Drop the instance of a query.
838843
The query will only be finalized when all query instances (one per queryable
@@ -1174,7 +1179,7 @@ class Sample:
11741179

11751180
@_unstable
11761181
@property
1177-
def source_info(self) -> SourceInfo:
1182+
def source_info(self) -> SourceInfo | None:
11781183
"""Gets info on the source of this Sample."""
11791184

11801185
@final
@@ -1635,15 +1640,13 @@ class SourceInfo:
16351640
global identifier and sequence number.
16361641
"""
16371642

1638-
def __new__(
1639-
cls, source_id: EntityGlobalId | None = None, source_sn: SourceSn | None = None
1640-
) -> Self: ...
1643+
def __new__(cls, source_id: EntityGlobalId, source_sn: SourceSn) -> Self: ...
16411644
@property
1642-
def source_id(self) -> EntityGlobalId | None:
1645+
def source_id(self) -> EntityGlobalId:
16431646
"""The EntityGlobalId of the zenoh entity that published the Sample in question."""
16441647

16451648
@property
1646-
def source_sn(self) -> SourceSn | None:
1649+
def source_sn(self) -> SourceSn:
16471650
"""The sequence number of the Sample from the source."""
16481651

16491652
SourceSn = int

0 commit comments

Comments
 (0)