Skip to content

Commit

Permalink
docs: update Python migration guide for drop-callback change (#81)
Browse files Browse the repository at this point in the history
* docs: update Python migration guide for drop-callback change

* Update content/docs/migration_1.0/Python.md

Co-authored-by: Luca Cominardi <[email protected]>

* Update content/docs/migration_1.0/Python.md

Co-authored-by: oteffahi <[email protected]>

* Update content/docs/migration_1.0/Python.md

Co-authored-by: oteffahi <[email protected]>

---------

Co-authored-by: Luca Cominardi <[email protected]>
Co-authored-by: Gabriele Baldoni <[email protected]>
Co-authored-by: oteffahi <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2024
1 parent 03993fa commit b438700
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions content/docs/migration_1.0/Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ with zenoh.open(zenoh.Config()) as session:
# and it will undeclare the subscriber
```

## Drop-callback has to be wrapped in `handlers.Callback`

In the previous 0.11.0 version, it was possible to pass a drop-callback with the main callback in a tuple for operations like `Session.declare_subscriber`. However, it was also possible to pass a tuple with a "receiver" (renamed "handler" in 1.0.0) as second member, and that could confuse users.
<br>
The API has been changed and now requires the drop-callback to be wrapped in `handlers.Callback`.

- Zenoh 0.11.x

```python
def on_sample(sample: zenoh.Sample): ...
def on_done(): ...
session.declare_subscriber((on_sample, on_done))
```

- Zenoh 1.0.0

```python
def on_sample(sample: zenoh.Sample): ...
def on_done(): ...
session.declare_subscriber(zenoh.handlers.Callback(on_sample, on_done))
```

NOTE: ⚠️ Passing drop-callback in a tuple will no longer work as expected, as the drop callback will never be executed. To ease migration and avoid surprises, a warning will be displayed in this case.

## Value is gone, long live ZBytes

`Value` has been split into `ZBytes` and `Encoding`. `put` and other operations now require a `ZBytes` payload, and builders accept an optional `Encoding` parameter.
Expand All @@ -49,14 +73,14 @@ with zenoh.open(zenoh.Config()) as session:

- Zenoh 0.11.x

```rust
```python
sample = subscriber.recv()
my_string = sample.payload.decode("utf-8")
```

- Zenoh 1.0.0

```rust
```python
sample = subscriber.recv()
my_string = sample.payload.to_string()
```
Expand Down

0 comments on commit b438700

Please sign in to comment.