Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ impl Query {
wait(py, build)
}

#[getter]
fn source_info(&self) -> PyResult<Option<SourceInfo>> {
Ok(self.get_ref()?.source_info().cloned().map_into())
}

fn drop(&mut self) {
Python::with_gil(|gil| gil.allow_threads(|| drop(self.0.take())));
}
Expand Down
17 changes: 7 additions & 10 deletions src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl Sample {
}

#[getter]
fn source_info(&self) -> SourceInfo {
self.0.source_info().clone().into()
fn source_info(&self) -> Option<SourceInfo> {
self.0.source_info().cloned().map_into()
}

fn __repr__(&self) -> String {
Expand All @@ -105,20 +105,17 @@ wrapper!(zenoh::sample::SourceInfo: Clone);
#[pymethods]
impl SourceInfo {
#[new]
fn new(source_id: Option<EntityGlobalId>, source_sn: Option<SourceSn>) -> Self {
Self(zenoh::sample::SourceInfo::new(
source_id.map_into(),
source_sn,
))
fn new(source_id: EntityGlobalId, source_sn: SourceSn) -> Self {
Self(zenoh::sample::SourceInfo::new(source_id.into(), source_sn))
}

#[getter]
fn source_id(&self) -> Option<EntityGlobalId> {
self.0.source_id().cloned().map_into()
fn source_id(&self) -> EntityGlobalId {
(*self.0.source_id()).into()
}

#[getter]
fn source_sn(&self) -> Option<SourceSn> {
fn source_sn(&self) -> SourceSn {
self.0.source_sn()
}
}
15 changes: 9 additions & 6 deletions zenoh/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ class Query:
See the class documentation for important details about which key expression to use for replies.
"""

@_unstable
@property
def source_info(self) -> SourceInfo | None:
"""Gets info on the source of this Query."""

def drop(self):
"""Drop the instance of a query.
The query will only be finalized when all query instances (one per queryable
Expand Down Expand Up @@ -1174,7 +1179,7 @@ class Sample:

@_unstable
@property
def source_info(self) -> SourceInfo:
def source_info(self) -> SourceInfo | None:
"""Gets info on the source of this Sample."""

@final
Expand Down Expand Up @@ -1635,15 +1640,13 @@ class SourceInfo:
global identifier and sequence number.
"""

def __new__(
cls, source_id: EntityGlobalId | None = None, source_sn: SourceSn | None = None
) -> Self: ...
def __new__(cls, source_id: EntityGlobalId, source_sn: SourceSn) -> Self: ...
@property
def source_id(self) -> EntityGlobalId | None:
def source_id(self) -> EntityGlobalId:
"""The EntityGlobalId of the zenoh entity that published the Sample in question."""

@property
def source_sn(self) -> SourceSn | None:
def source_sn(self) -> SourceSn:
"""The sequence number of the Sample from the source."""

SourceSn = int
Expand Down
Loading