Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add _unstable decorator #405

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 18 additions & 2 deletions docs/stubs_to_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
referencing a type not declared yet (i.e. forward reference)."""

import ast
import inspect
from collections import defaultdict
from pathlib import Path

PACKAGE = (Path(__file__) / "../../zenoh").resolve()
__INIT__ = PACKAGE / "__init__.py"


def _unstable(item):
warning = "Warning: This API has been marked as unstable: it works as advertised, but it may be changed in a future release."
if item.__doc__:
item.__doc__ += "\n" + warning
else:
item.__doc__ = warning
return item


class RemoveOverload(ast.NodeTransformer):
def __init__(self):
self.current_cls = None
Expand Down Expand Up @@ -95,10 +105,16 @@ def main():
entry.rename(PACKAGE / f"{entry.stem}.py")
# read stub code
with open(__INIT__) as f:
stub = ast.parse(f.read())
stub: ast.Module = ast.parse(f.read())
# replace _unstable
for i, stmt in enumerate(stub.body):
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
stub.body[i] = ast.parse(inspect.getsource(_unstable))
# remove overload
stub = RemoveOverload().visit(stub)
# write modified code
with open(__INIT__, "w") as f:
f.write(ast.unparse(RemoveOverload().visit(stub)))
f.write(ast.unparse(stub))


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions zenoh/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ _RustHandler = (
_PythonCallback = Callable[[_T], Any]
_PythonHandler = tuple[_PythonCallback[_T], _H]

def _unstable(item: _T) -> _T:
"""marker for unstable items"""

@final
class ZError(Exception): ...

Expand Down
Loading