Skip to content

Commit 9feddb6

Browse files
fix docs for __new__
1 parent 1256929 commit 9feddb6

2 files changed

Lines changed: 69 additions & 63 deletions

File tree

docs/stubs_to_sources.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
PACKAGE = (Path(__file__) / "../../zenoh").resolve()
3030
__INIT__ = PACKAGE / "__init__.py"
31+
EXT = PACKAGE / "ext.py"
3132

3233

3334
def _unstable(item):
@@ -98,23 +99,26 @@ def visit_FunctionDef(self, node: ast.FunctionDef):
9899

99100

100101
def main():
101-
# remove __init__.pyi
102-
__INIT__.unlink()
102+
fnames = [__INIT__, EXT]
103+
for fname in fnames:
104+
# remove *.py
105+
fname.unlink()
103106
# rename stubs
104107
for entry in PACKAGE.glob("*.pyi"):
105108
entry.rename(PACKAGE / f"{entry.stem}.py")
106-
# read stub code
107-
with open(__INIT__) as f:
108-
stub: ast.Module = ast.parse(f.read())
109-
# replace _unstable
110-
for i, stmt in enumerate(stub.body):
111-
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
112-
stub.body[i] = ast.parse(inspect.getsource(_unstable))
113-
# remove overload
114-
stub = RemoveOverload().visit(stub)
115-
# write modified code
116-
with open(__INIT__, "w") as f:
117-
f.write(ast.unparse(stub))
109+
for fname in fnames:
110+
# read stub code
111+
with open(fname) as f:
112+
stub: ast.Module = ast.parse(f.read())
113+
# replace _unstable
114+
for i, stmt in enumerate(stub.body):
115+
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
116+
stub.body[i] = ast.parse(inspect.getsource(_unstable))
117+
# remove overload
118+
stub = RemoveOverload().visit(stub)
119+
# write modified code
120+
with open(fname, "w") as f:
121+
f.write(ast.unparse(stub))
118122

119123

120124
if __name__ == "__main__":

zenoh/ext.pyi

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,36 @@ class AdvancedSubscriber(Generic[_H]):
203203
@_unstable
204204
@final
205205
class CacheConfig:
206+
"""
207+
:param max_samples: specify how many samples to keep for each resource, default to 1
208+
:param replies_config: the QoS to apply to replies
209+
"""
210+
206211
def __new__(
207212
cls,
208213
max_samples: int | None = None,
209214
*,
210215
replies_config: RepliesConfig | None = None,
211-
) -> Self:
212-
"""
213-
:param max_samples: specify how many samples to keep for each resource, default to 1
214-
:param replies_config: the QoS to apply to replies
215-
"""
216+
) -> Self: ...
216217

217218
@_unstable
218219
@final
219220
class HistoryConfig:
221+
"""
222+
:param detect_late_publishers: enable detection of late joiner publishers and query for their historical data;
223+
late joiner detection can only be achieved for `AdvancedPublisher` that enable `publisher_detection`
224+
history can only be retransmitted by `AdvancedPublisher` that enable `cache`
225+
:param max_samples: specify how many samples to query for each resource
226+
:param max_age: specify the maximum age of samples to query in seconds
227+
"""
228+
220229
def __new__(
221230
cls,
222231
*,
223232
detect_late_publishers: bool | None = None,
224233
max_samples: int | None = None,
225234
max_age: float | int | None = None,
226-
) -> Self:
227-
"""
228-
:param detect_late_publishers: enable detection of late joiner publishers and query for their historical data;
229-
late joiner detection can only be achieved for `AdvancedPublisher` that enable `publisher_detection`
230-
history can only be retransmitted by `AdvancedPublisher` that enable `cache`
231-
:param max_samples: specify how many samples to query for each resource
232-
:param max_age: specify the maximum age of samples to query in seconds
233-
"""
235+
) -> Self: ...
234236

235237
@_unstable
236238
@final
@@ -246,47 +248,48 @@ class Miss:
246248
@_unstable
247249
@final
248250
class MissDetectionConfig:
249-
@overload
250-
def __new__(cls) -> Self: ...
251-
@overload
252-
def __new__(cls, *, heartbeat: float | int) -> Self:
253-
"""
254-
:param heartbeat: period in seconds, allow last sample miss detection through periodic heartbeat;
255-
periodically send the last published Sample's sequence number to allow last sample recovery
256-
`AdvancedSubscriber`(crate::AdvancedSubscriber) can recover the last sample with the `heartbeat` option
257-
"""
251+
"""
252+
:param heartbeat: period in seconds, allow last sample miss detection through periodic heartbeat;
253+
periodically send the last published Sample's sequence number to allow last sample recovery.
254+
`AdvancedSubscriber can only recover the last sample with the `heartbeat` option enabled.
258255
259-
@overload
260-
def __new__(cls, sporadic_heartbeat: float | int) -> Self:
261-
"""
262-
:param sporadic_heartbeat: period in seconds, allow last sample miss detection through sporadic heartbeat;
263-
each period, the last published Sample's sequence number is sent with `CongestionControl.Block` but only if
264-
it has changed since the last period.
265-
"""
256+
**This option can not be enabled simultaneously with `sporadic_heartbeat`.**
257+
258+
:param sporadic_heartbeat: period in seconds, allow last sample miss detection through sporadic heartbeat;
259+
each period, the last published Sample's sequence number is sent with `CongestionControl.Block` but only if
260+
it has changed since the last period.
261+
`AdvancedSubscriber can only recover the last sample with the `heartbeat` option enabled.
262+
263+
**This option can not be enabled simultaneously with `heartbeat`.**
264+
"""
265+
266+
def __new__(
267+
cls, *, heartbeat: float | int | None, sporadic_heartbeat: float | int | None
268+
) -> Self: ...
266269

267270
@_unstable
268271
@final
269272
class RecoveryConfig:
270-
@overload
271-
def __new__(cls) -> Self: ...
272-
@overload
273-
def __new__(cls, *, periodic_queries: float | int) -> Self:
274-
"""
275-
:param periodic_queries: enable periodic queries for not yet received Samples and specify their period;
276-
it allows retrieving the last Sample(s) if the last Sample(s) is/are lost,
277-
so it is useful for sporadic publications but useless for periodic publications
278-
with a period smaller or equal to this period
279-
retransmission can only be achieved by `AdvancedPublisher` that enable `cache` and `sample_miss_detection`
280-
"""
273+
"""
274+
:param periodic_queries: enable periodic queries for not yet received Samples and specify their period;
275+
it allows retrieving the last Sample(s) if the last Sample(s) is/are lost,
276+
so it is useful for sporadic publications but useless for periodic publications
277+
with a period smaller or equal to this period.
278+
Retransmission can only be achieved by `AdvancedPublisher` that enable `cache` and `sample_miss_detection`.
281279
282-
@overload
283-
def __new__(cls, *, heartbeat: Literal[True]) -> Self:
284-
"""
285-
:param heartbeat: subscribe to heartbeats of `AdvancedPublisher`;
286-
it allows receiving the last published Sample's sequence number and check for misses
287-
heartbeat subscriber must be paired with `AdvancedPublishers` that enable `cache` and
288-
`sample_miss_detection` with `heartbeat` or `sporadic_heartbeat`
289-
"""
280+
**This option can not be enabled simultaneously with `heartbeat`.**
281+
282+
:param heartbeat: subscribe to heartbeats of `AdvancedPublisher`;
283+
it allows receiving the last published Sample's sequence number and check for misses.
284+
Heartbeat subscriber must be paired with `AdvancedPublishers` that enable `cache` and
285+
`sample_miss_detection` with `heartbeat` or `sporadic_heartbeat`.
286+
287+
**This option can not be enabled simultaneously with `periodic_queries`.**
288+
"""
289+
290+
def __new__(
291+
cls, *, periodic_queries: float | int | None, heartbeat: Literal[True] | None
292+
) -> Self: ...
290293

291294
@_unstable
292295
@final
@@ -302,7 +305,6 @@ class RepliesConfig:
302305
@_unstable
303306
@final
304307
class SampleMissListener(Generic[_H]):
305-
@property
306308
def undeclare(self): ...
307309
@overload
308310
def try_recv(self: SampleMissListener[Handler[Miss]]) -> Miss | None: ...

0 commit comments

Comments
 (0)